Search in sources :

Example 1 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, HashMap<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) ByteArrayByteIterator(com.yahoo.ycsb.ByteArrayByteIterator) ByteIterator(com.yahoo.ycsb.ByteIterator) Bin(com.aerospike.client.Bin) HashMap(java.util.HashMap) Map(java.util.Map) Key(com.aerospike.client.Key)

Example 2 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.
 * @throws Exception on aerorpike or cache errors.
 */
public void set(String set, String skey, Object value) throws Exception {
    WritePolicy policy = new WritePolicy();
    Key key = new Key("test", set, skey);
    Bin bin1 = new Bin("value", value);
    ae.getClient().put(null, key, bin1);
}
Also used : Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key) WritePolicy(com.aerospike.client.policy.WritePolicy)

Example 3 with Bin

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

the class RedissonClient method addList.

/**
 * Add a list to the cach2k/Aerorpike
 * @param id String. The name of the value.
 * @param list List. The value to set, a list.
 */
public void addList(String id, List list) throws Exception {
    if (ae == null) {
        cacheDb.put(id, list);
        return;
    }
    Key key = new Key("test", "cache", id);
    Bin bin1 = new Bin("list", list);
    ae.getClient().put(null, key, bin1);
}
Also used : Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key)

Example 4 with Bin

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

the class RedissonClient method hmset.

/**
 * Mimic a REDIS mhset operation.
 * @param id String. The key of the map.
 * @param m Map. The map to set.
 */
public void hmset(String id, Map m) throws Exception {
    if (ae == null) {
        cache.put(id, m);
        return;
    }
    Key key = new Key("test", "cache", id);
    Bin bin1 = new Bin("value", m);
    ae.getClient().put(null, key, bin1);
}
Also used : Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key)

Example 5 with Bin

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

the class RedissonClient method addSet.

/**
 * Ass a set of strings to the cache or aerospike. Used for blacklists.
 * @param name String. The name of the set of strings.
 * @param set Set. The set of strings.
 * @throws Exception
 */
public void addSet(String name, Set set) throws Exception {
    if (ae == null) {
        cacheDb.put(name, set);
        return;
    }
    Key key = new Key("test", "database", "rtb4free");
    String data = mapper.writer().writeValueAsString(set);
    Bin bin1 = new Bin("set", data);
    ae.getClient().put(null, key, bin1);
}
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