Search in sources :

Example 46 with Key

use of com.aerospike.client.Key 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 47 with Key

use of com.aerospike.client.Key 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 48 with Key

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

the class RedissonClient method hgetAll.

/**
	 * Mimic a REDIS hgetAll operation.
	 * @param id String. They key to get.
	 * @return Map. The map stored at 'key'
	 * @throws Exception on aerospike/cache2k errors.
	 */
public Map hgetAll(String id) {
    if (ae == null) {
        return (Map) cache.peek(id);
    }
    Key key = new Key("test", "cache", id);
    Record record = null;
    record = ae.getClient().get(null, key);
    if (record == null) {
        return null;
    }
    Map map = (Map) record.bins.get("value");
    return map;
}
Also used : Record(com.aerospike.client.Record) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) Key(com.aerospike.client.Key)

Example 49 with Key

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

the class RedissonClient method getMap.

/**
	 * Return the User object (as a map) from the database.
	 * @param name String. the name of the user.
	 * @return ConcurrentHashMap. The map representation of the user.
	 * @throws Exception on cache2k/aerorpike errors.
	 */
public ConcurrentHashMap getMap(String name) throws Exception {
    if (ae == null) {
        return (ConcurrentHashMap) cacheDb.peek(name);
    }
    Key key = new Key("test", "database", "rtb4free");
    Record record = null;
    record = ae.getClient().get(null, key);
    if (record == null) {
        return new ConcurrentHashMap();
    }
    String content = (String) record.bins.get("map");
    return mapper.readValue(content, ConcurrentHashMap.class);
}
Also used : Record(com.aerospike.client.Record) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Key(com.aerospike.client.Key)

Example 50 with Key

use of com.aerospike.client.Key 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

Key (com.aerospike.client.Key)204 Record (com.aerospike.client.Record)106 Bin (com.aerospike.client.Bin)104 Test (org.junit.Test)79 AerospikeException (com.aerospike.client.AerospikeException)50 ArrayList (java.util.ArrayList)50 Value (com.aerospike.client.Value)37 HashMap (java.util.HashMap)32 List (java.util.List)31 WritePolicy (com.aerospike.client.policy.WritePolicy)21 Map (java.util.Map)15 Statement (com.aerospike.client.query.Statement)10 BeforeClass (org.junit.BeforeClass)10 Policy (com.aerospike.client.policy.Policy)9 RecordSet (com.aerospike.client.query.RecordSet)9 IndexTask (com.aerospike.client.task.IndexTask)8 IOException (java.io.IOException)6 Collections.singletonList (java.util.Collections.singletonList)6 AerospikeClient (com.aerospike.client.AerospikeClient)5 BatchRead (com.aerospike.client.BatchRead)5