Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added zRangeStoreByLex and zRangeStoreByScore for ZRANGESTORE c… #2370

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
* @author dengliming
* @author ihaohong
* @author Dennis Neufeld
* @author Shyngys Sapraliyev
*/
@SuppressWarnings({ "ConstantConditions", "deprecation" })
public class DefaultStringRedisConnection implements StringRedisConnection, DecoratedRedisConnection {
Expand Down Expand Up @@ -2710,6 +2711,37 @@ public Set<byte[]> zRevRangeByLex(byte[] key, org.springframework.data.domain.Ra
return convertAndReturn(delegate.zRevRangeByLex(key, range, limit), Converters.identityConverter());
}

@Override
public Long zRangeStoreByLex(byte[] dstKey, byte[] srcKey,
org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit) {
return convertAndReturn(delegate.zRangeStoreByLex(dstKey, srcKey, range, limit),
Converters.identityConverter());
}

@Override
public Long zRangeStoreByLex(String dstKey, String srcKey,
org.springframework.data.domain.Range<String> range,
org.springframework.data.redis.connection.Limit limit) {
return convertAndReturn(delegate.zRangeStoreByLex(serialize(dstKey), serialize(srcKey), serialize(range), limit),
Converters.identityConverter());
}

@Override
public Long zRangeStoreByScore(String dstKey, String srcKey, double min, double max,
org.springframework.data.redis.connection.Limit limit) {
return convertAndReturn(delegate.zRangeStoreByScore(serialize(dstKey), serialize(srcKey), min, max, limit),
Converters.identityConverter());
}

@Override
public Long zRangeStoreByScore(byte[] dstKey, byte[] srcKey,
org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
return convertAndReturn(delegate.zRangeStoreByScore(dstKey, srcKey, range, limit),
Converters.identityConverter());
}

@Override
public Set<String> zRevRangeByLex(String key, org.springframework.data.domain.Range<String> range,
org.springframework.data.redis.connection.Limit limit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
* @author dengliming
* @author ihaohong
* @author Dennis Neufeld
* @author Shyngys Sapraliyev
* @since 2.0
*/
@Deprecated
Expand Down Expand Up @@ -1835,4 +1836,23 @@ default <T> T evalSha(String scriptSha, ReturnType returnType, int numKeys, byte
default <T> T evalSha(byte[] scriptSha, ReturnType returnType, int numKeys, byte[]... keysAndArgs) {
return scriptingCommands().evalSha(scriptSha, returnType, numKeys, keysAndArgs);
}

/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Long zRangeStoreByLex(byte[] dstKey, byte[] srcKey,
org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit) {
return zSetCommands().zRangeStoreByLex(dstKey, srcKey, range, limit);
}

/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Long zRangeStoreByScore(byte[] dstKey, byte[] srcKey,
org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
return zSetCommands().zRangeStoreByScore(dstKey, srcKey, range, limit);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* @author David Liu
* @author Mark Paluch
* @author Andrey Shlykov
* @author Shyngys Sapraliyev
*/
public interface RedisZSetCommands {

Expand Down Expand Up @@ -1367,4 +1368,103 @@ default Set<byte[]> zRevRangeByLex(byte[] key, org.springframework.data.domain.R
Set<byte[]> zRevRangeByLex(byte[] key, org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit);

/**
* This command is like ZRANGE , but stores the result in the {@literal dstKey} destination key.
*
* @param dstKey must not be {@literal null}.
* @param srcKey must not be {@literal null}.
* @param range must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 3.0
* @see <a href="https://redis.io/commands/zrangestore">Redis Documentation: ZRANGESTORE</a>
*/
@Nullable
default Long zRangeStoreByLex(byte[] dstKey, byte[] srcKey,
org.springframework.data.domain.Range<byte[]> range) {
return zRangeStoreByLex(dstKey, srcKey, range, org.springframework.data.redis.connection.Limit.unlimited());
}

/**
* This command is like ZRANGE , but stores the result in the {@literal dstKey} destination key.
*
* @param dstKey must not be {@literal null}.
* @param srcKey must not be {@literal null}.
* @param range must not be {@literal null}.
* @param limit must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 3.0
* @see <a href="https://redis.io/commands/zrangestore">Redis Documentation: ZRANGESTORE</a>
*/
@Nullable
Long zRangeStoreByLex(byte[] dstKey, byte[] srcKey,
org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit);

/**
* This command is like ZRANGE, but stores the result in the {@literal dstKey} destination key.
*
* @param dstKey must not be {@literal null}.
* @param srcKey must not be {@literal null}.
* @param min minimal inclusive score
* @param max maximal inclusive score
* @return {@literal null} when used in pipeline / transaction.
* @since 3.0
* @see <a href="https://redis.io/commands/zrangestore">Redis Documentation: ZRANGESTORE</a>
*/
@Nullable
default Long zRangeStoreByScore(byte[] dstKey, byte[] srcKey, double min, double max) {
return zRangeStoreByScore(dstKey, srcKey, org.springframework.data.domain.Range.closed(min, max));
}

/**
* This command is like ZRANGE, but stores the result in the {@literal dstKey} destination key.
*
* @param dstKey must not be {@literal null}.
* @param srcKey must not be {@literal null}.
* @param min minimal inclusive score
* @param max maximal inclusive score
* @param limit must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 3.0
* @see <a href="https://redis.io/commands/zrangestore">Redis Documentation: ZRANGESTORE</a>
*/
@Nullable
default Long zRangeStoreByScore(byte[] dstKey, byte[] srcKey, double min, double max,
org.springframework.data.redis.connection.Limit limit) {
return zRangeStoreByScore(dstKey, srcKey, org.springframework.data.domain.Range.closed(min, max), limit);
}

/**
* This command is like ZRANGE, but stores the result in the {@literal dstKey} destination key.
*
* @param dstKey must not be {@literal null}.
* @param srcKey must not be {@literal null}.
* @param range must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 3.0
* @see <a href="https://redis.io/commands/zrangestore">Redis Documentation: ZRANGESTORE</a>
*/
@Nullable
default Long zRangeStoreByScore(byte[] dstKey, byte[] srcKey,
org.springframework.data.domain.Range<Number> range) {
return zRangeStoreByScore(dstKey, srcKey, range,
org.springframework.data.redis.connection.Limit.unlimited());
}

/**
* This command is like ZRANGE, but stores the result in the {@literal dstKey} destination key.
*
* @param dstKey must not be {@literal null}.
* @param srcKey must not be {@literal null}.
* @param range must not be {@literal null}.
* @param limit must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 3.0
* @see <a href="https://redis.io/commands/zrangestore">Redis Documentation: ZRANGESTORE</a>
*/
@Nullable
Long zRangeStoreByScore(byte[] dstKey, byte[] srcKey,
org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit);

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
* @author Dengliming
* @author Andrey Shlykov
* @author ihaohong
* @author Shyngys Sapraliyev
*
* @see RedisCallback
* @see RedisSerializer
Expand Down Expand Up @@ -1987,6 +1988,71 @@ default Set<String> zRevRangeByLex(String key, org.springframework.data.domain.R
Set<String> zRevRangeByLex(String key, org.springframework.data.domain.Range<String> range,
org.springframework.data.redis.connection.Limit limit);

/**
* This command is like ZRANGE , but stores the result in the {@literal dstKey} destination key.
*
* @param dstKey must not be {@literal null}.
* @param srcKey must not be {@literal null}.
* @param range must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 3.0
* @see <a href="https://redis.io/commands/zrangestore">Redis Documentation: ZRANGESTORE</a>
*/
@Nullable
default Long zRangeStoreByLex(String dstKey, String srcKey,
org.springframework.data.domain.Range<String> range) {
return zRangeStoreByLex(dstKey, srcKey, range, org.springframework.data.redis.connection.Limit.unlimited());
}

/**
* This command is like ZRANGE , but stores the result in the {@literal dstKey} destination key.
*
* @param dstKey must not be {@literal null}.
* @param srcKey must not be {@literal null}.
* @param range must not be {@literal null}.
* @param limit must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 3.0
* @see <a href="https://redis.io/commands/zrangestore">Redis Documentation: ZRANGESTORE</a>
*/
@Nullable
Long zRangeStoreByLex(String dstKey, String srcKey,
org.springframework.data.domain.Range<String> range,
org.springframework.data.redis.connection.Limit limit);


/**
* This command is like ZRANGE, but stores the result in the {@literal dstKey} destination key.
*
* @param dstKey must not be {@literal null}.
* @param srcKey must not be {@literal null}.
* @param min minimal inclusive score
* @param max maximal inclusive score
* @return {@literal null} when used in pipeline / transaction.
* @since 3.0
* @see <a href="https://redis.io/commands/zrangestore">Redis Documentation: ZRANGESTORE</a>
*/
@Nullable
default Long zRangeStoreByScore(String dstKey, String srcKey, double min, double max) {
return zRangeStoreByScore(dstKey, srcKey, min, max, org.springframework.data.redis.connection.Limit.unlimited());
}

/**
* This command is like ZRANGE, but stores the result in the {@literal dstKey} destination key.
*
* @param dstKey must not be {@literal null}.
* @param srcKey must not be {@literal null}.
* @param min minimal inclusive score
* @param max maximal inclusive score
* @param limit must not be {@literal null}.
* @return {@literal null} when used in pipeline / transaction.
* @since 3.0
* @see <a href="https://redis.io/commands/zrangestore">Redis Documentation: ZRANGESTORE</a>
*/
@Nullable
Long zRangeStoreByScore(String dstKey, String srcKey, double min, double max,
org.springframework.data.redis.connection.Limit limit);

// -------------------------------------------------------------------------
// Methods dealing with Redis Hashes
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
*/
package org.springframework.data.redis.connection.jedis;

import redis.clients.jedis.Protocol;
import redis.clients.jedis.params.ScanParams;
import redis.clients.jedis.params.ZParams;
import redis.clients.jedis.params.ZRangeParams;
import redis.clients.jedis.resps.ScanResult;

import java.util.ArrayList;
Expand Down Expand Up @@ -48,6 +50,7 @@
* @author Mark Paluch
* @author Clement Ong
* @author Andrey Shlykov
* @author Shyngys Sapraliyev
* @since 2.0
*/
class JedisClusterZSetCommands implements RedisZSetCommands {
Expand Down Expand Up @@ -492,6 +495,52 @@ public Set<byte[]> zRevRangeByLex(byte[] key, org.springframework.data.domain.Ra
}
}

@Override
public Long zRangeStoreByLex(byte[] dstKey, byte[] srcKey,
org.springframework.data.domain.Range<byte[]> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(dstKey, "Destination key must not be null");
Assert.notNull(srcKey, "Source key must not be null");
Assert.notNull(range, "Range for ZRANGESTORE BYLEX must not be null");
Assert.notNull(limit, "Limit must not be null. Use Limit.unlimited() instead.");

byte[] min = JedisConverters.boundaryToBytesForZRangeByLex(range.getLowerBound(), JedisConverters.MINUS_BYTES);
byte[] max = JedisConverters.boundaryToBytesForZRangeByLex(range.getUpperBound(), JedisConverters.PLUS_BYTES);

ZRangeParams zRangeParams = new ZRangeParams(Protocol.Keyword.BYLEX, min, max)
.limit(limit.getOffset(), limit.getCount());

try {
return connection.getCluster().zrangestore(dstKey, srcKey, zRangeParams);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}

@Override
public Long zRangeStoreByScore(byte[] dstKey, byte[] srcKey,
org.springframework.data.domain.Range<Number> range,
org.springframework.data.redis.connection.Limit limit) {
Assert.notNull(dstKey, "Destination key must not be null");
Assert.notNull(srcKey, "Source key must not be null");
Assert.notNull(range, "Range for ZRANGESTORE BYSCORE must not be null");
Assert.notNull(limit, "Limit must not be null. Use Limit.unlimited() instead.");

byte[] min = JedisConverters
.boundaryToBytesForZRange(range.getLowerBound(), JedisConverters.NEGATIVE_INFINITY_BYTES);
byte[] max = JedisConverters
.boundaryToBytesForZRange(range.getUpperBound(), JedisConverters.POSITIVE_INFINITY_BYTES);

ZRangeParams zRangeParams = new ZRangeParams(Protocol.Keyword.BYSCORE, min, max)
.limit(limit.getOffset(), limit.getCount());

try {
return connection.getCluster().zrangestore(dstKey, srcKey, zRangeParams);
} catch (Exception ex) {
throw convertJedisAccessException(ex);
}
}

@Override
public Set<Tuple> zRangeWithScores(byte[] key, long start, long end) {

Expand Down
Loading