【问题标题】:Aerospike: How to perform IN query on PKAerospike:如何对 PK 执行 IN 查询
【发布时间】:2017-05-15 13:09:28
【问题描述】:

如何在 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>

【问题讨论】:

    标签: lua udf aerospike


    【解决方案1】:

    您基本上是在查看通过键列表检索记录。这是 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() 方法可以获取键列表。

    【讨论】:

    • 我完全误解了这个问题!但是,作为一个单独的问题,假设一个具有复合键,例如 abc:123、abc:456、abc:234...xyz:123、xyz:456 .. 等,我想要所有记录都是 abc:* 键,如果您将密钥存储在 bin 中,您现在可以在 3.12.1+ 版本中使用谓词过滤。对吗?
    • 谓词过滤将是一种内省 bin 信息并快速找到匹配记录的好方法。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-23
      • 1970-01-01
      • 1970-01-01
      • 2013-10-10
      • 2011-03-08
      • 2021-08-14
      • 2013-02-24
      • 2020-06-23
      相关资源
      最近更新 更多