I tried :
record.set_ttl(rec, -1)
record.set_ttl(rec, 0xFFFFFFFF)
record.set_ttl(rec, 0)
all not worked.
I tried :
record.set_ttl(rec, -1)
record.set_ttl(rec, 0xFFFFFFFF)
record.set_ttl(rec, 0)
all not worked.
was a record.update() called after setting?
I want to create a new no-expire record in lua.
Code like:
function f(rec, ...)
if aerospike:exists(rec) then
...
else
...
record.set_ttl(rec, 0xFFFFFFFF) --- or -1 , 0
return aerospike:create(rec)
end
end
But it not works. The ttl is decreasing.
Can you run the following snippet twice? The first time, it will create the record with a no expire. And second time print out the ttl You can also do a backup of the record and show the TTL in the record after creation.
if (aerospike:exists(rec)) then
warn("rec ttl = %s", tostring(record.ttl(rec)))
status = aerospike:update(rec);
warn("update status = %d", status)
else
record.set_ttl(rec, -1)
status = aerospike:create(rec);
warn("create status = %d", status)
end
Lua file :
function test_ttl(rec)
if aerospike:exists(rec) then
ttl = record.ttl(rec)
status = aerospike:update(rec)
return string.format("rec ttl = %d, update status = %d", ttl, status)
else
rec['bin'] = 'ttl'
record.set_ttl(rec, -1)
status = aerospike:create(rec)
return string.format("create status = %d", status)
end
end
The result shows that the third time make things wrong.
Thanks this is very helpful. Do you have a default-ttl of 30 days on your namespace ?
Filed JIRA ticket AER-4287 for continue tracking internally.
Yes. Default ttl of namespace(camel) is 30 days.
Thanks for the example.
To create a non-expiring record in LUA, you can use
record.set_ttl(rec, -1)
or, equivalently,
record.set_ttl(rec, 0xFFFFFFFF)
before calling aerospike:create().
Using record.set_ttl(rec, 0) will set the TTL to the namespace default if the default is non-zero, or it will set the TTL to infinite (i.e. record will not expire) if the namespace default is zero.
The other important point is that when subsequently calling aerospike:update() on the record, the TTL must first be assigned again with record.set_ttl(rec, -1) in order to preserve the record’s infinite life. Otherwise the aerospike:update() call will reset the record’s TTL according to the namespace default.
We’re still considering whether the behavior of aerospike:update() should be changed in this regard.
Call record.set_ttl(rec, -1) before aerospike:update() works.
Thank you