Skip to content

Commit

Permalink
Polishing #1450
Browse files Browse the repository at this point in the history
Revert zinterstore/zunionstore accepting ZAggregateArgs to retain binary compatibility. Remove numkey parameter as this parameter can be calculated from the number of specified keys to simplify API usage.

Reinstate builder and override methods in ZStoreArgs to retain binary compatibility.

Tweak Javadoc, add author tags and license headers. Fix Coroutines zmscore signature.

Original pull request: #1469.
  • Loading branch information
mp911de committed Nov 7, 2020
1 parent 9bf8491 commit a48f117
Show file tree
Hide file tree
Showing 14 changed files with 410 additions and 302 deletions.
53 changes: 31 additions & 22 deletions src/main/java/io/lettuce/core/AbstractRedisAsyncCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,17 @@
import io.lettuce.core.internal.LettuceAssert;
import io.lettuce.core.models.stream.PendingMessage;
import io.lettuce.core.models.stream.PendingMessages;
import io.lettuce.core.output.*;
import io.lettuce.core.protocol.*;
import io.lettuce.core.output.CommandOutput;
import io.lettuce.core.output.KeyStreamingChannel;
import io.lettuce.core.output.KeyValueStreamingChannel;
import io.lettuce.core.output.ScoredValueStreamingChannel;
import io.lettuce.core.output.ValueStreamingChannel;
import io.lettuce.core.protocol.AsyncCommand;
import io.lettuce.core.protocol.Command;
import io.lettuce.core.protocol.CommandArgs;
import io.lettuce.core.protocol.CommandType;
import io.lettuce.core.protocol.ProtocolKeyword;
import io.lettuce.core.protocol.RedisCommand;

/**
* An asynchronous and thread-safe API for a Redis connection.
Expand Down Expand Up @@ -1794,23 +1803,23 @@ public RedisFuture<Double> zincrby(K key, double amount, V member) {
}

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

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

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

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

@Override
Expand All @@ -1819,8 +1828,8 @@ public RedisFuture<Long> zinterstore(K destination, K... keys) {
}

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

@Override
Expand Down Expand Up @@ -2276,23 +2285,23 @@ public RedisFuture<Double> zscore(K key, V member) {
}

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

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

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

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

@Override
Expand All @@ -2301,8 +2310,8 @@ public RedisFuture<Long> zunionstore(K destination, K... keys) {
}

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

private byte[] encodeScript(String script) {
Expand Down
53 changes: 31 additions & 22 deletions src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,17 @@
import io.lettuce.core.internal.LettuceAssert;
import io.lettuce.core.models.stream.PendingMessage;
import io.lettuce.core.models.stream.PendingMessages;
import io.lettuce.core.output.*;
import io.lettuce.core.protocol.*;
import io.lettuce.core.output.CommandOutput;
import io.lettuce.core.output.KeyStreamingChannel;
import io.lettuce.core.output.KeyValueStreamingChannel;
import io.lettuce.core.output.ScoredValueStreamingChannel;
import io.lettuce.core.output.ValueStreamingChannel;
import io.lettuce.core.protocol.Command;
import io.lettuce.core.protocol.CommandArgs;
import io.lettuce.core.protocol.CommandType;
import io.lettuce.core.protocol.ProtocolKeyword;
import io.lettuce.core.protocol.RedisCommand;
import io.lettuce.core.protocol.TracedCommand;
import io.lettuce.core.resource.ClientResources;
import io.lettuce.core.tracing.TraceContext;
import io.lettuce.core.tracing.TraceContextProvider;
Expand Down Expand Up @@ -1867,23 +1876,23 @@ public Mono<Double> zincrby(K key, double amount, V member) {
}

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

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

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

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

@Override
Expand All @@ -1892,8 +1901,8 @@ public Mono<Long> zinterstore(K destination, K... keys) {
}

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

@Override
Expand Down Expand Up @@ -2341,23 +2350,23 @@ public Mono<Double> zscore(K key, V member) {
}

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

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

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

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

@Override
Expand All @@ -2366,8 +2375,8 @@ public Mono<Long> zunionstore(K destination, K... keys) {
}

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

private byte[] encodeScript(String script) {
Expand Down
47 changes: 28 additions & 19 deletions src/main/java/io/lettuce/core/RedisCommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
*/
package io.lettuce.core;

import static io.lettuce.core.internal.LettuceStrings.string;
import static io.lettuce.core.internal.LettuceStrings.*;
import static io.lettuce.core.protocol.CommandKeyword.*;
import static io.lettuce.core.protocol.CommandType.*;

import java.nio.ByteBuffer;
import java.util.*;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

import io.lettuce.core.Range.Boundary;
import io.lettuce.core.XReadArgs.StreamOffset;
Expand All @@ -30,7 +34,11 @@
import io.lettuce.core.models.stream.PendingMessage;
import io.lettuce.core.models.stream.PendingMessages;
import io.lettuce.core.output.*;
import io.lettuce.core.protocol.*;
import io.lettuce.core.protocol.BaseRedisCommandBuilder;
import io.lettuce.core.protocol.Command;
import io.lettuce.core.protocol.CommandArgs;
import io.lettuce.core.protocol.CommandType;
import io.lettuce.core.protocol.RedisCommand;

/**
* @param <K>
Expand All @@ -39,6 +47,7 @@
* @author Zhang Jessey
* @author Tugdual Grall
* @author dengliming
* @author Mikhael Sokolov
*/
@SuppressWarnings({ "unchecked", "varargs" })
class RedisCommandBuilder<K, V> extends BaseRedisCommandBuilder<K, V> {
Expand Down Expand Up @@ -2609,32 +2618,32 @@ 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) {
Command<K, V, List<V>> zinter(K... keys) {
notEmpty(keys);

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

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

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

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

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

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

CommandArgs<K, V> args = new CommandArgs<>(codec);
args.add(numkey).addKeys(keys).add(WITHSCORES);
args.add(keys.length).addKeys(keys).add(WITHSCORES);
aggregateArgs.build(args);
return createCommand(ZINTER, new ScoredValueListOutput<>(codec), args);
}
Expand Down Expand Up @@ -3260,32 +3269,32 @@ 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) {
Command<K, V, List<V>> zunion(K... keys) {
notEmpty(keys);

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

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

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

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

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

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

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

0 comments on commit a48f117

Please sign in to comment.