Use o.s.d.d.Range instead of inner Range class for ZSet operations.

Closes: #2288
Original Pull Request: #2292
This commit is contained in:
Mark Paluch
2022-03-29 15:09:35 +02:00
committed by Christoph Strobl
parent 6ca3800d8c
commit 4ab1789953
22 changed files with 450 additions and 324 deletions

View File

@@ -25,6 +25,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.domain.Range;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResults;
@@ -990,7 +991,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
}
@Override
public Long zCount(byte[] key, Range range) {
public Long zCount(byte[] key, org.springframework.data.domain.Range<Number> range) {
return convertAndReturn(delegate.zCount(key, range), Converters.identityConverter());
}
@@ -1100,17 +1101,18 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
}
@Override
public Set<byte[]> zRangeByScore(byte[] key, Range range) {
public Set<byte[]> zRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range) {
return convertAndReturn(delegate.zRangeByScore(key, range), Converters.identityConverter());
}
@Override
public Set<byte[]> zRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
return convertAndReturn(delegate.zRangeByScore(key, range, limit), Converters.identityConverter());
}
@Override
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range) {
public Set<Tuple> zRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range) {
return convertAndReturn(delegate.zRangeByScoreWithScores(key, range), Converters.identityConverter());
}
@@ -1126,7 +1128,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
}
@Override
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range,
public Set<Tuple> zRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
return convertAndReturn(delegate.zRangeByScoreWithScores(key, range, limit), Converters.identityConverter());
}
@@ -1147,7 +1149,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
}
@Override
public Set<byte[]> zRevRangeByScore(byte[] key, Range range) {
public Set<byte[]> zRevRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range) {
return convertAndReturn(delegate.zRevRangeByScore(key, range), Converters.identityConverter());
}
@@ -1157,7 +1159,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
}
@Override
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRevRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
return convertAndReturn(delegate.zRevRangeByScore(key, range, limit), Converters.identityConverter());
}
@@ -1168,12 +1171,12 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
}
@Override
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range) {
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range) {
return convertAndReturn(delegate.zRevRangeByScoreWithScores(key, range), Converters.identityConverter());
}
@Override
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range,
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
return convertAndReturn(delegate.zRevRangeByScoreWithScores(key, range, limit), Converters.identityConverter());
}
@@ -1199,7 +1202,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
}
@Override
public Long zRemRangeByLex(byte[] key, Range range) {
public Long zRemRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range) {
return convertAndReturn(delegate.zRemRangeByLex(key, range), Converters.identityConverter());
}
@@ -1209,7 +1212,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
}
@Override
public Long zRemRangeByScore(byte[] key, Range range) {
public Long zRemRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range) {
return convertAndReturn(delegate.zRemRangeByScore(key, range), Converters.identityConverter());
}
@@ -1291,8 +1294,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
}
@Override
public Long zLexCount(String key, Range range) {
return delegate.zLexCount(serialize(key), range);
public Long zLexCount(String key, org.springframework.data.domain.Range<String> range) {
return delegate.zLexCount(serialize(key), serialize(range));
}
@Override
@@ -1370,6 +1373,26 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
return serializer.serialize(data);
}
private org.springframework.data.domain.Range<byte[]> serialize(org.springframework.data.domain.Range<String> range) {
if (!range.getLowerBound().isBounded() && !range.getUpperBound().isBounded()) {
return org.springframework.data.domain.Range.unbounded();
}
org.springframework.data.domain.Range.Bound<byte[]> lower = rawBound(range.getLowerBound());
org.springframework.data.domain.Range.Bound<byte[]> upper = rawBound(range.getUpperBound());
return org.springframework.data.domain.Range.of(lower, upper);
}
private org.springframework.data.domain.Range.Bound<byte[]> rawBound(
org.springframework.data.domain.Range.Bound<String> source) {
return source.getValue().map(this::serialize)
.map(it -> source.isInclusive() ? org.springframework.data.domain.Range.Bound.inclusive(it)
: org.springframework.data.domain.Range.Bound.exclusive(it))
.orElseGet(org.springframework.data.domain.Range.Bound::unbounded);
}
@SuppressWarnings("unchecked")
private GeoReference<byte[]> serialize(GeoReference<String> data) {
return data instanceof GeoReference.GeoMemberReference
@@ -1987,7 +2010,7 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
}
@Override
public Long zLexCount(byte[] key, Range range) {
public Long zLexCount(byte[] key, org.springframework.data.domain.Range<byte[]> range) {
return delegate.zLexCount(key, range);
}
@@ -2165,8 +2188,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
}
@Override
public Long zRemRangeByLex(String key, Range range) {
return zRemRangeByLex(serialize(key), range);
public Long zRemRangeByLex(String key, org.springframework.data.domain.Range<String> range) {
return zRemRangeByLex(serialize(key), serialize(range));
}
@Override
@@ -2655,38 +2678,42 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
}
@Override
public Set<byte[]> zRangeByLex(byte[] key, Range range) {
public Set<byte[]> zRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range) {
return convertAndReturn(delegate.zRangeByLex(key, range), Converters.identityConverter());
}
@Override
public Set<byte[]> zRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit) {
return convertAndReturn(delegate.zRangeByLex(key, range, limit), Converters.identityConverter());
}
@Override
public Set<String> zRangeByLex(String key) {
return zRangeByLex(key, Range.unbounded());
return zRangeByLex(key, org.springframework.data.domain.Range.unbounded());
}
@Override
public Set<String> zRangeByLex(String key, Range range) {
public Set<String> zRangeByLex(String key, org.springframework.data.domain.Range<String> range) {
return zRangeByLex(key, range, org.springframework.data.redis.connection.Limit.unlimited());
}
@Override
public Set<String> zRangeByLex(String key, Range range, org.springframework.data.redis.connection.Limit limit) {
return convertAndReturn(delegate.zRangeByLex(serialize(key), range, limit), byteSetToStringSet);
public Set<String> zRangeByLex(String key, org.springframework.data.domain.Range<String> range,
org.springframework.data.redis.connection.Limit limit) {
return convertAndReturn(delegate.zRangeByLex(serialize(key), serialize(range), limit), byteSetToStringSet);
}
@Override
public Set<byte[]> zRevRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRevRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit) {
return convertAndReturn(delegate.zRevRangeByLex(key, range, limit), Converters.identityConverter());
}
@Override
public Set<String> zRevRangeByLex(String key, Range range, org.springframework.data.redis.connection.Limit limit) {
return convertAndReturn(delegate.zRevRangeByLex(serialize(key), range, limit), byteSetToStringSet);
public Set<String> zRevRangeByLex(String key, org.springframework.data.domain.Range<String> range,
org.springframework.data.redis.connection.Limit limit) {
return convertAndReturn(delegate.zRevRangeByLex(serialize(key), serialize(range), limit), byteSetToStringSet);
}
@Override

View File

@@ -23,6 +23,7 @@ import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.springframework.data.domain.Range;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResults;
@@ -967,7 +968,7 @@ public interface DefaultedRedisConnection extends RedisCommands, RedisCommandsPr
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Long zLexCount(byte[] key, Range range) {
default Long zLexCount(byte[] key, org.springframework.data.domain.Range<byte[]> range) {
return zSetCommands().zLexCount(key, range);
}
@@ -1016,7 +1017,7 @@ public interface DefaultedRedisConnection extends RedisCommands, RedisCommandsPr
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Long zCount(byte[] key, Range range) {
default Long zCount(byte[] key, org.springframework.data.domain.Range<Number> range) {
return zSetCommands().zCount(key, range);
}
@@ -1142,28 +1143,31 @@ public interface DefaultedRedisConnection extends RedisCommands, RedisCommandsPr
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Set<byte[]> zRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
default Set<byte[]> zRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit) {
return zSetCommands().zRangeByLex(key, range, limit);
}
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Set<byte[]> zRevRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
default Set<byte[]> zRevRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit) {
return zSetCommands().zRevRangeByLex(key, range, limit);
}
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Set<byte[]> zRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
default Set<byte[]> zRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
return zSetCommands().zRangeByScore(key, range, limit);
}
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range,
default Set<Tuple> zRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
return zSetCommands().zRangeByScoreWithScores(key, range, limit);
}
@@ -1178,14 +1182,15 @@ public interface DefaultedRedisConnection extends RedisCommands, RedisCommandsPr
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Set<byte[]> zRevRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
default Set<byte[]> zRevRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
return zSetCommands().zRevRangeByScore(key, range, limit);
}
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range,
default Set<Tuple> zRevRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
return zSetCommands().zRevRangeByScoreWithScores(key, range, limit);
}
@@ -1214,14 +1219,14 @@ public interface DefaultedRedisConnection extends RedisCommands, RedisCommandsPr
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Long zRemRangeByLex(byte[] key, Range range) {
default Long zRemRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range) {
return zSetCommands().zRemRangeByLex(key, range);
}
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Long zRemRangeByScore(byte[] key, Range range) {
default Long zRemRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range) {
return zSetCommands().zRemRangeByScore(key, range);
}

