Search in sources :

Example 91 with Bin

use of com.aerospike.client.Bin in project XRTB by benmfaul.

the class RedissonClient method set.

/**
 * Set a key value as string.
 * @param skey String. The key name.
 * @param value String. The value.
 * @throws Exception on aerorpike or cache errors.
 */
public void set(String skey, String value) {
    if (ae == null) {
        cache.put(skey, value);
        return;
    }
    Key key = new Key("test", "cache", skey);
    Bin bin1 = new Bin("value", value);
    ae.getClient().delete(null, key);
    ae.getClient().put(null, key, bin1);
}
Also used : Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key)

Example 92 with Bin

use of com.aerospike.client.Bin in project XRTB by benmfaul.

the class RedissonClient method set.

/**
 * Set a key value as string with an expiration (No expiration set on cache2k, it is already set
 * @param skey String. The key name.
 * @param value String. The value.
 * @param expire int. The number of seconds before expiring.
 * @throws Exception on aerorpike or cache errors.
 */
public void set(String skey, String value, int expire) throws Exception {
    if (ae == null) {
        cache.put(skey, value);
        return;
    }
    AerospikeClient client = ae.getClient();
    if (client == null)
        return;
    WritePolicy policy = new WritePolicy();
    policy.expiration = expire;
    Key key = new Key("test", "cache", skey);
    Bin bin1 = new Bin("value", value);
    ae.getClient().put(policy, key, bin1);
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key) WritePolicy(com.aerospike.client.policy.WritePolicy)

Example 93 with Bin

use of com.aerospike.client.Bin in project YCSB by brianfrankcooper.

the class AerospikeClient method write.

private Status write(String table, String key, WritePolicy writePolicy, Map<String, ByteIterator> values) {
    Bin[] bins = new Bin[values.size()];
    int index = 0;
    for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
        bins[index] = new Bin(entry.getKey(), entry.getValue().toArray());
        ++index;
    }
    Key keyObj = new Key(namespace, table, key);
    try {
        client.put(writePolicy, keyObj, bins);
        return Status.OK;
    } catch (AerospikeException e) {
        System.err.println("Error while writing key " + key + ": " + e);
        return Status.ERROR;
    }
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) Bin(com.aerospike.client.Bin) HashMap(java.util.HashMap) Map(java.util.Map) Key(com.aerospike.client.Key)

Example 94 with Bin

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

the class TestOperateBit method assertBitModifyRegion.

// Exhaustive modify tests verified with all read ops.
public void assertBitModifyRegion(int bin_sz, int offset, int set_sz, byte[] expected, boolean is_insert, Operation... operations) {
    client.delete(null, key);
    byte[] initial = new byte[bin_sz];
    for (int i = 0; i < bin_sz; i++) {
        initial[i] = (byte) 0xFF;
    }
    client.put(null, key, new Bin(binName, initial));
    int int_sz = 64;
    if (set_sz < int_sz) {
        int_sz = set_sz;
    }
    int bin_bit_sz = bin_sz * 8;
    if (is_insert) {
        bin_bit_sz += set_sz;
    }
    Operation[] full_ops = Arrays.copyOf(operations, operations.length + 7);
    full_ops[full_ops.length - 7] = BitOperation.lscan(binName, offset, set_sz, true);
    full_ops[full_ops.length - 6] = BitOperation.rscan(binName, offset, set_sz, true);
    full_ops[full_ops.length - 5] = BitOperation.getInt(binName, offset, int_sz, false);
    full_ops[full_ops.length - 4] = BitOperation.count(binName, offset, set_sz);
    full_ops[full_ops.length - 3] = BitOperation.lscan(binName, 0, bin_bit_sz, false);
    full_ops[full_ops.length - 2] = BitOperation.rscan(binName, 0, bin_bit_sz, false);
    full_ops[full_ops.length - 1] = BitOperation.get(binName, offset, set_sz);
    Record record = client.operate(null, key, full_ops);
    List<?> result_list = record.getList(binName);
    long lscan1_result = (Long) result_list.get(result_list.size() - 7);
    long rscan1_result = (Long) result_list.get(result_list.size() - 6);
    long getint_result = (Long) result_list.get(result_list.size() - 5);
    long count_result = (Long) result_list.get(result_list.size() - 4);
    long lscan_result = (Long) result_list.get(result_list.size() - 3);
    long rscan_result = (Long) result_list.get(result_list.size() - 2);
    byte[] actual = (byte[]) result_list.get(result_list.size() - 1);
    String err_output = String.format("bin_sz %d offset %d set_sz %d", bin_sz, offset, set_sz);
    assertEquals("lscan1 - " + err_output, -1, lscan1_result);
    assertEquals("rscan1 - " + err_output, -1, rscan1_result);
    assertEquals("getint - " + err_output, 0, getint_result);
    assertEquals("count - " + err_output, 0, count_result);
    assertEquals("lscan - " + err_output, offset, lscan_result);
    assertEquals("rscan - " + err_output, offset + set_sz - 1, rscan_result);
    assertArrayEquals("op - " + err_output, expected, actual);
}
Also used : Bin(com.aerospike.client.Bin) Record(com.aerospike.client.Record) Operation(com.aerospike.client.Operation) BitOperation(com.aerospike.client.operation.BitOperation)

Example 95 with Bin

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

the class TestOperateList method operateList6.

@Test
public void operateList6() {
    // Test clear.
    Key key = new Key(args.namespace, args.set, "oplkey6");
    client.delete(null, key);
    WritePolicy policy = new WritePolicy();
    policy.respondAllOps = true;
    List<Value> itemList = new ArrayList<Value>();
    itemList.add(Value.get("s11"));
    itemList.add(Value.get("s22222"));
    itemList.add(Value.get("s3333333"));
    itemList.add(Value.get("s4444444444"));
    itemList.add(Value.get("s5555555555555555"));
    Record record = client.operate(policy, key, Operation.put(new Bin("otherbin", 11)), Operation.get("otherbin"), ListOperation.appendItems(binName, itemList), ListOperation.clear(binName), ListOperation.size(binName));
    assertRecordFound(key, record);
    // System.out.println("Record: " + record);
    List<?> list = record.getList("otherbin");
    assertEquals(2, list.size());
    assertNull(list.get(0));
    assertEquals(11, (long) (Long) list.get(1));
    list = record.getList(binName);
    long size = (Long) list.get(0);
    assertEquals(5, size);
    // clear() does not return value by default, but we set respondAllOps, so it returns null.
    assertNull(list.get(1));
    size = (Long) list.get(2);
    assertEquals(0, size);
}
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) WritePolicy(com.aerospike.client.policy.WritePolicy) 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