DATAREDIS-729 - Polishing.
Reorder methods so lexCount(…) comes after count(…). Tweak Javadoc wording. Simplify tests. Original pull request: #569.
This commit is contained in:
@@ -1659,15 +1659,6 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
return convertAndReturn(delegate.zUnionStore(destKey, sets), identityConverter);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zLexCount(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range)
|
||||
*/
|
||||
@Override
|
||||
public Long zLexCount(byte[] key, Range range) {
|
||||
return delegate.zLexCount(key, range);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#zLexCount(java.lang.String, org.springframework.data.redis.connection.RedisZSetCommands.Range)
|
||||
@@ -2727,6 +2718,15 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
|
||||
return zCount(serialize(key), min, max);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zLexCount(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range)
|
||||
*/
|
||||
@Override
|
||||
public Long zLexCount(byte[] key, Range range) {
|
||||
return delegate.zLexCount(key, range);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.StringRedisConnection#zIncrBy(java.lang.String, double, java.lang.String)
|
||||
|
||||
@@ -898,6 +898,13 @@ public interface DefaultedRedisConnection extends RedisConnection {
|
||||
return zSetCommands().zCount(key, min, max);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Long zLexCount(byte[] key, Range range) {
|
||||
return zSetCommands().zLexCount(key, range);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
@@ -1094,13 +1101,6 @@ public interface DefaultedRedisConnection extends RedisConnection {
|
||||
return zSetCommands().zRangeByScore(key, min, max, offset, count);
|
||||
}
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
|
||||
@Override
|
||||
@Deprecated
|
||||
default Long zLexCount(byte[] key, Range range) {
|
||||
return zSetCommands().zLexCount(key, range);
|
||||
}
|
||||
|
||||
// HASH COMMANDS
|
||||
|
||||
/** @deprecated in favor of {@link RedisConnection#hashCommands()}}. */
|
||||
|
||||
@@ -1121,6 +1121,82 @@ public interface ReactiveZSetCommands {
|
||||
*/
|
||||
Flux<NumericResponse<ZCountCommand, Long>> zCount(Publisher<ZCountCommand> commands);
|
||||
|
||||
/**
|
||||
* {@code ZLEXCOUNT} command parameters.
|
||||
*
|
||||
* @author Andrey Shlykov
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
class ZLexCountCommand extends KeyCommand {
|
||||
|
||||
private final Range<String> range;
|
||||
|
||||
private ZLexCountCommand(@Nullable ByteBuffer key, Range<String> range) {
|
||||
super(key);
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link ZLexCountCommand} given a {@link Range} of {@link String} to retrieve elements count.
|
||||
*
|
||||
* @param range must not be {@literal null}.
|
||||
* @return a new {@link ZLexCountCommand} for {@link Range}.
|
||||
*/
|
||||
public static ZLexCountCommand stringsWithin(Range<String> range) {
|
||||
|
||||
Assert.notNull(range, "Range must not be null!");
|
||||
|
||||
return new ZLexCountCommand(null, range);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the {@literal key}. Constructs a new command instance with all previously configured properties.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @return a new {@link ZLexCountCommand} with {@literal key} applied.
|
||||
*/
|
||||
public ZLexCountCommand forKey(ByteBuffer key) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
|
||||
return new ZLexCountCommand(key, range);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Range<String> getRange() {
|
||||
return range;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with value between {@code Range#min} and {@code Range#max} applying
|
||||
* lexicographical ordering.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param range must not be {@literal null}.
|
||||
* @return
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
default Mono<Long> zLexCount(ByteBuffer key, Range<String> range) {
|
||||
return zLexCount(Mono.just(ZLexCountCommand.stringsWithin(range).forKey(key))).next()
|
||||
.map(NumericResponse::getOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with value between {@code Range#min} and {@code Range#max} applying
|
||||
* lexicographical ordering.
|
||||
*
|
||||
* @param commands must not be {@literal null}.
|
||||
* @return
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
Flux<NumericResponse<ZLexCountCommand, Long>> zLexCount(Publisher<ZLexCountCommand> commands);
|
||||
|
||||
/**
|
||||
* Get the size of sorted set with {@literal key}.
|
||||
*
|
||||
@@ -1937,78 +2013,4 @@ public interface ReactiveZSetCommands {
|
||||
*/
|
||||
Flux<CommandResponse<ZRangeByLexCommand, Flux<ByteBuffer>>> zRangeByLex(Publisher<ZRangeByLexCommand> commands);
|
||||
|
||||
/**
|
||||
* {@code ZLEXCOUNT} command parameters.
|
||||
*
|
||||
* @author Andrey Shlykov
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
class ZLexCountCommand extends KeyCommand {
|
||||
|
||||
private final Range<String> range;
|
||||
|
||||
private ZLexCountCommand(@Nullable ByteBuffer key, Range<String> range) {
|
||||
super(key);
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link ZLexCountCommand} given a {@link Range} of {@link String} to retrieve elements
|
||||
* count.
|
||||
*
|
||||
* @param range must not be {@literal null}.
|
||||
* @return a new {@link ZLexCountCommand} for {@link Range}.
|
||||
*/
|
||||
public static ZLexCountCommand stringsWithin(Range<String> range) {
|
||||
|
||||
Assert.notNull(range, "Range must not be null!");
|
||||
|
||||
return new ZLexCountCommand(null, range);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the {@literal key}. Constructs a new command instance with all previously configured properties.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @return a new {@link ZLexCountCommand} with {@literal key} applied.
|
||||
*/
|
||||
public ZLexCountCommand forKey(ByteBuffer key) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
|
||||
return new ZLexCountCommand(key, range);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Range<String> getRange() {
|
||||
return range;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with value within {@link Range}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param range must not be {@literal null}.
|
||||
* @return
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
default Mono<Long> zLexCount(ByteBuffer key, Range<String> range) {
|
||||
return zLexCount(Mono.just(ZLexCountCommand.stringsWithin(range).forKey(key))).next()
|
||||
.map(NumericResponse::getOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with value within {@link Range}.
|
||||
*
|
||||
* @param commands must not be {@literal null}.
|
||||
* @return
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
Flux<NumericResponse<ZLexCountCommand, Long>> zLexCount(Publisher<ZLexCountCommand> commands);
|
||||
|
||||
}
|
||||
|
||||
@@ -768,6 +768,19 @@ public interface RedisZSetCommands {
|
||||
@Nullable
|
||||
Long zCount(byte[] key, Range range);
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with value between {@code Range#min} and {@code Range#max} applying
|
||||
* lexicographical ordering.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param range must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long zLexCount(byte[] key, Range range);
|
||||
|
||||
/**
|
||||
* Get the size of sorted set with {@code key}.
|
||||
*
|
||||
@@ -1059,16 +1072,4 @@ public interface RedisZSetCommands {
|
||||
@Nullable
|
||||
Set<byte[]> zRevRangeByLex(byte[] key, Range range, Limit limit);
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with value between {@code Range#min} and {@code Range#max}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param range must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long zLexCount(byte[] key, Range range);
|
||||
|
||||
}
|
||||
|
||||
@@ -1329,6 +1329,20 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
*/
|
||||
Long zCount(String key, double min, double max);
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with value between {@code Range#min} and {@code Range#max} applying
|
||||
* lexicographical ordering.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param range must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
* @see RedisZSetCommands#zLexCount(byte[], Range)
|
||||
*/
|
||||
@Nullable
|
||||
Long zLexCount(String key, Range range);
|
||||
|
||||
/**
|
||||
* Get the size of sorted set with {@code key}.
|
||||
*
|
||||
@@ -1541,19 +1555,6 @@ public interface StringRedisConnection extends RedisConnection {
|
||||
*/
|
||||
Set<String> zRevRangeByLex(String key, Range range, Limit limit);
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with value between {@code Range#min} and {@code Range#max}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param range must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
* @see RedisZSetCommands#zLexCount(byte[], Range)
|
||||
*/
|
||||
@Nullable
|
||||
Long zLexCount(String key, Range range);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Methods dealing with Redis Hashes
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -257,6 +257,26 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zLexCount(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range)
|
||||
*/
|
||||
@Override
|
||||
public Long zLexCount(byte[] key, Range range) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range must not be null!");
|
||||
|
||||
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getMin(), JedisConverters.MINUS_BYTES);
|
||||
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getMax(), JedisConverters.PLUS_BYTES);
|
||||
|
||||
try {
|
||||
return connection.getCluster().zlexcount(key, min, max);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zRemRangeByScore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range)
|
||||
@@ -795,26 +815,6 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zLexCount(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range)
|
||||
*/
|
||||
@Override
|
||||
public Long zLexCount(byte[] key, Range range) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range must not be null!");
|
||||
|
||||
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getMin(), JedisConverters.MINUS_BYTES);
|
||||
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getMax(), JedisConverters.PLUS_BYTES);
|
||||
|
||||
try {
|
||||
return connection.getCluster().zlexcount(key, min, max);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private DataAccessException convertJedisAccessException(Exception ex) {
|
||||
return connection.convertJedisAccessException(ex);
|
||||
}
|
||||
|
||||
@@ -491,6 +491,34 @@ class JedisZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zLexCount(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range)
|
||||
*/
|
||||
@Override
|
||||
public Long zLexCount(byte[] key, Range range) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range must not be null!");
|
||||
|
||||
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getMin(), JedisConverters.MINUS_BYTES);
|
||||
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getMax(), JedisConverters.PLUS_BYTES);
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(connection.newJedisResult(connection.getRequiredPipeline().zlexcount(key, min, max)));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(connection.newJedisResult(connection.getRequiredTransaction().zlexcount(key, min, max)));
|
||||
return null;
|
||||
}
|
||||
return connection.getJedis().zlexcount(key, min, max);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zCard(byte[])
|
||||
@@ -942,34 +970,6 @@ class JedisZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zLexCount(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range)
|
||||
*/
|
||||
@Override
|
||||
public Long zLexCount(byte[] key, Range range) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range must not be null!");
|
||||
|
||||
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getMin(), JedisConverters.MINUS_BYTES);
|
||||
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getMax(), JedisConverters.PLUS_BYTES);
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(connection.newJedisResult(connection.getRequiredPipeline().zlexcount(key, min, max)));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(connection.newJedisResult(connection.getRequiredTransaction().zlexcount(key, min, max)));
|
||||
return null;
|
||||
}
|
||||
return connection.getJedis().zlexcount(key, min, max);
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPipelined() {
|
||||
return connection.isPipelined();
|
||||
}
|
||||
|
||||
@@ -327,6 +327,24 @@ class LettuceReactiveZSetCommands implements ReactiveZSetCommands {
|
||||
}));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.ReactiveZSetCommands#zLexCount(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Flux<NumericResponse<ZLexCountCommand, Long>> zLexCount(Publisher<ZLexCountCommand> commands) {
|
||||
|
||||
return connection.execute(cmd -> Flux.from(commands).concatMap(command -> {
|
||||
|
||||
Assert.notNull(command.getKey(), "Key must not be null!");
|
||||
Assert.notNull(command.getRange(), "Range must not be null!");
|
||||
|
||||
Mono<Long> result = cmd.zlexcount(command.getKey(), RangeConverter.toRange(command.getRange()));
|
||||
|
||||
return result.map(value -> new NumericResponse<>(command, value));
|
||||
}));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.ReactiveZSetCommands#zCard(org.reactivestreams.Publisher)
|
||||
@@ -485,24 +503,6 @@ class LettuceReactiveZSetCommands implements ReactiveZSetCommands {
|
||||
}));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.ReactiveZSetCommands#zLexCount(org.reactivestreams.Publisher)
|
||||
*/
|
||||
@Override
|
||||
public Flux<NumericResponse<ZLexCountCommand, Long>> zLexCount(Publisher<ZLexCountCommand> commands) {
|
||||
|
||||
return connection.execute(cmd -> Flux.from(commands).concatMap(command -> {
|
||||
|
||||
Assert.notNull(command.getKey(), "Key must not be null!");
|
||||
Assert.notNull(command.getRange(), "Range must not be null!");
|
||||
|
||||
Mono<Long> result = cmd.zlexcount(command.getKey(), RangeConverter.toRange(command.getRange()));
|
||||
|
||||
return result.map(value -> new NumericResponse<>(command, value));
|
||||
}));
|
||||
}
|
||||
|
||||
private static ZStoreArgs zStoreArgs(@Nullable Aggregate aggregate, @Nullable List<Double> weights) {
|
||||
|
||||
ZStoreArgs args = new ZStoreArgs();
|
||||
|
||||
@@ -471,6 +471,31 @@ class LettuceZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zLexCount(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range)
|
||||
*/
|
||||
@Override
|
||||
public Long zLexCount(byte[] key, Range range) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range must not be null!");
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(connection.newLettuceResult(getAsyncConnection().zlexcount(key, LettuceConverters.toRange(range))));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(connection.newLettuceResult(getAsyncConnection().zlexcount(key, LettuceConverters.toRange(range))));
|
||||
return null;
|
||||
}
|
||||
return getConnection().zlexcount(key, LettuceConverters.toRange(range, true));
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zCard(byte[])
|
||||
@@ -927,31 +952,6 @@ class LettuceZSetCommands implements RedisZSetCommands {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.connection.RedisZSetCommands#zLexCount(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Range)
|
||||
*/
|
||||
@Override
|
||||
public Long zLexCount(byte[] key, Range range) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range must not be null!");
|
||||
|
||||
try {
|
||||
if (isPipelined()) {
|
||||
pipeline(connection.newLettuceResult(getAsyncConnection().zlexcount(key, LettuceConverters.toRange(range))));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(connection.newLettuceResult(getAsyncConnection().zlexcount(key, LettuceConverters.toRange(range))));
|
||||
return null;
|
||||
}
|
||||
return getConnection().zlexcount(key, LettuceConverters.toRange(range, true));
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPipelined() {
|
||||
return connection.isPipelined();
|
||||
}
|
||||
|
||||
@@ -199,6 +199,18 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
|
||||
@Nullable
|
||||
Long count(double min, double max);
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with value between {@code Range#min} and {@code Range#max} applying
|
||||
* lexicographical ordering.
|
||||
*
|
||||
* @param range must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long lexCount(Range range);
|
||||
|
||||
/**
|
||||
* Returns the number of elements of the sorted set stored with given the bound key.
|
||||
*
|
||||
@@ -415,17 +427,6 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
|
||||
@Nullable
|
||||
Set<V> reverseRangeByLex(Range range, Limit limit);
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with value between {@code Range#min} and {@code Range#max}.
|
||||
*
|
||||
* @param range must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long lexCount(Range range);
|
||||
|
||||
/**
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
|
||||
@@ -276,6 +276,15 @@ class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> impl
|
||||
return ops.count(getKey(), min, max);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#lexCount(org.springframework.data.redis.connection.RedisZSetCommands.Range)
|
||||
*/
|
||||
@Override
|
||||
public Long lexCount(Range range) {
|
||||
return ops.lexCount(getKey(), range);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#size()
|
||||
@@ -330,15 +339,6 @@ class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> impl
|
||||
return ops.unionAndStore(getKey(), otherKeys, destKey, aggregate, weights);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#lexCount(org.springframework.data.redis.connection.RedisZSetCommands.Range)
|
||||
*/
|
||||
@Override
|
||||
public Long lexCount(Range range) {
|
||||
return ops.lexCount(getKey(), range);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundKeyOperations#getType()
|
||||
|
||||
@@ -332,6 +332,19 @@ class DefaultReactiveZSetOperations<K, V> implements ReactiveZSetOperations<K, V
|
||||
return createMono(connection -> connection.zCount(rawKey(key), range));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ReactiveZSetOperations#lexCount(java.lang.Object, org.springframework.data.domain.Range)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Long> lexCount(K key, Range<String> range) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range must not be null!");
|
||||
|
||||
return createMono(connection -> connection.zLexCount(rawKey(key), range));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ReactiveZSetOperations#size(java.lang.Object)
|
||||
@@ -549,20 +562,6 @@ class DefaultReactiveZSetOperations<K, V> implements ReactiveZSetOperations<K, V
|
||||
return template.createMono(connection -> connection.keyCommands().del(rawKey(key))).map(l -> l != 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ReactiveZSetOperations#lexCount(java.lang.Object, org.springframework.data.domain.Range)
|
||||
*/
|
||||
@Override
|
||||
public Mono<Long> lexCount(K key, Range<String> range) {
|
||||
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(range, "Range must not be null!");
|
||||
|
||||
|
||||
return createMono(connection -> connection.zLexCount(rawKey(key), range));
|
||||
}
|
||||
|
||||
private <T> Mono<T> createMono(Function<ReactiveZSetCommands, Publisher<T>> function) {
|
||||
|
||||
Assert.notNull(function, "Function must not be null!");
|
||||
|
||||
@@ -387,6 +387,17 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
|
||||
return execute(connection -> connection.zCount(rawKey, min, max), true);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#lexCount(java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Range)
|
||||
*/
|
||||
@Override
|
||||
public Long lexCount(K key, Range range) {
|
||||
|
||||
byte[] rawKey = rawKey(key);
|
||||
return execute(connection -> connection.zLexCount(rawKey, range), true);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#size(java.lang.Object)
|
||||
@@ -468,10 +479,4 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
|
||||
return execute(connection -> connection.zRangeByScore(rawKey, min, max, offset, count), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long lexCount(K key, Range range) {
|
||||
|
||||
byte[] rawKey = rawKey(key);
|
||||
return execute(connection -> connection.zLexCount(rawKey, range), true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,6 +269,18 @@ public interface ReactiveZSetOperations<K, V> {
|
||||
*/
|
||||
Mono<Long> count(K key, Range<Double> range);
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with a value between {@link Range#getLowerBound()} and
|
||||
* {@link Range#getUpperBound()} applying lexicographical ordering.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param range must not be {@literal null}
|
||||
* @return
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/ZLEXCOUNT">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
Mono<Long> lexCount(K key, Range<String> range);
|
||||
|
||||
/**
|
||||
* Returns the number of elements of the sorted set stored with given {@code key}.
|
||||
*
|
||||
@@ -463,14 +475,4 @@ public interface ReactiveZSetOperations<K, V> {
|
||||
*/
|
||||
Mono<Boolean> delete(K key);
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with a value between
|
||||
* {@link Range#getLowerBound()} and {@link Range#getUpperBound()}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param range must not be {@literal null}
|
||||
* @return
|
||||
* @see <a href="https://redis.io/commands/ZLEXCOUNT">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
Mono<Long> lexCount(K key, Range<String> range);
|
||||
}
|
||||
|
||||
@@ -286,6 +286,19 @@ public interface ZSetOperations<K, V> {
|
||||
@Nullable
|
||||
Long count(K key, double min, double max);
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with value between {@code Range#min} and {@code Range#max} applying
|
||||
* lexicographical ordering.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param range must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long lexCount(K key, Range range);
|
||||
|
||||
/**
|
||||
* Returns the number of elements of the sorted set stored with given {@code key}.
|
||||
*
|
||||
@@ -525,18 +538,6 @@ public interface ZSetOperations<K, V> {
|
||||
@Nullable
|
||||
Set<V> reverseRangeByLex(K key, Range range, Limit limit);
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with value between {@code Range#min} and {@code Range#max}.
|
||||
*
|
||||
* @param key must not be {@literal null}.
|
||||
* @param range must not be {@literal null}.
|
||||
* @return {@literal null} when used in pipeline / transaction.
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
@Nullable
|
||||
Long lexCount(K key, Range range);
|
||||
|
||||
/**
|
||||
* @return never {@literal null}.
|
||||
*/
|
||||
|
||||
@@ -135,6 +135,17 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
|
||||
*/
|
||||
boolean add(E e);
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with value between {@code Range#min} and {@code Range#max} applying
|
||||
* lexicographical ordering.
|
||||
*
|
||||
* @param range must not be {@literal null}.
|
||||
* @return
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
Long lexCount(Range range);
|
||||
|
||||
/**
|
||||
* Returns the score of the given element. Returns null if the element is not contained by the set.
|
||||
*
|
||||
@@ -168,16 +179,6 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
|
||||
*/
|
||||
Double getDefaultScore();
|
||||
|
||||
/**
|
||||
* Count number of elements within sorted set with value between {@code Range#min} and {@code Range#max}.
|
||||
*
|
||||
* @param range must not be {@literal null}.
|
||||
* @return
|
||||
* @since 2.4
|
||||
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
|
||||
*/
|
||||
Long lexCount(Range range);
|
||||
|
||||
/**
|
||||
* Returns the first (lowest) element currently in this sorted set.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user