@Override public RFuture<Boolean> trySetAsync(V value, long timeToLive, TimeUnit timeUnit) { if (value == null) { throw new IllegalArgumentException("Value can't be null"); } return commandExecutor.writeAsync(getName(), codec, RedisCommands.SETPXNX, getName(), encode(value), "PX", timeUnit.toMillis(timeToLive), "NX"); }
@Override public RFuture<Boolean> trySetAsync(V value, long timeToLive, TimeUnit timeUnit) { if (value == null) { throw new IllegalArgumentException("Value can't be null"); } return commandExecutor.writeAsync(getName(), codec, RedisCommands.SETPXNX, getName(), encode(value), "PX", timeUnit.toMillis(timeToLive), "NX"); }
@Override public RFuture<Boolean> compareAndSetAsync(V expect, V update) { if (expect == null && update == null) { return trySetAsync(null); } if (expect == null) { return trySetAsync(update); } if (update == null) { return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN, "if redis.call('get', KEYS[1]) == ARGV[1] then " + "redis.call('del', KEYS[1]); " + "return 1 " + "else " + "return 0 end", Collections.<Object>singletonList(getName()), encode(expect)); } return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN, "if redis.call('get', KEYS[1]) == ARGV[1] then " + "redis.call('set', KEYS[1], ARGV[2]); " + "return 1 " + "else " + "return 0 end", Collections.<Object>singletonList(getName()), encode(expect), encode(update)); }
@Override public RFuture<Boolean> compareAndSetAsync(V expect, V update) { if (expect == null && update == null) { return trySetAsync(null); } if (expect == null) { return trySetAsync(update); } if (update == null) { return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN, "if redis.call('get', KEYS[1]) == ARGV[1] then " + "redis.call('del', KEYS[1]); " + "return 1 " + "else " + "return 0 end", Collections.<Object>singletonList(getName()), encode(expect)); } return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN, "if redis.call('get', KEYS[1]) == ARGV[1] then " + "redis.call('set', KEYS[1], ARGV[2]); " + "return 1 " + "else " + "return 0 end", Collections.<Object>singletonList(getName()), encode(expect), encode(update)); }
@Override public RFuture<Void> setAsync(V value, long timeToLive, TimeUnit timeUnit) { if (value == null) { return commandExecutor.writeAsync(getName(), RedisCommands.DEL_VOID, getName()); } return commandExecutor.writeAsync(getName(), codec, RedisCommands.PSETEX, getName(), timeUnit.toMillis(timeToLive), encode(value)); }
@Override public RFuture<V> getAndSetAsync(V newValue) { if (newValue == null) { return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_OBJECT, "local v = redis.call('get', KEYS[1]); " + "redis.call('del', KEYS[1]); " + "return v", Collections.<Object>singletonList(getName())); } return commandExecutor.writeAsync(getName(), codec, RedisCommands.GETSET, getName(), encode(newValue)); }
@Override public RFuture<Void> setAsync(V value, long timeToLive, TimeUnit timeUnit) { if (value == null) { return commandExecutor.writeAsync(getName(), RedisCommands.DEL_VOID, getName()); } return commandExecutor.writeAsync(getName(), codec, RedisCommands.PSETEX, getName(), timeUnit.toMillis(timeToLive), encode(value)); }
@Override public RFuture<V> getAndSetAsync(V newValue) { if (newValue == null) { return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_OBJECT, "local v = redis.call('get', KEYS[1]); " + "redis.call('del', KEYS[1]); " + "return v", Collections.<Object>singletonList(getName())); } return commandExecutor.writeAsync(getName(), codec, RedisCommands.GETSET, getName(), encode(newValue)); }
@Override public RFuture<Void> setAsync(V value) { if (value == null) { return commandExecutor.writeAsync(getName(), RedisCommands.DEL_VOID, getName()); } return commandExecutor.writeAsync(getName(), codec, RedisCommands.SET, getName(), encode(value)); }
@Override public RFuture<Boolean> trySetAsync(V value) { if (value == null) { return commandExecutor.readAsync(getName(), codec, RedisCommands.NOT_EXISTS, getName()); } return commandExecutor.writeAsync(getName(), codec, RedisCommands.SETNX, getName(), encode(value)); }
@Override public RFuture<Boolean> trySetAsync(V value) { if (value == null) { return commandExecutor.readAsync(getName(), codec, RedisCommands.NOT_EXISTS, getName()); } return commandExecutor.writeAsync(getName(), codec, RedisCommands.SETNX, getName(), encode(value)); }
@Override public RFuture<Void> setAsync(V value) { if (value == null) { return commandExecutor.writeAsync(getName(), RedisCommands.DEL_VOID, getName()); } return commandExecutor.writeAsync(getName(), codec, RedisCommands.SET, getName(), encode(value)); }
@Override public RFuture<Boolean> trySetAsync(V value, long timeToLive, TimeUnit timeUnit) { if (value == null) { throw new IllegalArgumentException("Value can't be null"); } return commandExecutor.writeAsync(getName(), codec, RedisCommands.SETPXNX, getName(), encode(value), "PX", timeUnit.toMillis(timeToLive), "NX"); }
@Override public RFuture<Boolean> compareAndSetAsync(V expect, V update) { if (expect == null && update == null) { return trySetAsync(null); } if (expect == null) { return trySetAsync(update); } if (update == null) { return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN, "if redis.call('get', KEYS[1]) == ARGV[1] then " + "redis.call('del', KEYS[1]); " + "return 1 " + "else " + "return 0 end", Collections.<Object>singletonList(getName()), encode(expect)); } return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_BOOLEAN, "if redis.call('get', KEYS[1]) == ARGV[1] then " + "redis.call('set', KEYS[1], ARGV[2]); " + "return 1 " + "else " + "return 0 end", Collections.<Object>singletonList(getName()), encode(expect), encode(update)); }
@Override public RFuture<V> getAndSetAsync(V newValue) { if (newValue == null) { return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_OBJECT, "local v = redis.call('get', KEYS[1]); " + "redis.call('del', KEYS[1]); " + "return v", Collections.<Object>singletonList(getName())); } return commandExecutor.writeAsync(getName(), codec, RedisCommands.GETSET, getName(), encode(newValue)); }
@Override public RFuture<Void> setAsync(V value, long timeToLive, TimeUnit timeUnit) { if (value == null) { return commandExecutor.writeAsync(getName(), RedisCommands.DEL_VOID, getName()); } return commandExecutor.writeAsync(getName(), codec, RedisCommands.PSETEX, getName(), timeUnit.toMillis(timeToLive), encode(value)); }
@Override public RFuture<Void> setAsync(V value) { if (value == null) { return commandExecutor.writeAsync(getName(), RedisCommands.DEL_VOID, getName()); } return commandExecutor.writeAsync(getName(), codec, RedisCommands.SET, getName(), encode(value)); }
@Override public RFuture<Boolean> trySetAsync(V value) { if (value == null) { return commandExecutor.readAsync(getName(), codec, RedisCommands.NOT_EXISTS, getName()); } return commandExecutor.writeAsync(getName(), codec, RedisCommands.SETNX, getName(), encode(value)); }