如何從aerospike
命名空間獲取所有密鑰,例如我可以使用map.keyset
從地圖獲取密鑰。我通過這個鏈接Aerospike: how do I get record key?。我做了答案中所講的內容。我用writePolicy.sendKey = true
編寫了代碼,但當我在scanCallback
函數中顯示密鑰時,我仍然收到NULL
。如何獲取命名空間中的所有密鑰?
這裏是我的代碼寫一個記錄
def writeToAerospike(): Boolean = {
val host:Host = new Host("xx.xxx.xxx.xx", 3000)
val client = new AerospikeClient(new ClientPolicy,host)
val policy = new WritePolicy();
policy.sendKey = true;
policy.timeout = 50000;
if(client.isConnected()){
println("connection to aerospike client sucessful")
client.put(policy,new Key("test", "testSet", "1"),new Bin("name", "john"))
//verify if the record is entered correctly
println(client.get(policy,new Key("test", "testing", "1")).getValue("name"))
client.close()
return true
}
return false
}
我使用從這個例子的代碼掃描記錄(任何幫助,將不勝感激):http://www.aerospike.com/docs/client/java/usage/scan/scan.html
class ScanParallelTest extends ScanCallback {
private var recordCount: Int = _
def runTest() {
val client = new AerospikeClient("xxx.xx.xxx.xx", 3000)
try {
val policy = new ScanPolicy()
policy.concurrentNodes = true
policy.priority = Priority.LOW
policy.includeBinData = true
client.scanAll(policy, "test", "testSet", this)
println("Records " + recordCount)
} finally {
client.close()
}
}
def scanCallback(key: Key, record: Record) {
recordCount += 1
println("Records " + recordCount)
println ("key=" + " "+key.userKey.toString() +" and "+" record: "+" "+ record.bins)
}
}
這裏是錯誤我得到:
com.aerospike.client.AerospikeException: java.lang.NullPointerException
at com.aerospike.client.command.ScanExecutor.scanParallel(ScanExecutor.java:66)
at com.aerospike.client.AerospikeClient.scanAll(AerospikeClient.java:551)
at aerospike.asd.ScanParallelTest.runTest(ScanParallelTest.scala:23)
at aerospike.asd.test$.main(test.scala:10)
at aerospike.asd.test.main(test.scala)
Caused by: java.lang.NullPointerException
at aerospike.asd.ScanParallelTest.scanCallback(ScanParallelTest.scala:35)
at com.aerospike.client.command.ScanCommand.parseRecordResults(ScanCommand.java:122)
at com.aerospike.client.command.MultiCommand.parseResult(MultiCommand.java:58)
at com.aerospike.client.command.SyncCommand.execute(SyncCommand.java:56)
at com.aerospike.client.command.ScanExecutor$ScanThread.run(ScanExecutor.java:134)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
你能交叉檢查,關鍵確實是把你的數據備份到服務器的。您的備份文件應該有密鑰。試圖孤立罪魁禍首。寫或掃描。 – sunil
是的,鑰匙使它到服務器,但沒有讓它回到我身邊。 – Hammad