3
我想修改所有使用'never expire'TTL(客户端为-1)意外设置的记录的TTL。我会怎么做?如何修改在aerospike中以ttl为-1设置的所有记录的TTL?
我想修改所有使用'never expire'TTL(客户端为-1)意外设置的记录的TTL。我会怎么做?如何修改在aerospike中以ttl为-1设置的所有记录的TTL?
只是为了澄清,在客户端设置TTL of -1意味着从来没有(在服务器的aerospike.conf文件相当于0 default-ttl
)到期,而在客户端设置一个TTL值为0表示继承默认-TTL为这个名字空间。
谓语过滤:
如果您使用的Java,C,C#和Go客户最简单的方法,以确定为0的void time记录将使用predicate filter。您可以将简单记录UDF应用于谓词过滤器匹配的所有记录。在Java应用程序,然后
$ 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.
:
ttl.lua
function set_ttl(rec, to_ttl)
record.set_ttl(rec, to_ttl)
-- for the TTL update to happen a bin must be 'dirty'
-- set the first bin back with the value of the first bin
-- no changes will occur other than the TTL change, but the
-- aerospike:update(rec) will actually execute
local bin_names = record.bin_names(rec)
local do_nothing = rec[bin_names[1]]
rec[bin_names[1]] = do_nothing
aerospike:update(rec)
end
使用AQL注册的Lua模块
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)
-- for the TTL update to happen a bin must be 'dirty'
-- set the first bin back with the value of the first bin
-- no changes will occur other than the TTL change, but the
-- aerospike:update(rec) will actually execute
local bin_names = record.bin_names(rec)
local do_nothing = rec[bin_names[1]]
rec[bin_names[1]] = do_nothing
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
这被质疑https://stackoverflow.com/questions/45138351/how-to-fetch-records-相关我回答的是一套1气压飞行器,然后OP改变了他的问题。我不想丢失信息,因为我现在需要大量编辑原始答案。 –