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.

View File

@@ -44,6 +44,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Range;
import org.springframework.data.domain.Range.Bound;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
@@ -59,7 +60,6 @@ import org.springframework.data.redis.connection.RedisStreamCommands.XClaimOptio
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
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.SortParameters.Order;
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
@@ -1938,10 +1938,10 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myzset", 0, "g"));
actual.add(connection.zLexCount("myzset", Range.unbounded()));
actual.add(connection.zLexCount("myzset", Range.range().lt("c")));
actual.add(connection.zLexCount("myzset", Range.range().lte("c")));
actual.add(connection.zLexCount("myzset", Range.range().gte("aaa").lt("g")));
actual.add(connection.zLexCount("myzset", Range.range().gte("e")));
actual.add(connection.zLexCount("myzset", Range.leftUnbounded(Bound.exclusive("c"))));
actual.add(connection.zLexCount("myzset", Range.leftUnbounded(Bound.inclusive("c"))));
actual.add(connection.zLexCount("myzset", Range.rightOpen("aaa", "g")));
actual.add(connection.zLexCount("myzset", Range.rightUnbounded(Bound.inclusive("e"))));
List<Object> results = getResults();
@@ -2300,7 +2300,7 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myset", 0, "zip"));
actual.add(connection.zAdd("myset", 0, "ALPHA"));
actual.add(connection.zAdd("myset", 0, "alpha"));
actual.add(connection.zRemRangeByLex("myset", Range.range().gte("alpha").lte("omega")));
actual.add(connection.zRemRangeByLex("myset", Range.closed("alpha", "omega")));
actual.add(connection.zRange("myset", 0L, -1L));
verifyResults(Arrays.asList(true, true, true, true, true, true, true, true, true, true, 6L,
@@ -2815,14 +2815,15 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myzset", 0, "f"));
actual.add(connection.zAdd("myzset", 0, "g"));
actual.add(connection.zRangeByLex("myzset", Range.range().lte("c")));
actual.add(connection.zRangeByLex("myzset", Range.range().lt("c")));
actual.add(connection.zRangeByLex("myzset", Range.range().gte("aaa").lt("g")));
actual.add(connection.zRangeByLex("myzset", Range.range().gte("e")));
actual.add(connection.zRangeByLex("myzset", Range.leftUnbounded(Bound.inclusive("c"))));
actual.add(connection.zRangeByLex("myzset", Range.leftUnbounded(Bound.exclusive("c"))));
actual.add(connection.zRangeByLex("myzset", Range.rightOpen("aaa", "g")));
actual.add(connection.zRangeByLex("myzset", Range.rightUnbounded(Bound.inclusive("e"))));
actual.add(connection.zRangeByLex("myzset", Range.range().lte("c"), Limit.unlimited()));
actual.add(connection.zRangeByLex("myzset", Range.range().lte("c"), Limit.limit().count(1)));
actual.add(connection.zRangeByLex("myzset", Range.range().lte("c"), Limit.limit().count(1).offset(1)));
actual.add(connection.zRangeByLex("myzset", Range.leftUnbounded(Bound.inclusive("c")), Limit.unlimited()));
actual.add(connection.zRangeByLex("myzset", Range.leftUnbounded(Bound.inclusive("c")), Limit.limit().count(1)));
actual.add(
connection.zRangeByLex("myzset", Range.leftUnbounded(Bound.inclusive("c")), Limit.limit().count(1).offset(1)));
List<Object> results = getResults();
@@ -2847,14 +2848,15 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.zAdd("myzset", 0, "f"));
actual.add(connection.zAdd("myzset", 0, "g"));
actual.add(connection.zRevRangeByLex("myzset", Range.range().lte("c")));
actual.add(connection.zRevRangeByLex("myzset", Range.range().lt("c")));
actual.add(connection.zRevRangeByLex("myzset", Range.range().gte("aaa").lt("g")));
actual.add(connection.zRevRangeByLex("myzset", Range.range().gte("e")));
actual.add(connection.zRevRangeByLex("myzset", Range.leftUnbounded(Bound.inclusive("c"))));
actual.add(connection.zRevRangeByLex("myzset", Range.leftUnbounded(Bound.exclusive("c"))));
actual.add(connection.zRevRangeByLex("myzset", Range.rightOpen("aaa", "g")));
actual.add(connection.zRevRangeByLex("myzset", Range.rightUnbounded(Bound.inclusive("e"))));
actual.add(connection.zRevRangeByLex("myzset", Range.range().lte("c"), Limit.unlimited()));
actual.add(connection.zRevRangeByLex("myzset", Range.range().lte("d"), Limit.limit().count(2)));
actual.add(connection.zRevRangeByLex("myzset", Range.range().lte("d"), Limit.limit().count(2).offset(1)));
actual.add(connection.zRevRangeByLex("myzset", Range.leftUnbounded(Bound.inclusive("c")), Limit.unlimited()));
actual.add(connection.zRevRangeByLex("myzset", Range.leftUnbounded(Bound.inclusive("d")), Limit.limit().count(2)));
actual.add(connection.zRevRangeByLex("myzset", Range.leftUnbounded(Bound.inclusive("d")),
Limit.limit().count(2).offset(1)));
List<Object> results = getResults();

View File

@@ -1000,70 +1000,72 @@ class RedisConnectionUnitTests {
}
@Override
public Set<byte[]> zRangeByLex(byte[] key, Range range) {
public Set<byte[]> zRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range) {
return delegate.zRangeByLex(key, range);
}
@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 delegate.zRangeByLex(key, range, limit);
}
@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 delegate.zRangeByScoreWithScores(key, range, limit);
}
@Override
public Set<byte[]> zRevRangeByScore(byte[] key, Range range) {
public Set<byte[]> zRevRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range) {
return delegate.zRevRangeByScore(key, range);
}
@Override
public Set<byte[]> zRevRangeByScore(byte[] key, Range range,
public Set<byte[]> zRevRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
return delegate.zRevRangeByScore(key, range, limit);
}
@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 delegate.zRevRangeByScoreWithScores(key, range, limit);
}
@Override
public Long zCount(byte[] key, Range range) {
public Long zCount(byte[] key, org.springframework.data.domain.Range<Number> range) {
return delegate.zCount(key, range);
}
@Override
public Long zRemRangeByScore(byte[] key, Range range) {
public Long zRemRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range) {
return delegate.zRemRangeByScore(key, range);
}
@Override
public Long zRemRangeByLex(byte[] key, Range range) {
public Long zRemRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range) {
return delegate.zRemRangeByLex(key, range);
}
@Override
public Set<byte[]> zRangeByScore(byte[] key, Range range) {
public Set<byte[]> zRangeByScore(byte[] key, org.springframework.data.domain.Range<Number> range) {
return delegate.zRangeByScore(key, range);
}
@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 delegate.zRangeByScore(key, range, limit);
}
@Override
public Set<Tuple> zRangeByScoreWithScores(byte[] key, Range range) {
public Set<Tuple> zRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range) {
return delegate.zRangeByScoreWithScores(key, range);
}
@Override
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, Range range) {
public Set<Tuple> zRevRangeByScoreWithScores(byte[] key, org.springframework.data.domain.Range<Number> range) {
return delegate.zRevRangeByScoreWithScores(key, range);
}

View File

@@ -2342,23 +2342,23 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
nativeConnection.zadd(KEY_1, 0, "f");
nativeConnection.zadd(KEY_1, 0, "g");
Set<byte[]> values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lte("c"));
Set<byte[]> values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lte("c").toRange());
assertThat(values).contains(JedisConverters.toBytes("a"), JedisConverters.toBytes("b"),
JedisConverters.toBytes("c"));
assertThat(values).doesNotContain(JedisConverters.toBytes("d"), JedisConverters.toBytes("e"),
JedisConverters.toBytes("f"), JedisConverters.toBytes("g"));
values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lt("c"));
values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lt("c").toRange());
assertThat(values).contains(JedisConverters.toBytes("a"), JedisConverters.toBytes("b"));
assertThat(values).doesNotContain(JedisConverters.toBytes("c"));
values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("aaa").lt("g"));
values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("aaa").lt("g").toRange());
assertThat(values).contains(JedisConverters.toBytes("b"), JedisConverters.toBytes("c"),
JedisConverters.toBytes("d"), JedisConverters.toBytes("e"), JedisConverters.toBytes("f"));
assertThat(values).doesNotContain(JedisConverters.toBytes("a"), JedisConverters.toBytes("g"));
values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("e"));
values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("e").toRange());
assertThat(values).contains(JedisConverters.toBytes("e"), JedisConverters.toBytes("f"),
JedisConverters.toBytes("g"));
assertThat(values).doesNotContain(JedisConverters.toBytes("a"), JedisConverters.toBytes("b"),
@@ -2376,23 +2376,24 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
nativeConnection.zadd(KEY_1, 0, "f");
nativeConnection.zadd(KEY_1, 0, "g");
Set<byte[]> values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().lte("c"));
Set<byte[]> values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().lte("c").toRange());
assertThat(values).containsExactly(JedisConverters.toBytes("c"), JedisConverters.toBytes("b"),
JedisConverters.toBytes("a"));
assertThat(values).doesNotContain(JedisConverters.toBytes("d"), JedisConverters.toBytes("e"),
JedisConverters.toBytes("f"), JedisConverters.toBytes("g"));
values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().lt("c"));
values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().lt("c").toRange());
assertThat(values).containsExactly(JedisConverters.toBytes("b"), JedisConverters.toBytes("a"));
assertThat(values).doesNotContain(JedisConverters.toBytes("c"));
values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().gte("aaa").lt("g"));
values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().gte("aaa").lt("g").toRange());
assertThat(values).containsExactly(JedisConverters.toBytes("f"), JedisConverters.toBytes("e"),
JedisConverters.toBytes("d"), JedisConverters.toBytes("c"), JedisConverters.toBytes("b"));
assertThat(values).doesNotContain(JedisConverters.toBytes("a"), JedisConverters.toBytes("g"));
values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().lte("d"), Limit.limit().count(2).offset(1));
values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().lte("d").toRange(),
Limit.limit().count(2).offset(1));
assertThat(values).hasSize(2).containsExactly(JedisConverters.toBytes("c"), JedisConverters.toBytes("b"));
assertThat(values).doesNotContain(JedisConverters.toBytes("a"), JedisConverters.toBytes("d"),

View File

@@ -30,14 +30,17 @@ import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.connection.RedisServer;
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.data.redis.core.types.RedisClientInfo;
/**
* Unit tests for {@link JedisConverters}.
*
* @author Christoph Strobl
* @author Mark Paluch
*/
class JedisConvertersUnitTests {
@@ -113,46 +116,38 @@ class JedisConvertersUnitTests {
byte[] defaultValue = "tyrion".getBytes();
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.unbounded().getMax(), defaultValue))
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.Bound.unbounded(), defaultValue))
.isEqualTo(defaultValue);
}
@Test // DATAREDIS-378
void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsIncluing() {
assertThat(
JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gte(JedisConverters.toBytes("a")).getMin(), null))
.isEqualTo(JedisConverters.toBytes("[a"));
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.Bound.inclusive(JedisConverters.toBytes("a")), null))
.isEqualTo(JedisConverters.toBytes("[a"));
}
@Test // DATAREDIS-378
void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsExcluding() {
assertThat(
JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gt(JedisConverters.toBytes("a")).getMin(), null))
.isEqualTo(JedisConverters.toBytes("(a"));
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.Bound.exclusive(JedisConverters.toBytes("a")), null))
.isEqualTo(JedisConverters.toBytes("(a"));
}
@Test // DATAREDIS-378
void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsAString() {
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gt("a").getMin(), null))
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.Bound.exclusive(JedisConverters.toBytes("a")), null))
.isEqualTo(JedisConverters.toBytes("(a"));
}
@Test // DATAREDIS-378
void boundaryToBytesForZRangeByLexShouldReturnValueCorrectlyWhenBoundaryIsANumber() {
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gt(1L).getMin(), null))
assertThat(JedisConverters.boundaryToBytesForZRangeByLex(Range.Bound.exclusive(JedisConverters.toBytes("1")), null))
.isEqualTo(JedisConverters.toBytes("(1"));
}
@Test // DATAREDIS-378
void boundaryToBytesForZRangeByLexShouldThrowExceptionWhenBoundaryHoldsUnknownType() {
assertThatIllegalArgumentException()
.isThrownBy(() -> JedisConverters.boundaryToBytesForZRangeByLex(Range.range().gt(new Date()).getMin(), null));
}
@Test // DATAREDIS-352
void boundaryToBytesForZRangeByShouldReturnDefaultValueWhenBoundaryIsNull() {
@@ -166,42 +161,42 @@ class JedisConvertersUnitTests {
byte[] defaultValue = "tyrion".getBytes();
assertThat(JedisConverters.boundaryToBytesForZRange(Range.unbounded().getMax(), defaultValue))
.isEqualTo(defaultValue);
assertThat(JedisConverters.boundaryToBytesForZRange(Range.Bound.unbounded(), defaultValue)).isEqualTo(defaultValue);
}
@Test // DATAREDIS-352
void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsIncluing() {
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gte(JedisConverters.toBytes("a")).getMin(), null))
assertThat(JedisConverters.boundaryToBytesForZRange(Range.Bound.inclusive(JedisConverters.toBytes("a")), null))
.isEqualTo(JedisConverters.toBytes("a"));
}
@Test // DATAREDIS-352
void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsExcluding() {
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gt(JedisConverters.toBytes("a")).getMin(), null))
assertThat(JedisConverters.boundaryToBytesForZRange(Range.Bound.exclusive(JedisConverters.toBytes("a")), null))
.isEqualTo(JedisConverters.toBytes("(a"));
}
@Test // DATAREDIS-352
void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsAString() {
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gt("a").getMin(), null))
assertThat(JedisConverters.boundaryToBytesForZRange(Range.Bound.exclusive("a"), null))
.isEqualTo(JedisConverters.toBytes("(a"));
}
@Test // DATAREDIS-352
void boundaryToBytesForZRangeByShouldReturnValueCorrectlyWhenBoundaryIsANumber() {
assertThat(JedisConverters.boundaryToBytesForZRange(Range.range().gt(1L).getMin(), null))
.isEqualTo(JedisConverters.toBytes("(1"));
assertThat(
JedisConverters.boundaryToBytesForZRange(org.springframework.data.domain.Range.Bound.exclusive(1L), null))
.isEqualTo(JedisConverters.toBytes("(1"));
}
@Test // DATAREDIS-352
void boundaryToBytesForZRangeByShouldThrowExceptionWhenBoundaryHoldsUnknownType() {
assertThatIllegalArgumentException()
.isThrownBy(() -> JedisConverters.boundaryToBytesForZRange(Range.range().gt(new Date()).getMin(), null));
.isThrownBy(() -> JedisConverters.boundaryToBytesForZRange(Range.Bound.exclusive(new Date()), null));
}
@Test // DATAREDIS-316, DATAREDIS-749

