Changing TTL for a set in Aerospike with AQL

413 Views Asked by At

I was just wondering, is there a way to change the TTL of a set through AQL query alone. I have gone through this aerospike page : https://discuss.aerospike.com/t/how-to-modify-ttl-using-udf/5608 and it says I will have to create a lua script and execute using aql query, which is fine.

Is there no support in AQL to change the TTL for a particular set using query alone i.e. without having to write a script? Just curious.

Any help would be appreciated. Thanks

1

There are 1 best solutions below

4
pgupta On

I don't think with AQL you can do that without a lua module. However the lua module is quite simple. AQL does not have the ability to utilize Operations in execute(), which is the other way you could do using, say, a Java client.

(sets ttl to argument value, in seconds)

mymodule.lua  
============
function mytouch(rec, ttl_val)
   record.set_ttl(rec, ttl_val)
   aerospike:update(rec)
end

Now load this file to the server via AQL.

aql> register module "mymodule.lua"
OK, 1 module added.

I have 10 records, one of them is:

aql> set record_print_metadata true

aql> select * from test.testset where pk="key1"
select * from test.testset where pk="key1"
+--------+-----+--------+-------+
| name   | age | {ttl}  | {gen} |
+--------+-----+--------+-------+
| "Jack" | 26  | 431998 | 1     |
+--------+-----+--------+-------+
1 row in set (0.002 secs)

OK

Lets set all records ttl to 100 seconds..

aql> execute mymodule.mytouch(100) on test.testset
execute mymodule.mytouch(100) on test.testset
OK, Scan job (13085139689609506765) created.

aql> select * from test.testset where pk="key1"
select * from test.testset where pk="key1"
+--------+-----+-------+-------+
| name   | age | {ttl} | {gen} |
+--------+-----+-------+-------+
| "Jack" | 26  | 98    | 2     |
+--------+-----+-------+-------+
1 row in set (0.001 secs)

OK