RSet.diff and RSet.intersection methods were added

pull/484/head
Nikita 9 years ago
parent 3302870c57
commit a249586ef8

@ -263,6 +263,58 @@ public class RedissonSet<V> extends RedissonExpirable implements RSet<V> {
return commandExecutor.writeAsync(getName(), codec, RedisCommands.SUNION, args.toArray());
}
@Override
public int diff(String... names) {
return get(diffAsync(names));
}
@Override
public Future<Integer> diffAsync(String... names) {
List<Object> args = new ArrayList<Object>(names.length + 1);
args.add(getName());
args.addAll(Arrays.asList(names));
return commandExecutor.writeAsync(getName(), codec, RedisCommands.SDIFFSTORE_INT, args.toArray());
}
@Override
public Set<V> readDiff(String... names) {
return get(readDiffAsync(names));
}
@Override
public Future<Set<V>> readDiffAsync(String... names) {
List<Object> args = new ArrayList<Object>(names.length + 1);
args.add(getName());
args.addAll(Arrays.asList(names));
return commandExecutor.writeAsync(getName(), codec, RedisCommands.SDIFF, args.toArray());
}
@Override
public int intersection(String... names) {
return get(intersectionAsync(names));
}
@Override
public Future<Integer> intersectionAsync(String... names) {
List<Object> args = new ArrayList<Object>(names.length + 1);
args.add(getName());
args.addAll(Arrays.asList(names));
return commandExecutor.writeAsync(getName(), codec, RedisCommands.SINTERSTORE_INT, args.toArray());
}
@Override
public Set<V> readIntersection(String... names) {
return get(readIntersectionAsync(names));
}
@Override
public Future<Set<V>> readIntersectionAsync(String... names) {
List<Object> args = new ArrayList<Object>(names.length + 1);
args.add(getName());
args.addAll(Arrays.asList(names));
return commandExecutor.writeAsync(getName(), codec, RedisCommands.SINTER, args.toArray());
}
@Override
public void clear() {
delete();

@ -394,4 +394,56 @@ public class RedissonSetMultimapValues<V> extends RedissonExpirable implements R
delete();
}
@Override
public int diff(String... names) {
return get(diffAsync(names));
}
@Override
public Future<Integer> diffAsync(String... names) {
List<Object> args = new ArrayList<Object>(names.length + 1);
args.add(getName());
args.addAll(Arrays.asList(names));
return commandExecutor.writeAsync(getName(), codec, RedisCommands.SDIFFSTORE_INT, args.toArray());
}
@Override
public Set<V> readDiff(String... names) {
return get(readDiffAsync(names));
}
@Override
public Future<Set<V>> readDiffAsync(String... names) {
List<Object> args = new ArrayList<Object>(names.length + 1);
args.add(getName());
args.addAll(Arrays.asList(names));
return commandExecutor.writeAsync(getName(), codec, RedisCommands.SDIFF, args.toArray());
}
@Override
public int intersection(String... names) {
return get(intersectionAsync(names));
}
@Override
public Future<Integer> intersectionAsync(String... names) {
List<Object> args = new ArrayList<Object>(names.length + 1);
args.add(getName());
args.addAll(Arrays.asList(names));
return commandExecutor.writeAsync(getName(), codec, RedisCommands.SINTERSTORE_INT, args.toArray());
}
@Override
public Set<V> readIntersection(String... names) {
return get(readIntersectionAsync(names));
}
@Override
public Future<Set<V>> readIntersectionAsync(String... names) {
List<Object> args = new ArrayList<Object>(names.length + 1);
args.add(getName());
args.addAll(Arrays.asList(names));
return commandExecutor.writeAsync(getName(), codec, RedisCommands.SINTER, args.toArray());
}
}

