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);
}
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);
}
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;
}
}
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);
}
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);
}
Aggregations