Java – aerospike: how to get the record key?
The aerospike client has a scanall method to read all rows in its store
ScanPolicy policy = new ScanPolicy(); policy.concurrentNodes = true; policy.priority = Priority.DEFAULT; policy.includeBinData = true; policy.scanPercent = 100; client.scanAll(policy,"namespaceName","setName",new ScanCallback() { @Override public void scanCallback(Key key,Record record) throws AerospikeException { STORE.put(key.userKey.toLong(),record.getValue("binName").toString()); } });
However, since the userkey is null, the NullPointerException completes All other fields are valid as expected The user key is a long value used to save data:
client.put(writePolicy,new Key("namespaceName",userKey),new Bin("binName",value));
Everything is fine. If I do this, single request:
client.get(readPolicy,userKey));
What might be wrong? Why is the userkey empty?
Solution
Aerospike uses keys and set names to generate unique summaries, so it only stores summaries
If writepolicy. Is set Sendkey = true, insert a record, and the key will be stored as the metadata of the record If you use writepolicy Sendkey = true inserts a record, then the keyword can only be obtained in scancallback()
By default, writepolicy Sendkey is false, so scancallback() will be null by default That's why your key userKey. Tolong() gives NullPointerException