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

标签 lua user-defined-functions aerospike ttl aql

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

最佳答案

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

使用谓词过滤:

如果您使用 Java , C , C#Go客户识别记录的最简单方法是 void time 0 将使用 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()

关于lua - 如何在aerospike中获取ttl为-1的记录集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45138351/

相关文章:

regex - 我不明白的正则表达式

c++ - 将非全局 C++ 对象传递给 Lua 函数 (Swig)

user-defined-functions - 在 Pig 中按袋子值(value)分组

go - 如何在 Go 中反序列化 Aerospike 记录?

c# - LuaInterface - 如何限制对 .Net 类的访问?

oop - 错误的参数 #2 到 'setmetatable'(nil 或预期的表)?

python - 如何修复代码中的 'UnboundLocalError: local variable ' dc' 在分配之前引用'?

user-defined-functions - 将数组参数传递给自定义的 Pig 加载器

python - Aerospike 节点连接过载 - 全局连接问题

aerospike - AQL 无法通过 PK 找到行。选择时有行