DATAREDIS-729 - Expose reverseRangeByLex methods on Template API.

Also, switch methods to default methods where applicable.

Original pull request: #566.
This commit is contained in:
Mark Paluch
2020-10-13 12:38:28 +02:00
parent df37dc812b
commit 41136c6934
8 changed files with 173 additions and 42 deletions

View File

@@ -368,7 +368,9 @@ 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);
default Set<V> rangeByLex(Range range) {
return rangeByLex(range, Limit.unlimited());
}
/**
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
@@ -384,6 +386,34 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
@Nullable
Set<V> rangeByLex(Range range, Limit limit);
/**
* Get all elements with reverse lexicographical ordering with a value between {@link Range#getMin()} and
* {@link Range#getMax()}.
*
* @param range must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 2.4
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
*/
@Nullable
default Set<V> reverseRangeByLex(Range 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()}.
*
* @param range must not be {@literal null}.
* @param limit can be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 2.4
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
*/
@Nullable
Set<V> reverseRangeByLex(Range range, Limit limit);
/**
* @return never {@literal null}.
*/

View File

@@ -104,7 +104,7 @@ class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> impl
return ops.intersectAndStore(getKey(), otherKeys, destKey);
}
/*
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.BoundZSetOperations#intersectAndStore(java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate)
*/
@@ -113,7 +113,7 @@ class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> impl
return ops.intersectAndStore(getKey(), otherKeys, destKey, aggregate);
}
/*
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.BoundZSetOperations#intersectAndStore(java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights)
*/
@@ -185,15 +185,6 @@ class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> impl
return ops.reverseRangeWithScores(getKey(), start, end);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.BoundZSetOperations#rangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range)
*/
@Override
public Set<V> rangeByLex(Range range) {
return rangeByLex(range, Limit.unlimited());
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.BoundZSetOperations#rangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
@@ -203,6 +194,15 @@ class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> impl
return ops.rangeByLex(getKey(), range, limit);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.BoundZSetOperations#reverseRangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
*/
@Override
public Set<V> reverseRangeByLex(Range range, Limit limit) {
return ops.reverseRangeByLex(getKey(), range, limit);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.BoundZSetOperations#rank(java.lang.Object)
@@ -311,7 +311,7 @@ class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> impl
return ops.unionAndStore(getKey(), otherKeys, destKey);
}
/*
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.BoundZSetOperations#unionAndStore(java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate)
*/
@@ -320,7 +320,7 @@ class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> impl
return ops.unionAndStore(getKey(), otherKeys, destKey, aggregate);
}
/*
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.BoundZSetOperations#unionAndStore(java.util.Collection, java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights)
*/

View File

@@ -164,15 +164,6 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
return deserializeTupleValues(rawValues);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ZSetOperations#rangeByLex(java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Range)
*/
@Override
public Set<V> rangeByLex(K key, Range range) {
return rangeByLex(key, range, Limit.unlimited());
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ZSetOperations#rangeByLex(java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
@@ -186,6 +177,19 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
return deserializeValues(rawValues);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ZSetOperations#reverseRangeByLex(java.lang.Object, org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
*/
@Override
public Set<V> reverseRangeByLex(K key, Range range, Limit limit) {
byte[] rawKey = rawKey(key);
Set<byte[]> rawValues = execute(connection -> connection.zRevRangeByLex(rawKey, range, limit), true);
return deserializeValues(rawValues);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.core.ZSetOperations#rangeByScore(java.lang.Object, double, double)

View File

@@ -475,7 +475,9 @@ 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);
default Set<V> rangeByLex(K key, Range range) {
return rangeByLex(key, range, Limit.unlimited());
}
/**
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
@@ -492,6 +494,36 @@ public interface ZSetOperations<K, V> {
@Nullable
Set<V> rangeByLex(K key, Range range, Limit limit);
/**
* Get all elements with reverse lexicographical ordering from {@literal ZSET} at {@code key} with a value between
* {@link Range#getMin()} and {@link Range#getMax()}.
*
* @param key must not be {@literal null}.
* @param range must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 2.4
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
*/
@Nullable
default Set<V> reverseRangeByLex(K key, Range range) {
return reverseRangeByLex(key, range, Limit.unlimited());
}
/**
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
* {@link Limit#getOffset()} with reverse lexicographical ordering from {@literal ZSET} at {@code key} with a value
* between {@link Range#getMin()} and {@link Range#getMax()}.
*
* @param key must not be {@literal null}
* @param range must not be {@literal null}.
* @param limit can be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 2.4
* @see <a href="https://redis.io/commands/zrevrangebylex">Redis Documentation: ZREVRANGEBYLEX</a>
*/
@Nullable
Set<V> reverseRangeByLex(K key, Range range, Limit limit);
/**
* @return never {@literal null}.
*/

View File

@@ -143,15 +143,6 @@ public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements R
return boundZSetOps.reverseRange(start, end);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.support.collections.RedisZSet#rangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range)
*/
@Override
public Set<E> rangeByLex(Range range) {
return boundZSetOps.rangeByLex(range);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.support.collections.RedisZSet#rangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
@@ -161,6 +152,15 @@ public class DefaultRedisZSet<E> extends AbstractRedisCollection<E> implements R
return boundZSetOps.rangeByLex(range, limit);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.support.collections.RedisZSet#reverseRangeByLex(org.springframework.data.redis.connection.RedisZSetCommands.Range, org.springframework.data.redis.connection.RedisZSetCommands.Limit)
*/
@Override
public Set<E> reverseRangeByLex(Range range, Limit limit) {
return boundZSetOps.reverseRangeByLex(range, limit);
}
/*
* (non-Javadoc)
* @see org.springframework.data.redis.support.collections.RedisZSet#rangeByScore(double, double)

View File

@@ -60,7 +60,9 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
* @see BoundZSetOperations#rangeByLex(Range)
* @since 1.7
*/
Set<E> rangeByLex(Range range);
default Set<E> rangeByLex(Range range) {
return rangeByLex(range, Limit.unlimited());
}
/**
* Get all elements {@literal n} elements, where {@literal n = } {@link Limit#getCount()}, starting at
@@ -70,11 +72,37 @@ public interface RedisZSet<E> extends RedisCollection<E>, Set<E> {
* @param range must not be {@literal null}.
* @param limit can be {@literal null}.
* @return
* @see BoundZSetOperations#rangeByLex(Range, Limit)
* @since 1.7
* @see BoundZSetOperations#rangeByLex(Range, Limit)
*/
Set<E> rangeByLex(Range range, Limit limit);
/**
* Get all elements with reverse lexicographical ordering with a value between {@link Range#getMin()} and
* {@link Range#getMax()}.
*
* @param range must not be {@literal null}.
* @return
* @since 2.4
* @see BoundZSetOperations#reverseRangeByLex(Range)
*/
default Set<E> reverseRangeByLex(Range 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()}.
*
* @param range must not be {@literal null}.
* @param limit can be {@literal null}.
* @return
* @since 2.4
* @see BoundZSetOperations#reverseRangeByLex(Range, Limit)
*/
Set<E> reverseRangeByLex(Range range, Limit limit);
Set<E> rangeByScore(double min, double max);
Set<E> reverseRangeByScore(double min, double max);