Skip to content

Commit

Permalink
ZUNION/ZINTER commands introduced redis#1450
Browse files Browse the repository at this point in the history
  • Loading branch information
sokomishalov committed Nov 6, 2020
1 parent fe70d44 commit 905d985
Show file tree
Hide file tree
Showing 19 changed files with 1,058 additions and 260 deletions.
48 changes: 44 additions & 4 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -1793,14 +1793,34 @@ public RedisFuture<Double> zincrby(K key, double amount, V member) {
return dispatch(commandBuilder.zincrby(key, amount, member));
}

@Override
public RedisFuture<List<V>> zinter(long numkey, K... keys) {
return dispatch(commandBuilder.zinter(numkey, keys));
}

@Override
public RedisFuture<List<V>> zinter(long numkey, ZAggregateArgs aggregateArgs, K... keys) {
return dispatch(commandBuilder.zinter(numkey, aggregateArgs, keys));
}

@Override
public RedisFuture<List<ScoredValue<V>>> zinterWithScores(long numkey, K... keys) {
return dispatch(commandBuilder.zinterWithScores(numkey, keys));
}

@Override
public RedisFuture<List<ScoredValue<V>>> zinterWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys) {
return dispatch(commandBuilder.zinterWithScores(numkey, aggregateArgs, keys));
}

@Override
public RedisFuture<Long> zinterstore(K destination, K... keys) {
return dispatch(commandBuilder.zinterstore(destination, keys));
}

@Override
public RedisFuture<Long> zinterstore(K destination, ZStoreArgs storeArgs, K... keys) {
return dispatch(commandBuilder.zinterstore(destination, storeArgs, keys));
public RedisFuture<Long> zinterstore(K destination, ZAggregateArgs aggregateArgs, K... keys) {
return dispatch(commandBuilder.zinterstore(destination, aggregateArgs, keys));
}

@Override
Expand Down Expand Up @@ -2255,14 +2275,34 @@ public RedisFuture<Double> zscore(K key, V member) {
return dispatch(commandBuilder.zscore(key, member));
}

@Override
public RedisFuture<List<V>> zunion(long numkey, K... keys) {
return dispatch(commandBuilder.zunion(numkey, keys));
}

@Override
public RedisFuture<List<V>> zunion(long numkey, ZAggregateArgs aggregateArgs, K... keys) {
return dispatch(commandBuilder.zunion(numkey, aggregateArgs, keys));
}

@Override
public RedisFuture<List<ScoredValue<V>>> zunionWithScores(long numkey, K... keys) {
return dispatch(commandBuilder.zunionWithScores(numkey, keys));
}

@Override
public RedisFuture<List<ScoredValue<V>>> zunionWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys) {
return dispatch(commandBuilder.zunionWithScores(numkey, aggregateArgs, keys));
}

@Override
public RedisFuture<Long> zunionstore(K destination, K... keys) {
return dispatch(commandBuilder.zunionstore(destination, keys));
}

