Aerospike: 如何在主键上执行IN查询

在aerospike中如何执行(类似于sql的)IN查询。 这是否需要一个UDF?

类似于这样: Select * from ns.set where PK in (1,2,3)

如果这需要一个UDF,如何在按键上执行UDF:

EXECUTE <module>.<function>(<args>) ON <ns>[.<set>] WHERE PK = <key>
点赞
用户1917187
用户1917187

从 Ver 3.12.1 版本开始,如果您将主键存储在一个 bin 中并在该 bin 上运行谓词过滤,您可以运行此类查询。请参阅 http://www.aerospike.com/docs/guide/predicate.html

Aerospike 默认不会以您分配的原始字符串或数字形式存储主键,而是存储主键和集名称的 RIPEMD160 哈希值。

2017-05-15 16:56:37
用户582436
用户582436

你基本上是想通过一个键列表来检索记录。这是 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() 方法也可以使用一个键列表。

2017-05-15 23:50:08