如何修改在aerospike中所有带有-1 TTL的记录的TTL?

我想修改所有不小心设置了“永不过期”TTL的记录的TTL(在客户端中为-1)。我该如何处理?

点赞
用户582436
用户582436

使用谓词过滤:

如果您使用JavaCC#Go客户端,要找到 [存根时间] (https://discuss.aerospike.com/t/eviction-mechanisms-in-aerospike-3-8-and-onwards/2854)为0 的记录,最简单的方法是使用 谓词过滤。您需要将一个简单的记录UDF应用于谓词过滤器匹配的所有记录。

ttl.lua

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

使用AQL注册Lua模块:

$ 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.

然后在Java应用程序中:

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();

只使用UDF

对于其他尚未具有谓词过滤功能的客户端(Python、PHP等),您将通过应用于扫描的记录UDF来完成所有操作。过滤逻辑必须在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

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
2017-07-19 14:41:59