【发布时间】:2016-05-03 07:24:03
【问题描述】:
我正在尝试从 Aerospike 获取所有记录以及主键。 我尝试使用如下 client.query 功能
var query = client.query(aerospikeDBParams.dbName,"testRecords");
var stream = query.execute();
有了这个,我得到了除主键之外的所有字段。我怎样才能得到主键和其他字段?
提前致谢
【问题讨论】:
我正在尝试从 Aerospike 获取所有记录以及主键。 我尝试使用如下 client.query 功能
var query = client.query(aerospikeDBParams.dbName,"testRecords");
var stream = query.execute();
有了这个,我得到了除主键之外的所有字段。我怎样才能得到主键和其他字段?
提前致谢
【问题讨论】:
您首先需要使用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()
})
})
当键与记录一起存储时,查询将返回它们。
【讨论】:
data 事件不包含记录键。这是来自 v1 客户端的regression,我将在下一个补丁版本中修复此问题。