只是为了澄清,设置TTL 为 -1 https://github.com/aerospike/aerospike-client-go/blob/master/docs/policies.md#writepolicy-object在客户端意味着永不过期(相当于default-ttl http://www.aerospike.com/docs/reference/configuration#default-ttl服务器中的 0aerospike.conf http://www.aerospike.com/docs/operations/configure文件),而在客户端中设置 TTL 为 0 意味着继承此命名空间的默认 ttl.
使用谓词过滤:
如果您正在使用Java http://www.aerospike.com/apidocs/java/com/aerospike/client/query/PredExp.html, C http://www.aerospike.com/apidocs/c/d9/d10/as__predexp_8h_source.html, C# http://www.aerospike.com/apidocs/csharp/html/T_Aerospike_Client_PredExp.htm and Go https://github.com/aerospike/aerospike-client-go/blob/master/predexp.go客户识别记录的最简单方法空闲时间 https://discuss.aerospike.com/t/eviction-mechanisms-in-aerospike-3-8-and-onwards/28540 将使用谓词过滤器 http://www.aerospike.com/docs/guide/predicate.html.
在 Java 应用程序中:
Statement stmt = new Statement();
stmt.setNamespace(params.namespace);
stmt.setSetName(params.set);
stmt.setPredExp(
PredExp.recVoidTime(),
PredExp.integerValue(0),
PredExp.integerEqual()
);
RecordSet rs = client.query(null, stmt);
没有谓词过滤:
对于还没有谓词过滤的其他客户端(Python、PHP 等),您可以通过流式UDF http://www.aerospike.com/docs/udf/developing_stream_udfs.html。过滤逻辑必须位于 UDF 内部。
ttl.lua
local function filter_ttl_zero(rec)
local rec_ttl = record.ttl(rec)
if rec_ttl == 0 then
return true
end
return false
end
local function map_record(rec)
local ret = map()
for i, bin_name in ipairs(record.bin_names(rec)) do
ret[bin_name] = rec[bin_name]
end
return ret
end
function get_zero_ttl_recs(stream)
return stream : filter(filter_ttl_zero) : map(map_record)
end
In AQL http://www.aerospike.com/docs/tools/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> AGGREGATE ttl.get_zero_ttl_recs() on test.foo
或者,您可以从客户端运行流 UDF。以下示例适用于 Python 客户端:
import aerospike
import pprint
config = {'hosts': [('127.0.0.1', 3000)],
'lua': {'system_path':'/usr/local/aerospike/lua/',
'user_path':'/usr/local/aerospike/usr-lua/'}}
client = aerospike.client(config).connect()
pp = pprint.PrettyPrinter(indent=2)
query = client.query('test', 'foo')
query.apply('ttl', 'get_zero_ttl_recs')
records = query.results()
# we expect a dict (map) whose keys are bin names
# each with the associated bin value
pp.pprint(records)
client.close()