@ -129,8 +129,12 @@ public interface RedisCommands {
RedisStrictCommand<Integer> SCARD_INT = new RedisStrictCommand<Integer>("SCARD", new IntegerReplayConvertor());
RedisStrictCommand<Long> SCARD = new RedisStrictCommand<Long>("SCARD");
RedisStrictCommand<Integer> SUNIONSTORE_INT = new RedisStrictCommand<Integer>("SUNIONSTORE", new IntegerReplayConvertor());
RedisStrictCommand<Integer> SDIFFSTORE_INT = new RedisStrictCommand<Integer>("SDIFFSTORE", new IntegerReplayConvertor());
RedisStrictCommand<Integer> SINTERSTORE_INT = new RedisStrictCommand<Integer>("SINTERSTORE", new IntegerReplayConvertor());
RedisStrictCommand<Long> SUNIONSTORE = new RedisStrictCommand<Long>("SUNIONSTORE");
RedisCommand<Set<Object>> SUNION = new RedisCommand<Set<Object>>("SUNION", new ObjectSetReplayDecoder<Object>());
RedisCommand<Set<Object>> SDIFF = new RedisCommand<Set<Object>>("SDIFF", new ObjectSetReplayDecoder<Object>());
RedisCommand<Set<Object>> SINTER = new RedisCommand<Set<Object>>("SINTER", new ObjectSetReplayDecoder<Object>());
RedisCommand<Void> LSET = new RedisCommand<Void>("LSET", new VoidReplayConvertor(), 3);
RedisCommand<Object> LPOP = new RedisCommand<Object>("LPOP");

@ -68,4 +68,40 @@ public interface RSet<V> extends Set<V>, RExpirable, RSetAsync<V> {
*/
Set<V> readUnion(String... names);
/**
* Diff sets specified by name and write to current set.
* If current set already exists, it is overwritten.
*
* @param names
* @return
*/
int diff(String... names);
/**
* Diff sets specified by name with current set.
* Without current set state change.
*
* @param names
* @return
*/
Set<V> readDiff(String... names);
/**
* Intersection sets specified by name and write to current set.
* If current set already exists, it is overwritten.
*
* @param names
* @return
*/
int intersection(String... names);
/**
* Intersection sets specified by name with current set.
* Without current set state change.
*
* @param names
* @return
*/
Set<V> readIntersection(String... names);
}

@ -71,4 +71,40 @@ public interface RSetAsync<V> extends RCollectionAsync<V> {
*/
Future<Set<V>> readUnionAsync(String... keys);
/**
* Diff sets specified by name and write to current set.
* If current set already exists, it is overwritten.
*
* @param names
* @return
*/
Future<Integer> diffAsync(String... keys);
/**
* Diff sets specified by name with current set.
* Without current set state change.
*
* @param names
* @return
*/
Future<Set<V>> readDiffAsync(String... keys);
/**
* Intersection sets specified by name and write to current set.
* If current set already exists, it is overwritten.
*
* @param names
* @return
*/
Future<Integer> intersectionAsync(String... keys);
/**
* Intersection sets specified by name with current set.
* Without current set state change.
*
* @param names
* @return
*/
Future<Set<V>> readIntersectionAsync(String... keys);
}

@ -334,7 +334,81 @@ public class RedissonSetTest extends BaseTest {
assertThat(set).containsOnly(5, 6);
}
@Test
public void testDiff() {
RSet<Integer> set = redisson.getSet("set");
set.add(5);
set.add(6);
RSet<Integer> set1 = redisson.getSet("set1");
set1.add(1);
set1.add(2);
set1.add(3);
RSet<Integer> set2 = redisson.getSet("set2");
set2.add(3);
set2.add(4);
set2.add(5);
assertThat(set.diff("set1", "set2")).isEqualTo(2);
assertThat(set).containsOnly(1, 2);
}
@Test
public void testReadDiff() {
RSet<Integer> set = redisson.getSet("set");
set.add(5);
set.add(7);
set.add(6);
RSet<Integer> set1 = redisson.getSet("set1");
set1.add(1);
set1.add(2);
set1.add(5);
RSet<Integer> set2 = redisson.getSet("set2");
set2.add(3);
set2.add(4);
set2.add(5);
assertThat(set.readDiff("set1", "set2")).containsOnly(7, 6);
assertThat(set).containsOnly(6, 5, 7);
}
@Test
public void testIntersection() {
RSet<Integer> set = redisson.getSet("set");
set.add(5);
set.add(6);
RSet<Integer> set1 = redisson.getSet("set1");
set1.add(1);
set1.add(2);
set1.add(3);
RSet<Integer> set2 = redisson.getSet("set2");
set2.add(3);
set2.add(4);
set2.add(5);
assertThat(set.intersection("set1", "set2")).isEqualTo(1);
assertThat(set).containsOnly(3);
}
@Test
public void testReadIntersection() {
RSet<Integer> set = redisson.getSet("set");
set.add(5);
set.add(7);
set.add(6);
RSet<Integer> set1 = redisson.getSet("set1");
set1.add(1);
set1.add(2);
set1.add(5);
RSet<Integer> set2 = redisson.getSet("set2");
set2.add(3);
set2.add(4);
set2.add(5);
assertThat(set.readIntersection("set1", "set2")).containsOnly(5);
assertThat(set).containsOnly(6, 5, 7);
}
@Test
public void testMove() throws Exception {
RSet<Integer> set = redisson.getSet("set");

Loading…
Cancel
Save