Merge pull request #367 from thrau/master

Support for SMOVE command in RSet, RSetAsync, RSetReactive. #366
pull/365/merge
Nikita Koksharov 9 years ago
commit 220d456ea0

@ -189,6 +189,16 @@ public class RedissonSet<V> extends RedissonExpirable implements RSet<V> {
return get(removeAsync((V)value));
}
@Override
public Future<Boolean> moveAsync(String destination, V member) {
return commandExecutor.writeAsync(getName(), codec, RedisCommands.SMOVE, getName(), destination, member);
}
@Override
public boolean move(String destination, V member) {
return get(moveAsync(destination, member));
}
@Override
public boolean containsAll(Collection<?> c) {
return get(containsAllAsync(c));

@ -34,4 +34,13 @@ public interface RSetReactive<V> extends RCollectionReactive<V> {
*/
Publisher<V> removeRandom();
/**
* Move a member from this set to the given destination set in async mode.
*
* @param destination the destination set
* @param member the member to move
* @return true if the element is moved, false if the element is not a
* member of this set or no operation was performed
*/
Publisher<Boolean> move(String destination, V member);
}

@ -108,6 +108,7 @@ public interface RedisCommands {
RedisCommand<Object> SPOP_SINGLE = new RedisCommand<Object>("SPOP");
RedisCommand<Boolean> SADD_SINGLE = new RedisCommand<Boolean>("SADD", new BooleanReplayConvertor(), 2);
RedisCommand<Boolean> SREM_SINGLE = new RedisCommand<Boolean>("SREM", new BooleanReplayConvertor(), 2);
RedisCommand<Boolean> SMOVE = new RedisCommand<Boolean>("SMOVE", new BooleanReplayConvertor(), 3);
RedisCommand<List<Object>> SMEMBERS = new RedisCommand<List<Object>>("SMEMBERS", new ObjectListReplayDecoder<Object>());
RedisCommand<ListScanResult<Object>> SSCAN = new RedisCommand<ListScanResult<Object>>("SSCAN", new NestedMultiDecoder(new ObjectListReplayDecoder<Object>(), new ListScanResultReplayDecoder()), ValueType.OBJECT);
RedisCommand<ListScanResult<Object>> EVAL_SSCAN = new RedisCommand<ListScanResult<Object>>("EVAL", new NestedMultiDecoder(new ObjectListReplayDecoder<Object>(), new ListScanResultReplayDecoder()), ValueType.OBJECT);

@ -33,4 +33,14 @@ public interface RSet<V> extends Set<V>, RExpirable, RSetAsync<V> {
*/
V removeRandom();
/**
* Move a member from this set to the given destination set in.
*
* @param destination the destination set
* @param member the member to move
* @return true if the element is moved, false if the element is not a
* member of this set or no operation was performed
*/
boolean move(String destination, V member);
}

@ -34,4 +34,14 @@ public interface RSetAsync<V> extends RCollectionAsync<V> {
*/
Future<V> removeRandomAsync();
/**
* Move a member from this set to the given destination set in async mode.
*
* @param destination the destination set
* @param member the member to move
* @return true if the element is moved, false if the element is not a
* member of this set or no operation was performed
*/
Future<Boolean> moveAsync(String destination, V member);
}

@ -79,6 +79,11 @@ public class RedissonSetReactive<V> extends RedissonExpirableReactive implements
return commandExecutor.writeReactive(getName(), codec, RedisCommands.SREM_SINGLE, getName(), o);
}
@Override
public Publisher<Boolean> move(String destination, V member) {
return commandExecutor.writeReactive(getName(), codec, RedisCommands.SMOVE, getName(), destination, member);
}
@Override
public Publisher<Boolean> containsAll(Collection<?> c) {
return commandExecutor.evalReadReactive(getName(), codec, RedisCommands.EVAL_BOOLEAN_WITH_VALUES,

@ -221,4 +221,35 @@ public class RedissonSetReactiveTest extends BaseReactiveTest {
Assert.assertFalse(sync(set.retainAll(Arrays.asList(1, 2)))); // nothing changed
Assert.assertThat(sync(set), Matchers.containsInAnyOrder(1, 2));
}
@Test
public void testMove() throws Exception {
RSetReactive<Integer> set = redisson.getSet("set");
RSetReactive<Integer> otherSet = redisson.getSet("otherSet");
sync(set.add(1));
sync(set.add(2));
Assert.assertTrue(sync(set.move("otherSet", 1)));
Assert.assertEquals(1, sync(set.size()).intValue());
Assert.assertThat(sync(set), Matchers.contains(2));
Assert.assertEquals(1, sync(otherSet.size()).intValue());
Assert.assertThat(sync(otherSet), Matchers.contains(1));
}
@Test
public void testMoveNoMember() throws Exception {
RSetReactive<Integer> set = redisson.getSet("set");
RSetReactive<Integer> otherSet = redisson.getSet("otherSet");
set.add(1);
Assert.assertFalse(sync(set.move("otherSet", 2)));
Assert.assertEquals(1, sync(set.size()).intValue());
Assert.assertEquals(0, sync(otherSet.size()).intValue());
}
}

@ -288,4 +288,34 @@ public class RedissonSetTest extends BaseTest {
Assert.assertFalse(set.retainAll(Arrays.asList(1, 2))); // nothing changed
Assert.assertThat(set, Matchers.containsInAnyOrder(1, 2));
}
@Test
public void testMove() throws Exception {
RSet<Integer> set = redisson.getSet("set");
RSet<Integer> otherSet = redisson.getSet("otherSet");
set.add(1);
set.add(2);
Assert.assertTrue(set.move("otherSet", 1));
Assert.assertEquals(1, set.size());
Assert.assertThat(set, Matchers.contains(2));
Assert.assertEquals(1, otherSet.size());
Assert.assertThat(otherSet, Matchers.contains(1));
}
@Test
public void testMoveNoMember() throws Exception {
RSet<Integer> set = redisson.getSet("set");
RSet<Integer> otherSet = redisson.getSet("otherSet");
set.add(1);
Assert.assertFalse(set.move("otherSet", 2));
Assert.assertEquals(1, set.size());
Assert.assertEquals(0, otherSet.size());
}
}

Loading…
Cancel
Save