View File

@@ -52,7 +52,9 @@ public interface RedisZSetCommands {
*
* @author Christoph Strobl
* @since 1.6
* @deprecated since 3.0, use {@link org.springframework.data.domain.Range} or {@link #toRange()} instead.
*/
@Deprecated
class Range {
@Nullable Boundary min;
@@ -172,6 +174,30 @@ public interface RedisZSetCommands {
}
}
/**
* Create a {@link org.springframework.data.domain.Range} object from this range.
*
* @return a {@link org.springframework.data.domain.Range} object using bounds from this range.
* @since 3.0
*/
public <T> org.springframework.data.domain.Range<T> toRange() {
org.springframework.data.domain.Range.Bound<Object> lower = toBound(min);
org.springframework.data.domain.Range.Bound<Object> upper = toBound(max);
return (org.springframework.data.domain.Range<T>) org.springframework.data.domain.Range.from(lower).to(upper);
}
private org.springframework.data.domain.Range.Bound<Object> toBound(@Nullable Boundary boundary) {
if (boundary == null || boundary.value == null) {
return org.springframework.data.domain.Range.Bound.unbounded();
}
return boundary.isIncluding() ? org.springframework.data.domain.Range.Bound.inclusive(boundary.getValue())
: org.springframework.data.domain.Range.Bound.exclusive(boundary.getValue());
}
}
/**
@@ -532,7 +558,7 @@ public interface RedisZSetCommands {
*/
@Nullable
default Set<byte[]> zRangeByScore(byte[] key, double min, double max) {
return zRangeByScore(key, new Range().gte(min).lte(max));
return zRangeByScore(key, org.springframework.data.domain.Range.closed(min, max));
}
/**
@@ -546,7 +572,7 @@ public interface RedisZSetCommands {
* @see <a href="https://redis.io/commands/zrangebyscore">Redis Documentation: ZRANGEBYSCORE</a>
*/
@Nullable
default Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range) {
default Set<Tuple> zRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range) {
return zRangeByScoreWithScores(key, range, Limit.unlimited());
}
@@ -562,7 +588,7 @@ public interface RedisZSetCommands {
*/
@Nullable
default Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max) {
return zRangeByScoreWithScores(key, new Range().gte(min).lte(max));
return zRangeByScoreWithScores(key, org.springframework.data.domain.Range.closed(min, max));
}
/**
@@ -580,7 +606,7 @@ public interface RedisZSetCommands {
*/
@Nullable
default Set<byte[]> zRangeByScore(byte[] key, double min, double max, long offset, long count) {
return zRangeByScore(key, new Range().gte(min).lte(max),
return zRangeByScore(key, org.springframework.data.domain.Range.closed(min, max),
new org.springframework.data.redis.connection.Limit().offset(Long.valueOf(offset).intValue())
.count(Long.valueOf(count).intValue()));
}
@@ -600,7 +626,7 @@ public interface RedisZSetCommands {
*/
@Nullable
default Set<Tuple> zRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
return zRangeByScoreWithScores(key, new Range().gte(min).lte(max),
return zRangeByScoreWithScores(key, org.springframework.data.domain.Range.closed(min, max),
new org.springframework.data.redis.connection.Limit().offset(Long.valueOf(offset).intValue())
.count(Long.valueOf(count).intValue()));
}
@@ -618,7 +644,8 @@ public interface RedisZSetCommands {
* @see <a href="https://redis.io/commands/zrangebyscore">Redis Documentation: ZRANGEBYSCORE</a>
*/
@Nullable
Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit);
Set<Tuple> zRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit);
/**
* Get elements in range from {@code start} to {@code end} from sorted set ordered from high to low.
@@ -658,7 +685,7 @@ public interface RedisZSetCommands {
*/
@Nullable
default Set<byte[]> zRevRangeByScore(byte[] key, double min, double max) {
return zRevRangeByScore(key, new Range().gte(min).lte(max));
return zRevRangeByScore(key, org.springframework.data.domain.Range.closed(min, max));
}
/**
@@ -673,7 +700,7 @@ public interface RedisZSetCommands {
* @see <a href="https://redis.io/commands/zrevrangebyscore">Redis Documentation: ZREVRANGEBYSCORE</a>
*/
@Nullable
default Set<byte[]> zRevRangeByScore(byte[] key, Range range) {
default Set<byte[]> zRevRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range) {
return zRevRangeByScore(key, range, Limit.unlimited());
}
@@ -690,7 +717,7 @@ public interface RedisZSetCommands {
*/
@Nullable
default Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max) {
return zRevRangeByScoreWithScores(key, new Range().gte(min).lte(max), Limit.unlimited());
return zRevRangeByScoreWithScores(key, org.springframework.data.domain.Range.closed(min, max), Limit.unlimited());
}
/**
@@ -708,7 +735,7 @@ public interface RedisZSetCommands {
@Nullable
default Set<byte[]> zRevRangeByScore(byte[] key, double min, double max, long offset, long count) {
return zRevRangeByScore(key, new Range().gte(min).lte(max),
return zRevRangeByScore(key, org.springframework.data.domain.Range.closed(min, max),
new Limit().offset(Long.valueOf(offset).intValue()).count(Long.valueOf(count).intValue()));
}
@@ -724,7 +751,8 @@ public interface RedisZSetCommands {
* @see <a href="https://redis.io/commands/zrevrangebyscore">Redis Documentation: ZREVRANGEBYSCORE</a>
*/
@Nullable
Set<byte[]> zRevRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit);
Set<byte[]> zRevRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit);
/**
* Get set of {@link Tuple} in range from {@code start} to {@code end} where score is between {@code min} and
@@ -741,7 +769,7 @@ public interface RedisZSetCommands {
@Nullable
default Set<Tuple> zRevRangeByScoreWithScores(byte[] key, double min, double max, long offset, long count) {
return zRevRangeByScoreWithScores(key, new Range().gte(min).lte(max),
return zRevRangeByScoreWithScores(key, org.springframework.data.domain.Range.closed(min, max),
new org.springframework.data.redis.connection.Limit().offset(Long.valueOf(offset).intValue())
.count(Long.valueOf(count).intValue()));
}
@@ -757,7 +785,7 @@ public interface RedisZSetCommands {
* @see <a href="https://redis.io/commands/zrevrangebyscore">Redis Documentation: ZREVRANGEBYSCORE</a>
*/
@Nullable
default Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range) {
default Set<Tuple> zRevRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range) {
return zRevRangeByScoreWithScores(key, range, Limit.unlimited());
}
@@ -773,7 +801,8 @@ public interface RedisZSetCommands {
* @see <a href="https://redis.io/commands/zrevrangebyscore">Redis Documentation: ZREVRANGEBYSCORE</a>
*/
@Nullable
Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit);
Set<Tuple> zRevRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit);
/**
* Count number of elements within sorted set with scores between {@code min} and {@code max}.
@@ -786,7 +815,7 @@ public interface RedisZSetCommands {
*/
@Nullable
default Long zCount(byte[] key, double min, double max) {
return zCount(key, new Range().gte(min).lte(max));
return zCount(key, org.springframework.data.domain.Range.closed(min, max));
}
/**
@@ -799,7 +828,7 @@ public interface RedisZSetCommands {
* @see <a href="https://redis.io/commands/zcount">Redis Documentation: ZCOUNT</a>
*/
@Nullable
Long zCount(byte[] key, Range range);
Long zCount(byte[] key, org.springframework.data.domain.Range<Number> range);
/**
* Count number of elements within sorted set with value between {@code Range#min} and {@code Range#max} applying
@@ -812,7 +841,7 @@ public interface RedisZSetCommands {
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
*/
@Nullable
Long zLexCount(byte[] key, Range range);
Long zLexCount(byte[] key, org.springframework.data.domain.Range<byte[]> range);
/**
* Remove and return the value with its score having the lowest score from sorted set at {@code key}.
@@ -942,7 +971,7 @@ public interface RedisZSetCommands {
* @since 2.5
* @see <a href="https://redis.io/commands/zremrangebylex">Redis Documentation: ZREMRANGEBYLEX</a>
*/
Long zRemRangeByLex(byte[] key, Range range);
Long zRemRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range);
/**
* Remove elements with scores between {@code min} and {@code max} from sorted set with {@code key}.
@@ -955,7 +984,7 @@ public interface RedisZSetCommands {
*/
@Nullable
default Long zRemRangeByScore(byte[] key, double min, double max) {
return zRemRangeByScore(key, new Range().gte(min).lte(max));
return zRemRangeByScore(key, org.springframework.data.domain.Range.closed(min, max));
}
/**
@@ -968,7 +997,7 @@ public interface RedisZSetCommands {
* @see <a href="https://redis.io/commands/zremrangebyscore">Redis Documentation: ZREMRANGEBYSCORE</a>
*/
@Nullable
Long zRemRangeByScore(byte[] key, Range range);
Long zRemRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range);
/**
* Diff sorted {@code sets}.
@@ -1203,10 +1232,12 @@ public interface RedisZSetCommands {
* @return {@literal null} when used in pipeline / transaction.
* @since 1.5
* @see <a href="https://redis.io/commands/zrangebyscore">Redis Documentation: ZRANGEBYSCORE</a>
* @deprecated since 3.0, use {@link #zRangeByScore(byte[], org.springframework.data.domain.Range)} instead.
*/
@Nullable
@Deprecated
default Set<byte[]> zRangeByScore(byte[] key, String min, String max) {
return zRangeByScore(key, new Range().gte(min).lte(max));
return zRangeByScore(key, new Range().gte(min).lte(max).toRange());
}
/**
@@ -1219,7 +1250,7 @@ public interface RedisZSetCommands {
* @see <a href="https://redis.io/commands/zrangebyscore">Redis Documentation: ZRANGEBYSCORE</a>
*/
@Nullable
default Set<byte[]> zRangeByScore(byte[] key, Range range) {
default Set<byte[]> zRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range) {
return zRangeByScore(key, range, Limit.unlimited());
}
@@ -1251,7 +1282,8 @@ public interface RedisZSetCommands {
* @see <a href="https://redis.io/commands/zrangebyscore">Redis Documentation: ZRANGEBYSCORE</a>
*/
@Nullable
Set<byte[]> zRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit);
Set<byte[]> zRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit);
/**
* Get all the elements in the sorted set at {@literal key} in lexicographical ordering.
@@ -1263,7 +1295,7 @@ public interface RedisZSetCommands {
*/
@Nullable
default Set<byte[]> zRangeByLex(byte[] key) {
return zRangeByLex(key, Range.unbounded());
return zRangeByLex(key, org.springframework.data.domain.Range.unbounded());
}
/**
@@ -1276,7 +1308,7 @@ public interface RedisZSetCommands {
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
*/
@Nullable
default Set<byte[]> zRangeByLex(byte[] key, Range range) {
default Set<byte[]> zRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range) {
return zRangeByLex(key, range, Limit.unlimited());
}
@@ -1292,7 +1324,8 @@ public interface RedisZSetCommands {
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
*/
@Nullable
Set<byte[]> zRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit);
Set<byte[]> zRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit);
/**
* Get all the elements in the sorted set at {@literal key} in reversed lexicographical ordering.
@@ -1304,7 +1337,7 @@ public interface RedisZSetCommands {
*/
@Nullable
default Set<byte[]> zRevRangeByLex(byte[] key) {
return zRevRangeByLex(key, Range.unbounded());
return zRevRangeByLex(key, org.springframework.data.domain.Range.unbounded());
}
/**
@@ -1317,7 +1350,7 @@ public interface RedisZSetCommands {
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
*/
@Nullable
default Set<byte[]> zRevRangeByLex(byte[] key, Range range) {
default Set<byte[]> zRevRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range) {
return zRevRangeByLex(key, range, org.springframework.data.redis.connection.Limit.unlimited());
}
@@ -1333,6 +1366,7 @@ public interface RedisZSetCommands {
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
*/
@Nullable
Set<byte[]> zRevRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit);
Set<byte[]> zRevRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit);
}

