node.js - 从 Aerospike node.js 客户端检索主键

标签 node.js aerospike

我正在尝试使用 client.get() 检索 Aerospike node.js 客户端中的主键。我已使用 client.put() 插入记录,方法是将策略更改为 Aerospike.policy.key.SEND,如前所述 herehere .

现在我想检索记录以及主键。 我试过像 Aerospike Documentation 中提到的那样做但它似乎不起作用。

var key = aerospike.key(aerospikeDBParams.defaultNamespace,aerospikeDBParams.defaultSet,count);
    var readpolicy = {
        key: aerospike.policy.key.SEND
    }
    client.get(key, readpolicy, function(err, rec, meta){}

我得到了所有的 bin,但没有得到主键。我在这里错过了什么吗?

提前致谢。

最佳答案

函数的第四个参数是你想要的主键信息。

以我的代码为例:

  var readpolicy = {
      key: Aerospike.policy.key.SEND
  }
  var key = new Aerospike.Key(ns, set, "sel-fish")
  client.get(key, readpolicy, function (err, record, metadata, key) {
    if (null == err) {
      console.log("get ok")
      console.log(record)
      console.log(metadata)
      console.log(key)
    }
  })

输出是:

get ok
{ uid: 1000,
  name: 'sel-fish',
  dob: { mm: 12, dd: 29, yy: 1995 },
  friends: [ 1001, 1002, 1003 ],
  avatar: <Buffer 0a 0b 0c> }
{ ttl: 431997, gen: 3 }
Key { ns: 'test', set: '14', key: 'sel-fish', digest: null }

驱动版本为aerospike@2.0.3

关于node.js - 从 Aerospike node.js 客户端检索主键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37050047/

相关文章:

javascript - ExpressJS - 用于匹配路径的正则表达式不起作用

javascript - React Jest 示例不起作用

java - 使用 aerospike 进行集成测试?

go - 如何使用 golang 遍历 aerospike 中的列表?

java - Spring MVC - 实现 aerospike session

javascript - meteor 自动表单的简单验证码字段类型

node.js - 这种 Node.js 异常处理方法的最佳实践?

docker - 如何在 Docker 中安装 Aerospike 工具?

node.js - 即使我添加了安全组,也无法在特定端口上访问 EC2

Aerospike 管理控制台 : No batch query throughput