Search in sources :

Example 41 with Bin

use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.

the class UserDefinedFunction method writeUsingUdf.

private void writeUsingUdf(AerospikeClient client, Parameters params) throws Exception {
    Key key = new Key(params.namespace, params.set, "udfkey1");
    Bin bin = new Bin(params.getBinName("udfbin1"), "string value");
    client.execute(params.writePolicy, key, "record_example", "writeBin", Value.get(bin.name), bin.value);
    Record record = client.get(params.policy, key, bin.name);
    String expected = bin.value.toString();
    String received = record.getString(bin.name);
    if (received != null && received.equals(expected)) {
        console.info("Data matched: namespace=%s set=%s key=%s bin=%s value=%s", key.namespace, key.setName, key.userKey, bin.name, received);
    } else {
        console.error("Data mismatch: Expected %s. Received %s.", expected, received);
    }
}
Also used : Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key)

Example 42 with Bin

use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.

the class TestAsyncPutGet method asyncPutGetWithRetry.

@Test
public void asyncPutGetWithRetry() {
    final Key key = new Key(args.namespace, args.set, "putgetkey2");
    final Bin bin = new Bin(binName, "value");
    client.put(eventLoop, new WriteHandler(client, null, key, bin), null, key, bin);
    waitTillComplete();
}
Also used : Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 43 with Bin

use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.

the class TestAppend method prepend.

@Test
public void prepend() {
    Key key = new Key(args.namespace, args.set, "prependkey");
    String binName = args.getBinName("prependbin");
    // Delete record if it already exists.
    client.delete(null, key);
    Bin bin = new Bin(binName, "World");
    client.prepend(null, key, bin);
    bin = new Bin(binName, "Hello ");
    client.prepend(null, key, bin);
    Record record = client.get(null, key, bin.name);
    assertBinEqual(key, record, bin.name, "Hello World");
}
Also used : Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 44 with Bin

use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.

the class TestDeleteBin method deleteBin.

@Test
public void deleteBin() {
    Key key = new Key(args.namespace, args.set, "delbinkey");
    String binName1 = args.getBinName("bin1");
    String binName2 = args.getBinName("bin2");
    Bin bin1 = new Bin(binName1, "value1");
    Bin bin2 = new Bin(binName2, "value2");
    client.put(null, key, bin1, bin2);
    // Set bin value to null to drop bin.
    bin1 = Bin.asNull(binName1);
    client.put(null, key, bin1);
    Record record = client.get(null, key, bin1.name, bin2.name, "bin3");
    assertRecordFound(key, record);
    if (record.getValue("bin1") != null) {
        fail("bin1 still exists.");
    }
    Object v2 = record.getValue("bin2");
    assertNotNull(v2);
    assertEquals("value2", v2);
}
Also used : Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key) Test(org.junit.Test)

Example 45 with Bin

use of com.aerospike.client.Bin in project aerospike-client-java by aerospike.

the class TestBitExp method callRead.

@Test
public void callRead() {
    Key key = new Key(args.namespace, args.set, 5000);
    client.delete(null, key);
    Bin bin = new Bin(binA, new byte[] { 0x01, 0x42, 0x03, 0x04, 0x05 });
    client.put(null, key, bin);
    get(key);
    count(key);
    lscan(key);
    rscan(key);
    getInt(key);
}
Also used : Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key) Test(org.junit.Test)

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