How can I change the TTL of all entries set with TTL -1 in aerosics?

I want to change the TTL of all records that were accidentally set with a TTL (never expiring) (-1 on the client). How should I do it?

+3


source to share


1 answer


Just to clarify, setting TTL -1 in the client means that the term never expires (equivalent to the value of 0 in the server file aerospike.conf ). While setting TTL 0 in the client is the inheritance of default-ttl. for this namespace. default-ttl

With predicate filtering:

If you are using Java , C , C #, and Go clients , the easiest way to identify records with empty time 0 is to use a predicate filter . You would apply a simple UDF record to all records matched by a predicate filter.

ttl.lua

function set_ttl(rec, to_ttl)
  record.set_ttl(rec, to_ttl)
  aerospike:update(rec)
end

      

Register a Lua module using AQL :

$ aql
Aerospike Query Client
Version 3.12.0
C Client Version 4.1.4
Copyright 2012-2017 Aerospike. All rights reserved.
aql> register module './ttl.lua'
OK, 1 module added.

      

Then in a Java application:



Statement stmt = new Statement();
stmt.setNamespace(params.namespace);
stmt.setSetName(params.set);
stmt.setPredExp(
  PredExp.recVoidTime(),
  PredExp.integerValue(0),
  PredExp.integerEqual()
  );

ExecuteTask task = client.execute(params.writePolicy, stmt, "ttl", "set_ttl", Value.IntegerValue(604800));
task.waitTillComplete();

      

Using UDF only :

With other clients that don't have predicate filtering yet (Python, PHP, etc.), you could do all this with a UDF record applied to the scan. The filtering logic would have to live inside the UDF.

ttl.lua

function modify_zero_ttl(rec, to_ttl)
  local rec_ttl = record.ttl(rec)
  if rec_ttl == 0 then
    record.set_ttl(rec, to_ttl)
    aerospike:update(rec)
  end
end

      

In AQL :

$ aql
Aerospike Query Client
Version 3.12.0
C Client Version 4.1.4
Copyright 2012-2017 Aerospike. All rights reserved.
aql> register module './ttl.lua'
OK, 1 module added.

aql> execute ttl.modify_zero_ttl(604800) on test.foo

      

+3


source







All Articles