Search in sources :

Example 76 with Bin

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);
}
Also used : Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 77 with Bin

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));
}
Also used : Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key)

Example 78 with Bin

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);
}
Also used : Bin(com.aerospike.client.Bin) Value(com.aerospike.client.Value) ArrayList(java.util.ArrayList) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key)

Example 79 with Bin

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);
}
Also used : Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key)

Example 80 with Bin

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));
    }
}
Also used : Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key)

Aggregations

Bin (com.aerospike.client.Bin)151 Key (com.aerospike.client.Key)129 Record (com.aerospike.client.Record)70 Test (org.junit.Test)54 AerospikeException (com.aerospike.client.AerospikeException)34 ArrayList (java.util.ArrayList)31 WritePolicy (com.aerospike.client.policy.WritePolicy)27 HashMap (java.util.HashMap)22 Value (com.aerospike.client.Value)20 List (java.util.List)15 BeforeClass (org.junit.BeforeClass)14 Map (java.util.Map)13 Policy (com.aerospike.client.policy.Policy)12 IndexTask (com.aerospike.client.task.IndexTask)11 WriteListener (com.aerospike.client.listener.WriteListener)5 RegisterTask (com.aerospike.client.task.RegisterTask)5 AbstractMap (java.util.AbstractMap)4 TreeMap (java.util.TreeMap)4 CTX (com.aerospike.client.cdt.CTX)3 BitPolicy (com.aerospike.client.operation.BitPolicy)3