如何从命名空间获取所有键?
How do I get all the keys from a namespace?
如何从 aerospike
命名空间获取所有键,就像我可以使用 map.keyset
从地图中获取键一样。我经历了这个 link 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)
我尝试将 client.readPolicyDefault.sendKey = true;
和 client.scanPolicyDefault.sendKey = true;
与 client.writePolicyDefault.sendKey = true;
一起使用,代码开始 return 原始键而不是 NULL。
这是 helipilot50
对工作代码的 link:https://github.com/helipilot50/store-primary-key
这对我来说真的很有帮助。谢谢!
添加到 Fahad 的回答:
请记住,存储密钥(而不仅仅是摘要)占用 space。如果您的密钥是一个 100 个字符的字符串,而您的记录是两个 8 字节整数,则密钥存储将使用比这两个值更多的space。
利用这些知识行善而非作恶 :)
如何从 aerospike
命名空间获取所有键,就像我可以使用 map.keyset
从地图中获取键一样。我经历了这个 link 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)
我尝试将 client.readPolicyDefault.sendKey = true;
和 client.scanPolicyDefault.sendKey = true;
与 client.writePolicyDefault.sendKey = true;
一起使用,代码开始 return 原始键而不是 NULL。
这是 helipilot50
对工作代码的 link:https://github.com/helipilot50/store-primary-key
这对我来说真的很有帮助。谢谢!
添加到 Fahad 的回答:
请记住,存储密钥(而不仅仅是摘要)占用 space。如果您的密钥是一个 100 个字符的字符串,而您的记录是两个 8 字节整数,则密钥存储将使用比这两个值更多的space。
利用这些知识行善而非作恶 :)