I’m new to aerospike UDF need some help on basic UDF function, when creating a new record using record UDF is it possible to give a TTL value for it? also how to add the key value when creating a new record?
This is the sample UDF that I’m using to create record:
function create_record(rec, bin1, bin2, bin3)
if( not aerospike:exists( rec ) ) then
aerospike:create(rec);
end
rec['bin1'] = bin1;
rec["bin2"] = bin2;
rec["bin3"] = bin3;
return aerospike:update(rec);
end
All the bin values are getting updated properly, but the “key” isn’t getting updated. Is there a way to update the key when creating or updating the record using UDF, also is it possible to give a TTL value when performing a create/update operation.
I didn’t really understand your answer, when creating a new record how can we set the key? can you give me a code sample? I have a create statement in my sample code, but I’m not sure how to assign the key for it
The record is identified by key. When UDF execution is performed with a key. The record that you get access to using rec is the record for that key. You cannot change the key for a record. You can add/update bin values / TTL etc.
When I tried to call the above mention UDF (create_record) through AQL command ‘key’ column is not getting updated, as in when I check the set data ‘key’ column is empty. But still I was able to query the record with the primary key using below command:
select * from namespace.setname where PK = 'key'
Also inside the UDF when I tried to retrieve the ‘key’ value it returns nil. But when I call the same UDF function using the Java Client API ‘key’ column is getting updated properly also inside UDF I can retrieve the value of the key, is there any reason for that or am I doing anything wrong?