如何在Aerospike中修改ttl为-1的所有记录集的TTL? [英] How to modify the TTL of all records set with a ttl of -1 in aerospike?
问题描述
我想修改所有意外设置为永不过期" TTL(客户端为-1)的记录的TTL.我该怎么办?
只需澄清一下,设置 default-ttl
为0 /operations/configure"rel =" nofollow noreferrer> aerospike.conf 文件),而在客户端中将TTL设置为0意味着继承此命名空间的默认ttl .>
具有谓词过滤功能:
如果您使用的是 Java , C ,转到客户端使用谓词过滤器.您可以对谓词过滤器匹配的所有记录应用简单的记录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
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
I want to modify the TTL of all the records that were accidentally set with a 'never expire' TTL (-1 in the client). How would I do that?
Just to clarify, setting a TTL of -1 in the client means never expire (equivalent to a default-ttl
of 0 in the server's aerospike.conf file), while setting a TTL of 0 in the client means inherit the default-ttl for this namespace.
With Predicate Filtering:
If you're using the Java, C, C# and Go clients the easiest way to identify the records with a void time of 0 would be to use a predicate filter. You would apply a simple record UDF to all the records matched by the predicate filter.
ttl.lua
function set_ttl(rec, to_ttl)
record.set_ttl(rec, to_ttl)
aerospike:update(rec)
end
Register the 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 the Java app:
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();
Only using UDFs:
With other clients that don't yet have predicate filtering (Python, PHP, etc), you would do it all through a record UDF that's applied to a 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
这篇关于如何在Aerospike中修改ttl为-1的所有记录集的TTL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!