Aerospike:如何在PK上执行IN查询

时间:2017-05-15 13:09:28

标签: lua udf aerospike

如何在aerospike中执行(sql like)IN查询。 我们需要一个UDF吗?

这样的事情:Select * from ns.set where PK in (1,2,3)

如果这需要UDF如何解决它,因为在密钥上执行UDF:

EXECUTE <module>.<function>(<args>) ON <ns>[.<set>] WHERE PK = <key>

2 个答案:

答案 0 :(得分:2)

在Ver 3.12.1+中,如果将主键存储在bin中,然后对该bin运行谓词过滤,则可以运行此类查询。见http://www.aerospike.com/docs/guide/predicate.html

默认情况下,Aerospike不会在分配PK时以原始字符串或数字形式存储PK。它存储PK + Set名称的RIPEMD160哈希值。

答案 1 :(得分:2)

您基本上都在寻找按键列表检索记录的方法。这是Aerospike中的批量读取操作。 Aerospike的每个语言客户都应具备此功能。

例如,在Python客户端中,这是Client.get_many方法:

from __future__ import print_function
import aerospike
from aerospike.exception import AerospikeError
import sys

config = { 'hosts': [('127.0.0.1', 3000)] }
client = aerospike.client(config).connect()

try:
    # assume the fourth key has no matching record
    keys = [
      ('test', 'demo', '1'),
      ('test', 'demo', '2'),
      ('test', 'demo', '3'),
      ('test', 'demo', '4')
    ]
    records = client.get_many(keys)
    print records
except AerospikeError as e:
    print("Error: {0} [{1}]".format(e.msg, e.code))
    sys.exit(1)
finally:
    client.close()

同样,在Java客户端中,AerospikeClient.get()方法可以获取密钥列表。