How to 'touch' record on UDF


#1

Is it possible to do touch operation from UDF (Lua)? or is the update/exists operations do the touch automatically?

We use the last Aerospike version.

Thanks, Avi


Remote Cluster in XDR Growing and Not Expiring As Expected...I Think
Changes to Default TTL Not Effecting Existing Data
#2

The effect of a touch operation is to update the TTL and increment the generation of the record, and this can be done directly in UDF in the following example:

function update_ttl( rec ) record.set_ttl( rec, updatedttl ) status = aerospike:update( rec ) end

The record.exists() function is a read-only function, and thus will not increment the record generation nor the TTL. A record.update() w/o having updated any bin or metadata (such as the TTL) is also a no-op.


#3

You could push it one second past the original TTL, and apply that record UDF to a scan of the namespace/set.

function touch_rec(rec)
    local new_ttl = record.ttl(rec) + 1
    record.set_ttl(rec, new_ttl)
    aerospike:update(rec)
end

Then

from __future__ import print_function
import aerospike

client = aerospike.client({ 'hosts': [('33.33.33.2', 3000)] }).connect()
client.scan_apply('test','testset','touchy','touch_rec',
           options={'priority': aerospike.SCAN_PRIORITY_LOW})