@Override
public RedisFuture<Long> zunionstore(K destination, ZStoreArgs storeArgs, K... keys) {
return dispatch(commandBuilder.zunionstore(destination, storeArgs, keys));
public RedisFuture<Long> zunionstore(K destination, ZAggregateArgs aggregateArgs, K... keys) {
return dispatch(commandBuilder.zunionstore(destination, aggregateArgs, keys));
}

private byte[] encodeScript(String script) {
Expand Down
48 changes: 44 additions & 4 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -1866,14 +1866,34 @@ public Mono<Double> zincrby(K key, double amount, V member) {
return createMono(() -> commandBuilder.zincrby(key, amount, member));
}

@Override
public Flux<V> zinter(long numkey, K... keys) {
return createDissolvingFlux(() -> commandBuilder.zinter(numkey, keys));
}

@Override
public Flux<V> zinter(long numkey, ZAggregateArgs aggregateArgs, K... keys) {
return createDissolvingFlux(() -> commandBuilder.zinter(numkey, aggregateArgs, keys));
}

@Override
public Flux<ScoredValue<V>> zinterWithScores(long numkey, K... keys) {
return createDissolvingFlux(() -> commandBuilder.zinterWithScores(numkey, keys));
}

@Override
public Flux<ScoredValue<V>> zinterWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys) {
return createDissolvingFlux(() -> commandBuilder.zinterWithScores(numkey, aggregateArgs, keys));
}

@Override
public Mono<Long> zinterstore(K destination, K... keys) {
return createMono(() -> commandBuilder.zinterstore(destination, keys));
}

@Override
public Mono<Long> zinterstore(K destination, ZStoreArgs storeArgs, K... keys) {
return createMono(() -> commandBuilder.zinterstore(destination, storeArgs, keys));
public Mono<Long> zinterstore(K destination, ZAggregateArgs aggregateArgs, K... keys) {
return createMono(() -> commandBuilder.zinterstore(destination, aggregateArgs, keys));
}

@Override
Expand Down Expand Up @@ -2320,14 +2340,34 @@ public Mono<Double> zscore(K key, V member) {
return createMono(() -> commandBuilder.zscore(key, member));
}

@Override
public Flux<V> zunion(long numkey, K... keys) {
return createDissolvingFlux(() -> commandBuilder.zunion(numkey, keys));
}

@Override
public Flux<V> zunion(long numkey, ZAggregateArgs aggregateArgs, K... keys) {
return createDissolvingFlux(() -> commandBuilder.zunion(numkey, aggregateArgs, keys));
}

@Override
public Flux<ScoredValue<V>> zunionWithScores(long numkey, K... keys) {
return createDissolvingFlux(() -> commandBuilder.zunionWithScores(numkey, keys));
}

@Override
public Flux<ScoredValue<V>> zunionWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys) {
return createDissolvingFlux(() -> commandBuilder.zunionWithScores(numkey, aggregateArgs, keys));
}

@Override
public Mono<Long> zunionstore(K destination, K... keys) {
return createMono(() -> commandBuilder.zunionstore(destination, keys));
}

@Override
public Mono<Long> zunionstore(K destination, ZStoreArgs storeArgs, K... keys) {
return createMono(() -> commandBuilder.zunionstore(destination, storeArgs, keys));
public Mono<Long> zunionstore(K destination, ZAggregateArgs aggregateArgs, K... keys) {
return createMono(() -> commandBuilder.zunionstore(destination, aggregateArgs, keys));
}

private byte[] encodeScript(String script) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/lettuce/core/CompositeArgument.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @since 5.0
* @see CommandArgs
* @see SetArgs
* @see ZStoreArgs
* @see ZAggregateArgs
* @see GeoArgs
*/
public interface CompositeArgument {
Expand Down
74 changes: 67 additions & 7 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2609,19 +2609,49 @@ Command<K, V, Double> zincrby(K key, double amount, V member) {
return createCommand(ZINCRBY, new DoubleOutput<>(codec), args);
}

Command<K, V, List<V>> zinter(long numkey, K... keys) {
notEmpty(keys);

return zinter(numkey, new ZAggregateArgs(), keys);
}

Command<K, V, List<V>> zinter(long numkey, ZAggregateArgs aggregateArgs, K... keys) {
notEmpty(keys);

CommandArgs<K, V> args = new CommandArgs<>(codec);
args.add(numkey).addKeys(keys);
aggregateArgs.build(args);
return createCommand(ZINTER, new ValueListOutput<>(codec), args);
}

Command<K, V, List<ScoredValue<V>>> zinterWithScores(long numkey, K... keys) {
notEmpty(keys);

return zinterWithScores(numkey, new ZAggregateArgs(), keys);
}

Command<K, V, List<ScoredValue<V>>> zinterWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys) {
notEmpty(keys);

CommandArgs<K, V> args = new CommandArgs<>(codec);
args.add(numkey).addKeys(keys).add(WITHSCORES);
aggregateArgs.build(args);
return createCommand(ZINTER, new ScoredValueListOutput<>(codec), args);
}

Command<K, V, Long> zinterstore(K destination, K... keys) {
notEmpty(keys);

return zinterstore(destination, new ZStoreArgs(), keys);
return zinterstore(destination, new ZAggregateArgs(), keys);
}

Command<K, V, Long> zinterstore(K destination, ZStoreArgs storeArgs, K... keys) {
Command<K, V, Long> zinterstore(K destination, ZAggregateArgs aggregateArgs, K... keys) {
LettuceAssert.notNull(destination, "Destination " + MUST_NOT_BE_NULL);
LettuceAssert.notNull(storeArgs, "ZStoreArgs " + MUST_NOT_BE_NULL);
LettuceAssert.notNull(aggregateArgs, "ZStoreArgs " + MUST_NOT_BE_NULL);
notEmpty(keys);

CommandArgs<K, V> args = new CommandArgs<>(codec).addKey(destination).add(keys.length).addKeys(keys);
storeArgs.build(args);
aggregateArgs.build(args);
return createCommand(ZINTERSTORE, new IntegerOutput<>(codec), args);
}

Expand Down Expand Up @@ -3230,19 +3260,49 @@ Command<K, V, Double> zscore(K key, V member) {
return createCommand(ZSCORE, new DoubleOutput<>(codec), key, member);
}

Command<K, V, List<V>> zunion(long numkey, K... keys) {
notEmpty(keys);

return zunion(numkey, new ZAggregateArgs(), keys);
}

Command<K, V, List<V>> zunion(long numkey, ZAggregateArgs aggregateArgs, K... keys) {
notEmpty(keys);

CommandArgs<K, V> args = new CommandArgs<>(codec);
args.add(numkey).addKeys(keys);
aggregateArgs.build(args);
return createCommand(ZUNION, new ValueListOutput<>(codec), args);
}

Command<K, V, List<ScoredValue<V>>> zunionWithScores(long numkey, K... keys) {
notEmpty(keys);

return zunionWithScores(numkey, new ZAggregateArgs(), keys);
}

Command<K, V, List<ScoredValue<V>>> zunionWithScores(long numkey, ZAggregateArgs aggregateArgs, K... keys) {
notEmpty(keys);

CommandArgs<K, V> args = new CommandArgs<>(codec);
args.add(numkey).addKeys(keys).add(WITHSCORES);
aggregateArgs.build(args);
return createCommand(ZUNION, new ScoredValueListOutput<>(codec), args);
}

Command<K, V, Long> zunionstore(K destination, K... keys) {
notEmpty(keys);
LettuceAssert.notNull(destination, "Destination " + MUST_NOT_BE_NULL);

return zunionstore(destination, new ZStoreArgs(), keys);
return zunionstore(destination, new ZAggregateArgs(), keys);
}

Command<K, V, Long> zunionstore(K destination, ZStoreArgs storeArgs, K... keys) {
Command<K, V, Long> zunionstore(K destination, ZAggregateArgs aggregateArgs, K... keys) {
notEmpty(keys);

CommandArgs<K, V> args = new CommandArgs<>(codec);
args.addKey(destination).add(keys.length).addKeys(keys);
storeArgs.build(args);
aggregateArgs.build(args);
return createCommand(ZUNIONSTORE, new IntegerOutput<>(codec), args);
}

Expand Down
Loading

0 comments on commit 905d985

Please sign in to comment.