Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/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的记录集?_Lua_User Defined Functions_Aerospike_Ttl_Aql - Fatal编程技术网

Lua 如何在aerospike中获取ttl为-1的记录集?

Lua 如何在aerospike中获取ttl为-1的记录集?,lua,user-defined-functions,aerospike,ttl,aql,Lua,User Defined Functions,Aerospike,Ttl,Aql,我在aerospike中有这么多记录,我想获取ttl为-1的记录请提供解决方案只是为了澄清,在客户端中设置a意味着永不过期(相当于在服务器文件中设置a为0),而在客户端中设置ttl为0意味着继承此命名空间的默认ttl 使用谓词筛选: 如果您使用的是和客户端,那么识别0的记录的最简单方法是使用 在Java应用程序中: Statement stmt = new Statement(); stmt.setNamespace(params.namespace); stmt.setSetName(para

我在aerospike中有这么多记录,我想获取ttl为-1的记录请提供解决方案

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

使用谓词筛选:

如果您使用的是和客户端,那么识别0的记录的最简单方法是使用

在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内部

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
在:

或者,您可以从客户端运行流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()

好吧,但是你想怎么处理这些记录?你想阅读他们的内容吗?是否要删除它们?您想将他们的TTL重置为指定的时间量吗?这与您在讨论中提出的问题不同:-您提出了重复的问题,但给出了不同的信息?这是怎么回事?为了避免我在回答你的问题时所做的工作丢失,我创建了一个重复的问题()。现在我需要编辑这个问题,因为你自相矛盾。这是不礼貌的——你要求别人解决你的问题,然后在发布了一个写得不好的问题后,你改变了对问题的看法。
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()