View File

@@ -2382,23 +2382,23 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
nativeConnection.zadd(KEY_1, 0, "f");
nativeConnection.zadd(KEY_1, 0, "g");
Set<byte[]> values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lte("c"));
Set<byte[]> values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lte("c").toRange());
assertThat(values).contains(LettuceConverters.toBytes("a"), LettuceConverters.toBytes("b"),
LettuceConverters.toBytes("c"));
assertThat(values).doesNotContain(LettuceConverters.toBytes("d"), LettuceConverters.toBytes("e"),
LettuceConverters.toBytes("f"), LettuceConverters.toBytes("g"));
values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lt("c"));
values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().lt("c").toRange());
assertThat(values).contains(LettuceConverters.toBytes("a"), LettuceConverters.toBytes("b"));
assertThat(values).doesNotContain(LettuceConverters.toBytes("c"));
values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("aaa").lt("g"));
values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("aaa").lt("g").toRange());
assertThat(values).contains(LettuceConverters.toBytes("b"), LettuceConverters.toBytes("c"),
LettuceConverters.toBytes("d"), LettuceConverters.toBytes("e"), LettuceConverters.toBytes("f"));
assertThat(values).doesNotContain(LettuceConverters.toBytes("a"), LettuceConverters.toBytes("g"));
values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("e"));
values = clusterConnection.zRangeByLex(KEY_1_BYTES, Range.range().gte("e").toRange());
assertThat(values).contains(LettuceConverters.toBytes("e"), LettuceConverters.toBytes("f"),
LettuceConverters.toBytes("g"));
assertThat(values).doesNotContain(LettuceConverters.toBytes("a"), LettuceConverters.toBytes("b"),
@@ -2416,23 +2416,24 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
nativeConnection.zadd(KEY_1, 0, "f");
nativeConnection.zadd(KEY_1, 0, "g");
Set<byte[]> values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().lte("c"));
Set<byte[]> values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().lte("c").toRange());
assertThat(values).containsExactly(LettuceConverters.toBytes("c"), LettuceConverters.toBytes("b"),
LettuceConverters.toBytes("a"));
assertThat(values).doesNotContain(LettuceConverters.toBytes("d"), LettuceConverters.toBytes("e"),
LettuceConverters.toBytes("f"), LettuceConverters.toBytes("g"));
values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().lt("c"));
values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().lt("c").toRange());
assertThat(values).containsExactly(LettuceConverters.toBytes("b"), LettuceConverters.toBytes("a"));
assertThat(values).doesNotContain(LettuceConverters.toBytes("c"));
values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().gte("aaa").lt("g"));
values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().gte("aaa").lt("g").toRange());
assertThat(values).containsExactly(LettuceConverters.toBytes("f"), LettuceConverters.toBytes("e"),
LettuceConverters.toBytes("d"), LettuceConverters.toBytes("c"), LettuceConverters.toBytes("b"));
assertThat(values).doesNotContain(LettuceConverters.toBytes("a"), LettuceConverters.toBytes("g"));
values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().lte("d"), Limit.limit().count(2).offset(1));
values = clusterConnection.zRevRangeByLex(KEY_1_BYTES, Range.range().lte("d").toRange(),
Limit.limit().count(2).offset(1));
assertThat(values).hasSize(2).containsExactly(LettuceConverters.toBytes("c"), LettuceConverters.toBytes("b"));
assertThat(values).doesNotContain(LettuceConverters.toBytes("a"), LettuceConverters.toBytes("d"),

View File

@@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.DoubleAsStringObjectFactory;
import org.springframework.data.redis.DoubleObjectFactory;
import org.springframework.data.redis.LongAsStringObjectFactory;
@@ -112,7 +113,7 @@ public class DefaultZSetOperationsIntegrationTests<K, V> {
zSetOps.add(key, value2, 0);
zSetOps.add(key, value3, 0);
assertThat(zSetOps.lexCount(key, RedisZSetCommands.Range.unbounded())).isEqualTo(3);
assertThat(zSetOps.lexCount(key, Range.unbounded())).isEqualTo(3);
}
@ParameterizedRedisTest // DATAREDIS-729
@@ -130,7 +131,7 @@ public class DefaultZSetOperationsIntegrationTests<K, V> {
zSetOps.add(key, value2, 0);
zSetOps.add(key, value3, 0);
assertThat(zSetOps.lexCount(key, RedisZSetCommands.Range.range().gt(value1))).isEqualTo(2);
assertThat(zSetOps.lexCount(key, Range.rightUnbounded(Range.Bound.exclusive(value1.toString())))).isEqualTo(2);
}
@ParameterizedRedisTest // GH-2007
@@ -310,7 +311,7 @@ public class DefaultZSetOperationsIntegrationTests<K, V> {
zSetOps.add(key, value1, 1.9);
zSetOps.add(key, value2, 3.7);
zSetOps.add(key, value3, 5.8);
Set<V> tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.unbounded());
Set<V> tuples = zSetOps.rangeByLex(key, Range.unbounded());
assertThat(tuples).hasSize(3).contains(value1);
}
@@ -329,7 +330,7 @@ public class DefaultZSetOperationsIntegrationTests<K, V> {
zSetOps.add(key, value1, 1.9);
zSetOps.add(key, value2, 3.7);
zSetOps.add(key, value3, 5.8);
Set<V> tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.range().gt(value1).lt(value3));
Set<V> tuples = zSetOps.rangeByLex(key, Range.open(value1.toString(), value3.toString()));
assertThat(tuples).hasSize(1).contains(value2);
}
@@ -348,8 +349,7 @@ public class DefaultZSetOperationsIntegrationTests<K, V> {
zSetOps.add(key, value1, 1.9);
zSetOps.add(key, value2, 3.7);
zSetOps.add(key, value3, 5.8);
Set<V> tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.unbounded(),
Limit.limit().count(2).offset(1));
Set<V> tuples = zSetOps.rangeByLex(key, Range.unbounded(), Limit.limit().count(2).offset(1));
assertThat(tuples).hasSize(2).containsSequence(value2, value3);
}
@@ -368,8 +368,7 @@ public class DefaultZSetOperationsIntegrationTests<K, V> {
zSetOps.add(key, value1, 1.9);
zSetOps.add(key, value2, 3.7);
zSetOps.add(key, value3, 5.8);
Set<V> tuples = zSetOps.reverseRangeByLex(key, RedisZSetCommands.Range.unbounded(),
Limit.limit().count(2).offset(1));
Set<V> tuples = zSetOps.reverseRangeByLex(key, Range.unbounded(), Limit.limit().count(2).offset(1));
assertThat(tuples).hasSize(2).containsSequence(value2, value1);
}
@@ -388,7 +387,7 @@ public class DefaultZSetOperationsIntegrationTests<K, V> {
zSetOps.add(key, value1, 1.9);
zSetOps.add(key, value2, 3.7);
zSetOps.add(key, value3, 5.8);
Set<V> tuples = zSetOps.rangeByLex(key, RedisZSetCommands.Range.range().gte(value1),
Set<V> tuples = zSetOps.rangeByLex(key, Range.rightUnbounded(Range.Bound.inclusive(value1.toString())),
Limit.limit().count(1).offset(1));
assertThat(tuples).hasSize(1).startsWith(value2);

View File

@@ -22,7 +22,8 @@ import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.connection.RedisZSetCommands.ZAddArgs;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
@@ -46,10 +47,10 @@ class DefaultZSetOperationsUnitTests {
@Test // GH-1816
void delegatesRemoveRangeByLex() {
Range range = Range.range().gte("alpha").lte("omega");
Range<String> range = Range.closed("alpha", "omega");
zSetOperations.removeRangeByLex("key", range);
template.verify().zRemRangeByLex(eq(template.serializeKey("key")), eq(range));
template.verify().zRemRangeByLex(eq(template.serializeKey("key")), any(Range.class));
}
@Test // GH-1794

View File

@@ -29,13 +29,13 @@ import java.util.concurrent.TimeUnit;
import org.assertj.core.data.Offset;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.DoubleAsStringObjectFactory;
import org.springframework.data.redis.DoubleObjectFactory;
import org.springframework.data.redis.LongAsStringObjectFactory;
import org.springframework.data.redis.LongObjectFactory;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.core.BoundZSetOperations;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.DefaultTypedTuple;
@@ -260,7 +260,7 @@ public abstract class AbstractRedisZSetTestIntegration<T> extends AbstractRedisC
zSet.add(t2, 1);
zSet.add(t3, 1);
assertThat(zSet.lexCount(RedisZSetCommands.Range.unbounded())).isEqualTo(Long.valueOf(3));
assertThat(zSet.lexCount(Range.unbounded())).isEqualTo(Long.valueOf(3));
}
@ParameterizedRedisTest // DATAREDIS-729
@@ -277,7 +277,7 @@ public abstract class AbstractRedisZSetTestIntegration<T> extends AbstractRedisC
zSet.add(t2, 1);
zSet.add(t3, 1);
assertThat(zSet.lexCount(RedisZSetCommands.Range.range().gt(t1))).isEqualTo(Long.valueOf(2));
assertThat(zSet.lexCount(Range.rightUnbounded(Range.Bound.exclusive(t1.toString())))).isEqualTo(Long.valueOf(2));
}
@ParameterizedRedisTest
@@ -401,7 +401,7 @@ public abstract class AbstractRedisZSetTestIntegration<T> extends AbstractRedisC
zSet.add(t1, 1);
zSet.add(t2, 2);
zSet.add(t3, 3);
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.unbounded());
Set<T> tuples = zSet.rangeByLex(Range.unbounded());
assertThat(tuples).hasSize(3);
T tuple = tuples.iterator().next();
@@ -421,7 +421,7 @@ public abstract class AbstractRedisZSetTestIntegration<T> extends AbstractRedisC
zSet.add(t1, 1);
zSet.add(t2, 2);
zSet.add(t3, 3);
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.range().gt(t1).lt(t3));
Set<T> tuples = zSet.rangeByLex(Range.open(t1.toString(), t3.toString()));
assertThat(tuples).hasSize(1);
T tuple = tuples.iterator().next();
@@ -441,8 +441,7 @@ public abstract class AbstractRedisZSetTestIntegration<T> extends AbstractRedisC
zSet.add(t1, 1);
zSet.add(t2, 2);
zSet.add(t3, 3);
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.unbounded(),
Limit.limit().count(1).offset(1));
Set<T> tuples = zSet.rangeByLex(Range.unbounded(), Limit.limit().count(1).offset(1));
assertThat(tuples).hasSize(1);
T tuple = tuples.iterator().next();
@@ -452,8 +451,8 @@ public abstract class AbstractRedisZSetTestIntegration<T> extends AbstractRedisC
@ParameterizedRedisTest // DATAREDIS-407
void testRangeByLexBoundedWithLimit() {
assumeThat(factory).isOfAnyClassIn(DoubleObjectFactory.class,
LongAsStringObjectFactory.class, LongObjectFactory.class);
assumeThat(factory).isOfAnyClassIn(DoubleObjectFactory.class, LongAsStringObjectFactory.class,
LongObjectFactory.class);
T t1 = getT();
T t2 = getT();
@@ -462,7 +461,7 @@ public abstract class AbstractRedisZSetTestIntegration<T> extends AbstractRedisC
zSet.add(t1, 1);
zSet.add(t2, 2);
zSet.add(t3, 3);
Set<T> tuples = zSet.rangeByLex(RedisZSetCommands.Range.range().gte(t1),
Set<T> tuples = zSet.rangeByLex(Range.rightUnbounded(Range.Bound.inclusive(t1.toString())),
Limit.limit().count(2).offset(1));
assertThat(tuples).hasSize(2).containsSequence(t2, t3);
@@ -481,7 +480,7 @@ public abstract class AbstractRedisZSetTestIntegration<T> extends AbstractRedisC
zSet.add(t1, 1);
zSet.add(t2, 2);
zSet.add(t3, 3);
Set<T> tuples = zSet.reverseRangeByLex(RedisZSetCommands.Range.range().gte(t1),
Set<T> tuples = zSet.reverseRangeByLex(Range.rightUnbounded(Range.Bound.inclusive(t1.toString())),
Limit.limit().count(2).offset(1));
assertThat(tuples).hasSize(2).containsSequence(t2, t1);
@@ -863,7 +862,7 @@ public abstract class AbstractRedisZSetTestIntegration<T> extends AbstractRedisC
@EnabledOnCommand("ZRANDMEMBER")
void randMemberReturnsSomething() {
Object[] valuesArray = new Object[]{getT(), getT(), getT()};
Object[] valuesArray = new Object[] { getT(), getT(), getT() };
collection.addAll((List<T>) Arrays.asList(valuesArray));