RBucket.getAndDelete method added. #1247

pull/1249/head
Nikita 7 years ago
parent e30739cb19
commit fa48e706ff

@ -102,6 +102,20 @@ public class RedissonBucket<V> extends RedissonExpirable implements RBucket<V> {
return commandExecutor.readAsync(getName(), codec, RedisCommands.GET, getName());
}
@Override
public V getAndDelete() {
return get(getAndDeleteAsync());
}
@Override
public RFuture<V> getAndDeleteAsync() {
return commandExecutor.evalWriteAsync(getName(), codec, RedisCommands.EVAL_OBJECT,
"local currValue = redis.call('get', KEYS[1]); "
+ "redis.call('del', KEYS[1]); "
+ "return currValue; ",
Collections.<Object>singletonList(getName()));
}
@Override
public long size() {
return get(sizeAsync());

@ -35,6 +35,8 @@ public interface RBucket<V> extends RExpirable, RBucketAsync<V> {
V get();
V getAndDelete();
boolean trySet(V value);
boolean trySet(V value, long timeToLive, TimeUnit timeUnit);

@ -35,6 +35,8 @@ public interface RBucketAsync<V> extends RExpirableAsync {
RFuture<V> getAsync();
RFuture<V> getAndDeleteAsync();
RFuture<Boolean> trySetAsync(V value);
RFuture<Boolean> trySetAsync(V value, long timeToLive, TimeUnit timeUnit);

@ -12,6 +12,15 @@ import org.redisson.api.RBucket;
public class RedissonBucketTest extends BaseTest {
@Test
public void testGetAndDelete() {
RBucket<Integer> al = redisson.getBucket("test");
al.set(10);
assertThat(al.getAndDelete()).isEqualTo(10);
assertThat(al.isExists()).isFalse();
assertThat(al.getAndDelete()).isNull();
}
@Test
public void testSize() {
RBucket<String> bucket = redisson.getBucket("testCompareAndSet");

Loading…
Cancel
Save