View File

@@ -1538,7 +1538,7 @@ public interface StringRedisConnection extends RedisConnection {
* @see RedisZSetCommands#zLexCount(byte[], Range)
*/
@Nullable
Long zLexCount(String key, Range range);
Long zLexCount(String key, org.springframework.data.domain.Range<String> range);
/**
* Remove and return the value with its score having the lowest score from sorted set at {@code key}.
@@ -1669,7 +1669,7 @@ public interface StringRedisConnection extends RedisConnection {
* @since 2.5
* @see <a href="https://redis.io/commands/zremrangebylex">Redis Documentation: ZREMRANGEBYLEX</a>
*/
Long zRemRangeByLex(String key, Range range);
Long zRemRangeByLex(String key, org.springframework.data.domain.Range<String> range);
/**
* Remove elements with scores between {@code min} and {@code max} from sorted set with {@code key}.
@@ -1927,7 +1927,7 @@ public interface StringRedisConnection extends RedisConnection {
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
* @see RedisZSetCommands#zRangeByLex(byte[], Range)
*/
Set<String> zRangeByLex(String key, Range range);
Set<String> zRangeByLex(String key, org.springframework.data.domain.Range<String> range);
/**
* Get all the elements in {@link Range} from the sorted set at {@literal key} in lexicographical ordering. Result is
@@ -1941,7 +1941,8 @@ public interface StringRedisConnection extends RedisConnection {
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
* @see RedisZSetCommands#zRangeByLex(byte[], Range, Limit)
*/
Set<String> zRangeByLex(String key, Range range, org.springframework.data.redis.connection.Limit limit);
Set<String> zRangeByLex(String key, org.springframework.data.domain.Range<String> range,
org.springframework.data.redis.connection.Limit limit);
/**
* Get all the elements in the sorted set at {@literal key} in reversed lexicographical ordering.
@@ -1953,7 +1954,7 @@ public interface StringRedisConnection extends RedisConnection {
* @see RedisZSetCommands#zRevRangeByLex(byte[])
*/
default Set<String> zRevRangeByLex(String key) {
return zRevRangeByLex(key, Range.unbounded());
return zRevRangeByLex(key, org.springframework.data.domain.Range.unbounded());
}
/**
@@ -1966,7 +1967,7 @@ public interface StringRedisConnection extends RedisConnection {
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
* @see RedisZSetCommands#zRevRangeByLex(byte[], Range)
*/
default Set<String> zRevRangeByLex(String key, Range range) {
default Set<String> zRevRangeByLex(String key, org.springframework.data.domain.Range<String> range) {
return zRevRangeByLex(key, range, org.springframework.data.redis.connection.Limit.unlimited());
}
@@ -1982,7 +1983,8 @@ public interface StringRedisConnection extends RedisConnection {
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
* @see RedisZSetCommands#zRevRangeByLex(byte[], Range, Limit)
*/
Set<String> zRevRangeByLex(String key, Range range, org.springframework.data.redis.connection.Limit limit);
Set<String> zRevRangeByLex(String key, org.springframework.data.domain.Range<String> range,
org.springframework.data.redis.connection.Limit limit);
// -------------------------------------------------------------------------
// Methods dealing with Redis Hashes

View File

@@ -205,14 +205,16 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
}
@Override
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range,
public Set<Tuple> zRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range cannot be null for ZRANGEBYSCOREWITHSCORES.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getLowerBound(),
JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getUpperBound(),
JedisConverters.POSITIVE_INFINITY_BYTES);
try {
if (limit.isUnlimited()) {
@@ -226,13 +228,16 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
}
@Override
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRevRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range cannot be null for ZREVRANGEBYSCORE.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getLowerBound(),
JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getUpperBound(),
JedisConverters.POSITIVE_INFINITY_BYTES);
try {
if (limit.isUnlimited()) {
@@ -246,14 +251,16 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
}
@Override
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range,
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range cannot be null for ZREVRANGEBYSCOREWITHSCORES.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getLowerBound(),
JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getUpperBound(),
JedisConverters.POSITIVE_INFINITY_BYTES);
try {
if (limit.isUnlimited()) {
@@ -267,13 +274,15 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
}
@Override
public Long zCount(byte[] key, Range range) {
public Long zCount(byte[] key, org.springframework.data.domain.Range<Number> range) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range cannot be null for ZCOUNT.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getLowerBound(),
JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getUpperBound(),
JedisConverters.POSITIVE_INFINITY_BYTES);
try {
return connection.getCluster().zcount(key, min, max);
@@ -283,13 +292,13 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
}
@Override
public Long zLexCount(byte[] key, Range range) {
public Long zLexCount(byte[] key, org.springframework.data.domain.Range<byte[]> 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);
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getLowerBound(), JedisConverters.MINUS_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getUpperBound(), JedisConverters.PLUS_BYTES);
try {
return connection.getCluster().zlexcount(key, min, max);
@@ -381,13 +390,15 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
}
@Override
public Long zRemRangeByScore(byte[] key, Range range) {
public Long zRemRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range cannot be null for ZREMRANGEBYSCORE.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getLowerBound(),
JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getUpperBound(),
JedisConverters.POSITIVE_INFINITY_BYTES);
try {
return connection.getCluster().zremrangeByScore(key, min, max);
@@ -398,13 +409,16 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
}
@Override
public Set<byte[]> zRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range cannot be null for ZRANGEBYSCORE.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getLowerBound(),
JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getUpperBound(),
JedisConverters.POSITIVE_INFINITY_BYTES);
try {
if (limit.isUnlimited()) {
@@ -418,14 +432,15 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
}
@Override
public Set<byte[]> zRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range must not be null for ZRANGEBYLEX!");
Assert.notNull(limit, "Limit must not be null!");
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getMin(), JedisConverters.MINUS_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getMax(), JedisConverters.PLUS_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getLowerBound(), JedisConverters.MINUS_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getUpperBound(), JedisConverters.PLUS_BYTES);
try {
if (limit.isUnlimited()) {
@@ -439,13 +454,13 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
}
@Override
public Long zRemRangeByLex(byte[] key, Range range) {
public Long zRemRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range must not be null for ZREMRANGEBYLEX!");
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getMin(), JedisConverters.MINUS_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getMax(), JedisConverters.PLUS_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getLowerBound(), JedisConverters.MINUS_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getUpperBound(), JedisConverters.PLUS_BYTES);
try {
return connection.getCluster().zremrangeByLex(key, min, max);
@@ -455,14 +470,15 @@ class JedisClusterZSetCommands implements RedisZSetCommands {
}
@Override
public Set<byte[]> zRevRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRevRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range must not be null for ZREVRANGEBYLEX!");
Assert.notNull(limit, "Limit must not be null!");
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getMin(), JedisConverters.MINUS_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getMax(), JedisConverters.PLUS_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getLowerBound(), JedisConverters.MINUS_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getUpperBound(), JedisConverters.PLUS_BYTES);
try {
if (limit.isUnlimited()) {

View File

@@ -63,7 +63,6 @@ import org.springframework.data.redis.connection.RedisServer;
import org.springframework.data.redis.connection.RedisServerCommands;
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
import org.springframework.data.redis.connection.RedisZSetCommands.Range.Boundary;
import org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs;
import org.springframework.data.redis.connection.SortParameters;
import org.springframework.data.redis.connection.SortParameters.Order;
@@ -304,7 +303,7 @@ abstract class JedisConverters extends Converters {
}
/**
* Converts a given {@link Boundary} to its binary representation suitable for {@literal ZRANGEBY*} commands, despite
* Converts a given {@link Bound} to its binary representation suitable for {@literal ZRANGEBY*} commands, despite
* {@literal ZRANGEBYLEX}.
*
* @param boundary
@@ -312,9 +311,10 @@ abstract class JedisConverters extends Converters {
* @return
* @since 1.6
*/
public static byte[] boundaryToBytesForZRange(@Nullable Boundary boundary, byte[] defaultValue) {
public static byte[] boundaryToBytesForZRange(@Nullable org.springframework.data.domain.Range.Bound<?> boundary,
byte[] defaultValue) {
if (boundary == null || boundary.getValue() == null) {
if (boundary == null || !boundary.isBounded()) {
return defaultValue;
}
@@ -322,15 +322,16 @@ abstract class JedisConverters extends Converters {
}
/**
* Converts a given {@link Boundary} to its binary representation suitable for ZRANGEBYLEX command.
* Converts a given {@link Bound} to its binary representation suitable for ZRANGEBYLEX command.
*
* @param boundary
* @return
* @since 1.6
*/
public static byte[] boundaryToBytesForZRangeByLex(@Nullable Boundary boundary, byte[] defaultValue) {
public static byte[] boundaryToBytesForZRangeByLex(
@Nullable org.springframework.data.domain.Range.Bound<byte[]> boundary, byte[] defaultValue) {
if (boundary == null || boundary.getValue() == null) {
if (boundary == null || !boundary.isBounded()) {
return defaultValue;
}
@@ -471,20 +472,22 @@ abstract class JedisConverters extends Converters {
}
}
private static byte[] boundaryToBytes(Boundary boundary, byte[] inclPrefix, byte[] exclPrefix) {
private static byte[] boundaryToBytes(org.springframework.data.domain.Range.Bound<?> boundary, byte[] inclPrefix,
byte[] exclPrefix) {
byte[] prefix = boundary.isIncluding() ? inclPrefix : exclPrefix;
byte[] prefix = boundary.isInclusive() ? inclPrefix : exclPrefix;
byte[] value = null;
if (boundary.getValue() instanceof byte[]) {
value = (byte[]) boundary.getValue();
} else if (boundary.getValue() instanceof Double) {
value = toBytes((Double) boundary.getValue());
} else if (boundary.getValue() instanceof Long) {
value = toBytes((Long) boundary.getValue());
} else if (boundary.getValue() instanceof Integer) {
value = toBytes((Integer) boundary.getValue());
} else if (boundary.getValue() instanceof String) {
value = toBytes((String) boundary.getValue());
Object theValue = boundary.getValue().get();
if (theValue instanceof byte[]) {
value = (byte[]) theValue;
} else if (theValue instanceof Double) {
value = toBytes((Double) theValue);
} else if (theValue instanceof Long) {
value = toBytes((Long) theValue);
} else if (theValue instanceof Integer) {
value = toBytes((Integer) theValue);
} else if (theValue instanceof String) {
value = toBytes((String) theValue);
} else {
throw new IllegalArgumentException(String.format("Cannot convert %s to binary format", boundary.getValue()));
}

View File

@@ -171,15 +171,17 @@ class JedisZSetCommands implements RedisZSetCommands {
}
@Override
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range,
public Set<Tuple> zRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZRANGEBYSCOREWITHSCORES must not be null!");
Assert.notNull(limit, "Limit must not be null! Use Limit.unlimited() instead.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getLowerBound(),
JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getUpperBound(),
JedisConverters.POSITIVE_INFINITY_BYTES);
if (!limit.isUnlimited()) {
return connection.invoke().fromMany(Jedis::zrangeByScoreWithScores,
@@ -211,14 +213,17 @@ class JedisZSetCommands implements RedisZSetCommands {
}
@Override
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRevRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZREVRANGEBYSCORE must not be null!");
Assert.notNull(limit, "Limit must not be null! Use Limit.unlimited() instead.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getLowerBound(),
JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getUpperBound(),
JedisConverters.POSITIVE_INFINITY_BYTES);
if (!limit.isUnlimited()) {
return connection.invoke().fromMany(Jedis::zrevrangeByScore, PipelineBinaryCommands::zrevrangeByScore, key, max,
@@ -230,15 +235,17 @@ class JedisZSetCommands implements RedisZSetCommands {
}
@Override
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range,
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZREVRANGEBYSCOREWITHSCORES must not be null!");
Assert.notNull(limit, "Limit must not be null! Use Limit.unlimited() instead.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getLowerBound(),
JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getUpperBound(),
JedisConverters.POSITIVE_INFINITY_BYTES);
if (!limit.isUnlimited()) {
return connection.invoke().fromMany(Jedis::zrevrangeByScoreWithScores,
@@ -260,25 +267,27 @@ class JedisZSetCommands implements RedisZSetCommands {
}
@Override
public Long zCount(byte[] key, Range range) {
public Long zCount(byte[] key, org.springframework.data.domain.Range<Number> range) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range must not be null!");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getLowerBound(),
JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getUpperBound(),
JedisConverters.POSITIVE_INFINITY_BYTES);
return connection.invoke().just(Jedis::zcount, PipelineBinaryCommands::zcount, key, min, max);
}
@Override
public Long zLexCount(byte[] key, Range range) {
public Long zLexCount(byte[] key, org.springframework.data.domain.Range<byte[]> 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);
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getLowerBound(), JedisConverters.MINUS_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getUpperBound(), JedisConverters.PLUS_BYTES);
return connection.invoke().just(Jedis::zlexcount, PipelineBinaryCommands::zlexcount, key, min, max);
}
@@ -380,25 +389,27 @@ class JedisZSetCommands implements RedisZSetCommands {
}
@Override
public Long zRemRangeByLex(byte[] key, Range range) {
public Long zRemRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range must not be null for ZREMRANGEBYLEX!");
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getMin(), JedisConverters.MINUS_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getMax(), JedisConverters.PLUS_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getLowerBound(), JedisConverters.MINUS_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getUpperBound(), JedisConverters.PLUS_BYTES);
return connection.invoke().just(Jedis::zremrangeByLex, PipelineBinaryCommands::zremrangeByLex, key, min, max);
}
@Override
public Long zRemRangeByScore(byte[] key, Range range) {
public Long zRemRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZREMRANGEBYSCORE must not be null!");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getLowerBound(),
JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getUpperBound(),
JedisConverters.POSITIVE_INFINITY_BYTES);
return connection.invoke().just(Jedis::zremrangeByScore, PipelineBinaryCommands::zremrangeByScore, key, min, max);
}
@@ -604,14 +615,17 @@ class JedisZSetCommands implements RedisZSetCommands {
}
@Override
public Set<byte[]> zRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZRANGEBYSCORE must not be null!");
Assert.notNull(limit, "Limit must not be null! Use Limit.unlimited() instead.");
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getMin(), JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getMax(), JedisConverters.POSITIVE_INFINITY_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRange(range.getLowerBound(),
JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRange(range.getUpperBound(),
JedisConverters.POSITIVE_INFINITY_BYTES);
if (!limit.isUnlimited()) {
return connection.invoke().fromMany(Jedis::zrangeByScore, PipelineBinaryCommands::zrangeByScore, key, min, max,
@@ -623,14 +637,15 @@ class JedisZSetCommands implements RedisZSetCommands {
}
@Override
public Set<byte[]> zRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZRANGEBYLEX must not be null!");
Assert.notNull(limit, "Limit must not be null! Use Limit.unlimited() instead.");
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getMin(), JedisConverters.MINUS_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getMax(), JedisConverters.PLUS_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getLowerBound(), JedisConverters.MINUS_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getUpperBound(), JedisConverters.PLUS_BYTES);
if (!limit.isUnlimited()) {
return connection.invoke().fromMany(Jedis::zrangeByLex, PipelineBinaryCommands::zrangeByLex, key, min, max,
@@ -641,14 +656,15 @@ class JedisZSetCommands implements RedisZSetCommands {
}
@Override
public Set<byte[]> zRevRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRevRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZREVRANGEBYLEX must not be null!");
Assert.notNull(limit, "Limit must not be null! Use Limit.unlimited() instead.");
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getMin(), JedisConverters.MINUS_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getMax(), JedisConverters.PLUS_BYTES);
byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getLowerBound(), JedisConverters.MINUS_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getUpperBound(), JedisConverters.PLUS_BYTES);
if (!limit.isUnlimited()) {
return connection.invoke().from(Jedis::zrevrangeByLex, PipelineBinaryCommands::zrevrangeByLex, key, max, min,

View File

@@ -289,7 +289,7 @@ public abstract class LettuceConverters extends Converters {
* @return
* @since 2.0
*/
public static <T> Range<T> toRange(org.springframework.data.redis.connection.RedisZSetCommands.Range range) {
public static <T> Range<T> toRange(org.springframework.data.domain.Range<T> range) {
return Range.from(lowerBoundaryOf(range, false), upperBoundaryOf(range, false));
}
@@ -301,7 +301,7 @@ public abstract class LettuceConverters extends Converters {
* @return
* @since 2.2
*/
public static <T> Range<T> toRange(org.springframework.data.redis.connection.RedisZSetCommands.Range range,
public static <T> Range<T> toRange(org.springframework.data.domain.Range<T> range,
boolean convertNumberToBytes) {
return Range.from(lowerBoundaryOf(range, convertNumberToBytes), upperBoundaryOf(range, convertNumberToBytes));
}
@@ -314,34 +314,35 @@ public abstract class LettuceConverters extends Converters {
* @return
* @since 2.0
*/
public static <T> Range<T> toRevRange(org.springframework.data.redis.connection.RedisZSetCommands.Range range) {
public static <T> Range<T> toRevRange(org.springframework.data.domain.Range<T> range) {
return Range.from(upperBoundaryOf(range, false), lowerBoundaryOf(range, false));
}
@SuppressWarnings("unchecked")
private static <T> Range.Boundary<T> lowerBoundaryOf(
org.springframework.data.redis.connection.RedisZSetCommands.Range range, boolean convertNumberToBytes) {
org.springframework.data.domain.Range<T> range, boolean convertNumberToBytes) {
return (Range.Boundary<T>) rangeToBoundaryArgumentConverter(false, convertNumberToBytes).convert(range);
}
@SuppressWarnings("unchecked")
private static <T> Range.Boundary<T> upperBoundaryOf(
org.springframework.data.redis.connection.RedisZSetCommands.Range range, boolean convertNumberToBytes) {
org.springframework.data.domain.Range<T> range, boolean convertNumberToBytes) {
return (Range.Boundary<T>) rangeToBoundaryArgumentConverter(true, convertNumberToBytes).convert(range);
}
private static Converter<org.springframework.data.redis.connection.RedisZSetCommands.Range, Range.Boundary<?>> rangeToBoundaryArgumentConverter(
private static Converter<org.springframework.data.domain.Range<?>, Range.Boundary<?>> rangeToBoundaryArgumentConverter(
boolean upper, boolean convertNumberToBytes) {
return (source) -> {
Boundary sourceBoundary = upper ? source.getMax() : source.getMin();
if (sourceBoundary == null || sourceBoundary.getValue() == null) {
org.springframework.data.domain.Range.Bound<?> sourceBoundary = upper ? source.getUpperBound()
: source.getLowerBound();
if (sourceBoundary == null || !sourceBoundary.isBounded()) {
return Range.Boundary.unbounded();
}
boolean inclusive = sourceBoundary.isIncluding();
Object value = sourceBoundary.getValue();
boolean inclusive = sourceBoundary.isInclusive();
Object value = sourceBoundary.getValue().get();
if (value instanceof Number) {

View File

@@ -164,7 +164,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
@Override
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range,
public Set<Tuple> zRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
@@ -202,7 +202,8 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
@Override
public Set<byte[]> zRevRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRevRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZREVRANGEBYSCORE must not be null!");
@@ -221,7 +222,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
@Override
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range,
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
@@ -241,7 +242,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
@Override
public Long zCount(byte[] key, Range range) {
public Long zCount(byte[] key, org.springframework.data.domain.Range<Number> range) {
Assert.notNull(key, "Key must not be null!");
@@ -250,7 +251,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
@Override
public Long zLexCount(byte[] key, Range range) {
public Long zLexCount(byte[] key, org.springframework.data.domain.Range<byte[]> range) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range must not be null!");
@@ -370,7 +371,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
@Override
public Long zRemRangeByLex(byte[] key, Range range) {
public Long zRemRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range must not be null for ZREMRANGEBYLEX!");
@@ -380,7 +381,7 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
@Override
public Long zRemRangeByScore(byte[] key, Range range) {
public Long zRemRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZREMRANGEBYSCORE must not be null!");
@@ -589,7 +590,8 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
@Override
public Set<byte[]> zRangeByScore(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZRANGEBYSCORE must not be null!");
@@ -605,7 +607,8 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
@Override
public Set<byte[]> zRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZRANGEBYLEX must not be null!");
@@ -622,7 +625,8 @@ class LettuceZSetCommands implements RedisZSetCommands {
}
@Override
public Set<byte[]> zRevRangeByLex(byte[] key, Range range, org.springframework.data.redis.connection.Limit limit) {
public Set<byte[]> zRevRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(key, "Key must not be null!");
Assert.notNull(range, "Range for ZREVRANGEBYLEX must not be null!");

View File

@@ -22,9 +22,9 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.connection.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.connection.zset.Tuple;
import org.springframework.data.redis.connection.zset.Weights;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
@@ -303,7 +303,7 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
*/
@Nullable
Long lexCount(Range range);
Long lexCount(Range<String> range);
/**
* Remove and return the value with its score having the lowest score from sorted set at the bound key.
@@ -472,7 +472,7 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
* @see <a href="https://redis.io/commands/zremrangebylex">Redis Documentation: ZREMRANGEBYLEX</a>
*/
@Nullable
Long removeRangeByLex(Range range);
Long removeRangeByLex(Range<String> range);
/**
* Remove elements with scores between {@code min} and {@code max} from sorted set with the bound key.
@@ -805,8 +805,8 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
Cursor<TypedTuple<V>> scan(ScanOptions options);
/**
* Get all elements with lexicographical ordering with a value between {@link Range#getMin()} and
* {@link Range#getMax()}.
* Get all elements with lexicographical ordering with a value between {@link Range#getLowerBound()} and
* {@link Range#getUpperBound()}.
*
* @param range must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
@@ -814,14 +814,14 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
*/
@Nullable
default Set<V> rangeByLex(Range range) {
default Set<V> rangeByLex(Range<String> range) {
return rangeByLex(range, Limit.unlimited());
}
/**
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
* {@link Limit#getOffset()} with lexicographical ordering having a value between {@link Range#getMin()} and
* {@link Range#getMax()}.
* {@link Limit#getOffset()} with lexicographical ordering having a value between {@link Range#getLowerBound()} and
* {@link Range#getUpperBound()}.
*
* @param range must not be {@literal null}.
* @param limit can be {@literal null}.
@@ -830,11 +830,11 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
*/
@Nullable
Set<V> rangeByLex(Range range, Limit limit);
Set<V> rangeByLex(Range<String> range, Limit limit);
/**
* Get all elements with reverse lexicographical ordering with a value between {@link Range#getMin()} and
* {@link Range#getMax()}.
* Get all elements with reverse lexicographical ordering with a value between {@link Range#getLowerBound()} and
* {@link Range#getUpperBound()}.
*
* @param range must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
@@ -842,14 +842,14 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
*/
@Nullable
default Set<V> reverseRangeByLex(Range range) {
default Set<V> reverseRangeByLex(Range<String> range) {
return reverseRangeByLex(range, Limit.unlimited());
}
/**
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
* {@link Limit#getOffset()} with reverse lexicographical ordering having a value between {@link Range#getMin()} and
* {@link Range#getMax()}.
* {@link Limit#getOffset()} with reverse lexicographical ordering having a value between
* {@link Range#getLowerBound()} and {@link Range#getUpperBound()}.
*
* @param range must not be {@literal null}.
* @param limit can be {@literal null}.
@@ -858,7 +858,7 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
*/
@Nullable
Set<V> reverseRangeByLex(Range range, Limit limit);
Set<V> reverseRangeByLex(Range<String> range, Limit limit);
/**
* @return never {@literal null}.

View File

@@ -22,9 +22,9 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.connection.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs;
import org.springframework.data.redis.connection.zset.Tuple;
import org.springframework.data.redis.connection.zset.Weights;
@@ -209,19 +209,19 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
}
@Override
public Set<V> rangeByLex(K key, Range range, Limit limit) {
public Set<V> rangeByLex(K key, Range<String> range, Limit limit) {
byte[] rawKey = rawKey(key);
Set<byte[]> rawValues = execute(connection -> connection.zRangeByLex(rawKey, range, limit));
Set<byte[]> rawValues = execute(connection -> connection.zRangeByLex(rawKey, serialize(range), limit));
return deserializeValues(rawValues);
}
@Override
public Set<V> reverseRangeByLex(K key, Range range, Limit limit) {
public Set<V> reverseRangeByLex(K key, Range<String> range, Limit limit) {
byte[] rawKey = rawKey(key);
Set<byte[]> rawValues = execute(connection -> connection.zRevRangeByLex(rawKey, range, limit));
Set<byte[]> rawValues = execute(connection -> connection.zRevRangeByLex(rawKey, serialize(range), limit));
return deserializeValues(rawValues);
}
@@ -340,10 +340,10 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
}
@Override
public Long removeRangeByLex(K key, Range range) {
public Long removeRangeByLex(K key, Range<String> range) {
byte[] rawKey = rawKey(key);
return execute(connection -> connection.zRemRangeByLex(rawKey, range));
return execute(connection -> connection.zRemRangeByLex(rawKey, serialize(range)));
}
@Override
@@ -377,10 +377,10 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
}
@Override
public Long lexCount(K key, Range range) {
public Long lexCount(K key, Range<String> range) {
byte[] rawKey = rawKey(key);
return execute(connection -> connection.zLexCount(rawKey, range));
return execute(connection -> connection.zLexCount(rawKey, serialize(range)));
}
@Nullable
@@ -397,7 +397,7 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
byte[] rawKey = rawKey(key);
Set<Tuple> result = execute(connection -> connection.zPopMin(rawKey, count));
return deserializeTupleValues(new LinkedHashSet<> (result));
return deserializeTupleValues(new LinkedHashSet<>(result));
}
@Nullable
@@ -538,8 +538,7 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
byte[][] rawKeys = rawKeys(key, otherKeys);
Set<Tuple> result = execute(connection -> connection.zUnionWithScores(aggregate, weights, rawKeys));
return deserializeTupleValues(
result);
return deserializeTupleValues(result);
}
@Override
@@ -587,4 +586,22 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
return execute(connection -> connection.zRangeByScore(rawKey, min, max, offset, count));
}
private Range<byte[]> serialize(Range<String> range) {
if (!range.getLowerBound().isBounded() && !range.getUpperBound().isBounded()) {
return Range.unbounded();
}
Range.Bound<byte[]> lower = rawBound(range.getLowerBound());
Range.Bound<byte[]> upper = rawBound(range.getUpperBound());
return Range.of(lower, upper);
}
private Range.Bound<byte[]> rawBound(Range.Bound<String> source) {
return source.getValue().map(this::rawString)
.map(it -> source.isInclusive() ? Range.Bound.inclusive(it) : Range.Bound.exclusive(it))
.orElseGet(Range.Bound::unbounded);
}
}

View File

@@ -22,9 +22,9 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.connection.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.connection.zset.Tuple;
import org.springframework.data.redis.connection.zset.Weights;
import org.springframework.lang.Nullable;
@@ -402,8 +402,8 @@ public interface ZSetOperations<K, V> {
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.
* Count number of elements within sorted set with 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}.
@@ -412,7 +412,7 @@ public interface ZSetOperations<K, V> {
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
*/
@Nullable
Long lexCount(K key, Range range);
Long lexCount(K key, Range<String> range);
/**
* Remove and return the value with its score having the lowest score from sorted set at {@code key}.
@@ -595,7 +595,7 @@ public interface ZSetOperations<K, V> {
* @see <a href="https://redis.io/commands/zremrangebylex">Redis Documentation: ZREMRANGEBYLEX</a>
*/
@Nullable
Long removeRangeByLex(K key, Range range);
Long removeRangeByLex(K key, org.springframework.data.domain.Range<String> range);
/**
* Remove elements with scores between {@code min} and {@code max} from sorted set with {@code key}.
@@ -970,7 +970,7 @@ public interface ZSetOperations<K, V> {
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
*/
@Nullable
default Set<V> rangeByLex(K key, Range range) {
default Set<V> rangeByLex(K key, org.springframework.data.domain.Range<String> range) {
return rangeByLex(key, range, Limit.unlimited());
}
@@ -987,7 +987,7 @@ public interface ZSetOperations<K, V> {
* @see <a href="https://redis.io/commands/zrangebylex">Redis Documentation: ZRANGEBYLEX</a>
*/
@Nullable
Set<V> rangeByLex(K key, Range range, Limit limit);
Set<V> rangeByLex(K key, org.springframework.data.domain.Range<String> range, Limit limit);
/**
* Get all elements with reverse lexicographical ordering from {@literal ZSET} at {@code key} with a value between
@@ -1000,7 +1000,7 @@ public interface ZSetOperations<K, V> {
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
*/
@Nullable
default Set<V> reverseRangeByLex(K key, Range range) {
default Set<V> reverseRangeByLex(K key, org.springframework.data.domain.Range<String> range) {
return reverseRangeByLex(key, range, Limit.unlimited());
}
@@ -1017,7 +1017,7 @@ public interface ZSetOperations<K, V> {
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
*/
@Nullable
Set<V> reverseRangeByLex(K key, Range range, Limit limit);
Set<V> reverseRangeByLex(K key, org.springframework.data.domain.Range<String> range, Limit limit);
/**
* @return never {@literal null}.

View File

@@ -21,9 +21,9 @@ import java.util.NoSuchElementException;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.core.BoundZSetOperations;
import org.springframework.data.redis.core.ConvertingCursor;
import org.springframework.data.redis.core.Cursor;
@@ -221,12 +221,12 @@ public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements R
}
@Override
public Set<E> rangeByLex(Range range, Limit limit) {
public Set<E> rangeByLex(Range<String> range, Limit limit) {
return boundZSetOps.rangeByLex(range, limit);
}
@Override
public Set<E> reverseRangeByLex(Range range, Limit limit) {
public Set<E> reverseRangeByLex(Range<String> range, Limit limit) {
return boundZSetOps.reverseRangeByLex(range, limit);
}
@@ -267,7 +267,7 @@ public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements R
}
@Override
public Set<E> removeByLex(Range range) {
public Set<E> removeByLex(Range<String> range) {
boundZSetOps.removeRangeByLex(range);
return this;
}
@@ -424,7 +424,7 @@ public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements R
}
@Override
public Long lexCount(Range range) {
public Long lexCount(Range<String> range) {
return boundZSetOps.lexCount(range);
}

View File

@@ -23,8 +23,8 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.concurrent.TimeUnit;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.connection.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.connection.zset.Tuple;
import org.springframework.data.redis.core.BoundZSetOperations;
import org.springframework.data.redis.core.RedisOperations;
@@ -263,22 +263,22 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
Set<E> reverseRange(long start, long end);
/**
* Get all elements with lexicographical ordering with a value between {@link Range#getMin()} and
* {@link Range#getMax()}.
* Get all elements with lexicographical ordering with a value between {@link Range#getLowerBound()} and
* {@link Range#getUpperBound()}.
*
* @param range must not be {@literal null}.
* @return
* @see BoundZSetOperations#rangeByLex(Range)
* @since 1.7
*/
default Set<E> rangeByLex(Range range) {
default Set<E> rangeByLex(Range<String> range) {
return rangeByLex(range, Limit.unlimited());
}
/**
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
* {@link Limit#getOffset()} with lexicographical ordering having a value between {@link Range#getMin()} and
* {@link Range#getMax()}.
* {@link Limit#getOffset()} with lexicographical ordering having a value between {@link Range#getLowerBound()} and
* {@link Range#getUpperBound()}.
*
* @param range must not be {@literal null}.
* @param limit can be {@literal null}.
@@ -286,25 +286,25 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
* @since 1.7
* @see BoundZSetOperations#rangeByLex(Range, Limit)
*/
Set<E> rangeByLex(Range range, Limit limit);
Set<E> rangeByLex(Range<String> range, Limit limit);
/**
* Get all elements with reverse lexicographical ordering with a value between {@link Range#getMin()} and
* {@link Range#getMax()}.
* Get all elements with reverse lexicographical ordering with a value between {@link Range#getLowerBound()} and
* {@link Range#getUpperBound()}.
*
* @param range must not be {@literal null}.
* @return
* @since 2.4
* @see BoundZSetOperations#reverseRangeByLex(Range)
*/
default Set<E> reverseRangeByLex(Range range) {
default Set<E> reverseRangeByLex(Range<String> range) {
return reverseRangeByLex(range, Limit.unlimited());
}
/**
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
* {@link Limit#getOffset()} with reverse lexicographical ordering having a value between {@link Range#getMin()} and
* {@link Range#getMax()}.
* {@link Limit#getOffset()} with reverse lexicographical ordering having a value between
* {@link Range#getLowerBound()} and {@link Range#getUpperBound()}.
*
* @param range must not be {@literal null}.
* @param limit can be {@literal null}.
@@ -312,7 +312,7 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
* @since 2.4
* @see BoundZSetOperations#reverseRangeByLex(Range, Limit)
*/
Set<E> reverseRangeByLex(Range range, Limit limit);
Set<E> reverseRangeByLex(Range<String> range, Limit limit);
/**
* Get elements where score is between {@code min} and {@code max} from sorted set.
@@ -386,7 +386,7 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
* @since 2.5
*/
// TODO: Switch to RedisZSet
Set<E> removeByLex(Range range);
Set<E> removeByLex(Range<String> range);
/**
* Remove elements with scores between {@code min} and {@code max} from sorted set with the bound key.
@@ -413,7 +413,8 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
boolean add(E e);
/**
* Adds an element to the set using the {@link #getDefaultScore() default score} if the element does not already exists.
* Adds an element to the set using the {@link #getDefaultScore() default score} if the element does not already
* exists.
*
* @param e element to add
* @return true if a new element was added, false otherwise (only the score has been updated)
@@ -442,7 +443,7 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
* @since 2.4
* @see <a href="https://redis.io/commands/zlexcount">Redis Documentation: ZLEXCOUNT</a>
*/
Long lexCount(Range range);
Long lexCount(Range<String> range);
/**
* Returns the score of the given element. Returns null if the element is not contained by the set.