【问题标题】:How to fetch primary key in Aerospike Node.js Client如何在 Aerospike Node.js 客户端中获取主键
【发布时间】:2016-05-03 07:24:03
【问题描述】:

我正在尝试从 Aerospike 获取所有记录以及主键。 我尝试使用如下 client.query 功能

var query = client.query(aerospikeDBParams.dbName,"testRecords");
var stream = query.execute();

有了这个,我得到了除主键之外的所有字段。我怎样才能得到主键和其他字段?

提前致谢

【问题讨论】:

    标签: node.js aerospike


    【解决方案1】:

    您首先需要使用record 实际存储主键。客户端和服务器使用其摘要定位记录,客户端使用(命名空间、集合、主键)信息对其进行散列。密钥写入策略的默认值为Aerospike.policy.key.DIGEST。您需要将其显式设置为 Aerospike.policy.key.SEND

    请参阅Aerospike:module 文档。它包含以下示例:

    // global policy, applied to all commands that do not override it
    var config = {
      policies: {
        timeout: 100,
        retry: Aerospike.policy.retry.ONCE
      }
    }
    
    Aerospike.connect(config, (error, client) => {
      if (error) throw error
    
      var key = new Aerospike.Key('test', 'demo', 'k1')
      var record = {i: 1234}
    
      // override policy for put command
      var policy = {
        exists: Aerospike.policy.exists.CREATE,
        key: Aerospike.policy.key.SEND
      }
    
      client.put(key, record, {}, policy, (error) => {
        if (error && error.code === Aerospike.status.AEROSPIKE_ERR_RECORD_EXISTS) {
          console.info('record already exists')
        } else if (error) {
          throw error
        }
        client.close()
      })
    })
    

    当键与记录一起存储时,查询将返回它们。

    【讨论】:

    • 就是把关键信息放到服务器上的方法。但是查询方法返回recordStream,数据事件只返回(bins,meta),我找不到'key'。用java客户端思维就OK了。
    • @sel-fish,你是对的:从 v2.0.3 开始,客户端的记录流data 事件不包含记录键。这是来自 v1 客户端的regression,我将在下一个补丁版本中修复此问题。
    猜你喜欢
    • 2016-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-01
    • 2013-10-16
    • 2019-12-17
    • 2011-04-23
    • 1970-01-01
    相关资源
    最近更新 更多