use of com.aerospike.client.policy.WritePolicy in project aerospike-client-java by aerospike.
the class Touch method runExample.
/**
* Demonstrate touch command.
*/
@Override
public void runExample(AerospikeClient client, Parameters params) throws Exception {
Key key = new Key(params.namespace, params.set, "touchkey");
Bin bin = new Bin(params.getBinName("touchbin"), "touchvalue");
console.info("Create record with 2 second expiration.");
WritePolicy writePolicy = new WritePolicy();
writePolicy.expiration = 2;
client.put(writePolicy, key, bin);
console.info("Touch same record with 5 second expiration.");
writePolicy.expiration = 5;
Record record = client.operate(writePolicy, key, Operation.touch(), Operation.getHeader());
if (record == null) {
throw new Exception(String.format("Failed to get: namespace=%s set=%s key=%s bin=%s value=%s", key.namespace, key.setName, key.userKey, bin.name, null));
}
if (record.expiration == 0) {
throw new Exception(String.format("Failed to get record expiration: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey));
}
console.info("Sleep 3 seconds.");
Thread.sleep(3000);
record = client.get(params.policy, key, bin.name);
if (record == null) {
throw new Exception(String.format("Failed to get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey));
}
console.info("Success. Record still exists.");
console.info("Sleep 4 seconds.");
Thread.sleep(4000);
record = client.get(params.policy, key, bin.name);
if (record == null) {
console.info("Success. Record expired as expected.");
} else {
console.error("Found record when it should have expired.");
}
}
use of com.aerospike.client.policy.WritePolicy in project aerospike-client-java by aerospike.
the class TestBatch method writeRecords.
@BeforeClass
public static void writeRecords() {
WritePolicy policy = new WritePolicy();
policy.expiration = 2592000;
for (int i = 1; i <= size; i++) {
Key key = new Key(args.namespace, args.set, keyPrefix + i);
Bin bin = new Bin(binName, valuePrefix + i);
client.put(policy, key, bin);
}
}
use of com.aerospike.client.policy.WritePolicy in project aerospike-client-java by aerospike.
the class TestTouch method touch.
@Test
public void touch() {
Key key = new Key(args.namespace, args.set, "touchkey");
Bin bin = new Bin(args.getBinName("touchbin"), "touchvalue");
WritePolicy writePolicy = new WritePolicy();
writePolicy.expiration = 2;
client.put(writePolicy, key, bin);
writePolicy.expiration = 5;
Record record = client.operate(writePolicy, key, Operation.touch(), Operation.getHeader());
assertRecordFound(key, record);
assertNotEquals(0, record.expiration);
Util.sleep(3000);
record = client.get(null, key, bin.name);
assertRecordFound(key, record);
Util.sleep(4000);
record = client.get(null, key, bin.name);
assertNull(record);
}
use of com.aerospike.client.policy.WritePolicy 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);
}
use of com.aerospike.client.policy.WritePolicy in project aerospike-client-java by aerospike.
the class TestAsyncBatch method initialize.
@BeforeClass
public static void initialize() {
sendKeys = new Key[size];
for (int i = 0; i < size; i++) {
sendKeys[i] = new Key(args.namespace, args.set, keyPrefix + (i + 1));
}
AsyncMonitor monitor = new AsyncMonitor();
WriteHandler handler = new WriteHandler(monitor, size);
WritePolicy policy = new WritePolicy();
policy.expiration = 2592000;
for (int i = 1; i <= size; i++) {
Key key = sendKeys[i - 1];
Bin bin = new Bin(binName, valuePrefix + i);
client.put(eventLoop, handler, policy, key, bin);
}
monitor.waitTillComplete();
}
Aggregations