2017-07-17 79 views
2

我在塞这么多的纪录,我希望获取其TTL值为-1请提供解决方案如何获取记录集中的ttl为-1的aerospike?

+1

好的,但您想对所有这些记录做什么?你想阅读他们的内容?你想删除它们吗?你想重置他们的TTL到指定的时间? –

+0

这与您在讨论中提出的问题不同:https://discuss.aerospike.com/t/how-to-get-records-whose-ttl-is-1/4400/5 - 您打开重复的问题,但给予不同信息?那是什么? –

+0

为了保存我在回答丢失问题时所做的工作,我创建了一个重复问题(https://stackoverflow.com/questions/45193957/how-to-modify-the-ttl-of-all-records-set -with-A-TTL-的-1合塞)。现在我需要编辑这个问题,因为你反驳了你自己。这是无礼的 - 你要求某人解决你的问题,然后在发表一个写得不好的问题后,你就改变主意。 –

回答

2

只是为了澄清记录,在客户端设置TTL of -1意味着永不过期(相当于0的default-ttl在服务器的aerospike.conf文件中),同时在客户端中设置TTL为0意味着继承此名称空间的默认-ttl。

谓语过滤:

如果您使用的JavaCC#Go客户最简单的方法,以确定为0的void time记录将使用predicate filter

在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等)等客户端,你会做这一切通过stream UDF。过滤逻辑必须位于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 

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