use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class TestAdd method add.
@Test
public void add() {
Key key = new Key(args.namespace, args.set, "addkey");
String binName = args.getBinName("addbin");
// Delete record if it already exists.
client.delete(null, key);
// Perform some adds and check results.
Bin bin = new Bin(binName, 10);
client.add(null, key, bin);
bin = new Bin(binName, 5);
client.add(null, key, bin);
Record record = client.get(null, key, bin.name);
assertBinEqual(key, record, bin.name, 15);
// Test add and get combined.
bin = new Bin(binName, 30);
record = client.operate(null, key, Operation.add(bin), Operation.get(bin.name));
assertBinEqual(key, record, bin.name, 45);
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class Operate method runExample.
/**
* Demonstrate multiple operations on a single record in one call.
*/
@Override
public void runExample(AerospikeClient client, Parameters params) throws Exception {
// Write initial record.
Key key = new Key(params.namespace, params.set, "opkey");
Bin bin1 = new Bin("optintbin", 7);
Bin bin2 = new Bin("optstringbin", "string value");
console.info("Put: namespace=%s set=%s key=%s bin1=%s value1=%s bin2=%s value2=%s", key.namespace, key.setName, key.userKey, bin1.name, bin1.value, bin2.name, bin2.value);
client.put(params.writePolicy, key, bin1, bin2);
// Add integer, write new string and read record.
Bin bin3 = new Bin(bin1.name, 4);
Bin bin4 = new Bin(bin2.name, "new string");
console.info("Add: " + bin3.value);
console.info("Write: " + bin4.value);
console.info("Read:");
Record record = client.operate(params.writePolicy, key, Operation.add(bin3), Operation.put(bin4), Operation.get());
if (record == null) {
throw new Exception(String.format("Failed to get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey));
}
validateBin(key, record, bin3.name, 11, record.getInt(bin3.name));
validateBin(key, record, bin4.name, bin4.value.toString(), record.getValue(bin4.name));
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class OperateList method runNestedExample.
/**
* Operate on a list of lists.
*/
public void runNestedExample(AerospikeClient client, Parameters params) {
Key key = new Key(params.namespace, params.set, "listkey2");
String binName = params.getBinName("listbin");
// Delete record if it already exists.
client.delete(params.writePolicy, key);
List<Value> l1 = new ArrayList<Value>();
l1.add(Value.get(7));
l1.add(Value.get(9));
l1.add(Value.get(5));
List<Value> l2 = new ArrayList<Value>();
l2.add(Value.get(1));
l2.add(Value.get(2));
l2.add(Value.get(3));
List<Value> l3 = new ArrayList<Value>();
l3.add(Value.get(6));
l3.add(Value.get(5));
l3.add(Value.get(4));
l3.add(Value.get(1));
List<Value> inputList = new ArrayList<Value>();
inputList.add(Value.get(l1));
inputList.add(Value.get(l2));
inputList.add(Value.get(l3));
// Create list.
client.put(params.writePolicy, key, new Bin(binName, inputList));
// Append value to last list and retrieve all lists.
Record record = client.operate(params.writePolicy, key, ListOperation.append(binName, Value.get(11), CTX.listIndex(-1)), Operation.get(binName));
record = client.get(params.policy, key);
console.info("Record: " + record);
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class PutGet method runSingleBinTest.
/**
* Execute put and get on a server configured as single-bin.
*/
private void runSingleBinTest(AerospikeClient client, Parameters params) throws Exception {
Key key = new Key(params.namespace, params.set, "putgetkey");
Bin bin = new Bin("", "value");
console.info("Single Bin Put: namespace=%s set=%s key=%s value=%s", key.namespace, key.setName, key.userKey, bin.value);
client.put(params.writePolicy, key, bin);
console.info("Single Bin Get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey);
Record record = client.get(params.policy, key);
if (record == null) {
throw new Exception(String.format("Failed to get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey));
}
validateBin(key, bin, record);
}
use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.
the class QueryExecute method writeRecords.
private void writeRecords(AerospikeClient client, Parameters params, String keyPrefix, String binName1, String binName2, int size) throws Exception {
console.info("Write " + size + " records.");
for (int i = 1; i <= size; i++) {
Key key = new Key(params.namespace, params.set, keyPrefix + i);
client.put(params.writePolicy, key, new Bin(binName1, i), new Bin(binName2, i));
}
}
Aggregations