Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 如何修改aerospike中TTL为-1的所有记录集的TTL?_Lua_User Defined Functions_Predicate_Aerospike_Ttl - Fatal编程技术网

Lua 如何修改aerospike中TTL为-1的所有记录集的TTL?

Lua 如何修改aerospike中TTL为-1的所有记录集的TTL?,lua,user-defined-functions,predicate,aerospike,ttl,Lua,User Defined Functions,Predicate,Aerospike,Ttl,我想修改所有意外设置为“永不过期”TTL的记录的TTL(客户端中为-1)。我将如何做到这一点?只是澄清一下,在客户机中设置a意味着永不过期(相当于在服务器文件中设置a为0),而在客户机中设置TTL为0意味着继承此命名空间的默认TTL 使用谓词筛选: 如果您使用的是和客户端,那么识别0的记录的最简单方法是使用。您将对谓词过滤器匹配的所有记录应用一个简单的记录UDF ttl.lua function set_ttl(rec, to_ttl) record.set_ttl(rec, to_ttl)

我想修改所有意外设置为“永不过期”TTL的记录的TTL(客户端中为-1)。我将如何做到这一点?

只是澄清一下,在客户机中设置a意味着永不过期(相当于在服务器文件中设置a为0),而在客户机中设置TTL为0意味着继承此命名空间的默认TTL

使用谓词筛选:

如果您使用的是和客户端,那么识别0的记录的最简单方法是使用。您将对谓词过滤器匹配的所有记录应用一个简单的记录UDF

ttl.lua

function set_ttl(rec, to_ttl)
  record.set_ttl(rec, to_ttl)
  aerospike:update(rec)
end
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
使用以下方法注册Lua模块:

然后在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();
仅使用自定义项

对于其他还没有谓词过滤的客户机(Python、PHP等),您可以通过应用于扫描的记录UDF来完成这一切。过滤逻辑必须存在于UDF内部

ttl.lua

function set_ttl(rec, to_ttl)
  record.set_ttl(rec, to_ttl)
  aerospike:update(rec)
end
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
在:

这与我回答的问题有关,然后OP改变了他的问题。我不想丢失这些信息,因为我现在需要大量编辑原始答案。