首先,您需要實際存儲與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客戶端思想。 –
@Ronen它的工作..謝謝:) –
@ sel魚,你是對的:從v2.0.3,客戶端的記錄流'數據'事件不包括記錄密鑰。這是v1客戶端的[迴歸](https://github.com/aerospike/aerospike-client-nodejs/issues/126),我將在下一個補丁版本中修復此問題。 –