Skip to content

Add support for ZMSCORE and ZPOPMIN/ZPOPMAX commands #2088

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

Closed
wants to merge 9 commits into from
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
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.6.0-SNAPSHOT</version>
<version>2.6.0-2038-SNAPSHOT</version>

<name>Spring Data Redis</name>

Expand Down
2 changes: 1 addition & 1 deletion src/main/asciidoc/new-features.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This section briefly covers items that are new and noteworthy in the latest rele
== New in Spring Data Redis 2.6

* Support for `SubscriptionListener` when using `MessageListener` for subscription confirmation callbacks. `ReactiveRedisMessageListenerContainer` and `ReactiveRedisOperations` provide `receiveLater(…)` and `listenToLater(…)` methods to await until Redis acknowledges the subscription.
* Support Redis 6.2 commands (`LPOP`/`RPOP` with `count`, `COPY`, `GETEX`, `GETDEL`).
* Support Redis 6.2 commands (`LPOP`/`RPOP` with `count`, `COPY`, `GETEX`, `GETDEL`, `ZPOPMIN`, `BZPOPMIN`, `ZPOPMAX`, `BZPOPMAX`, `ZMSCORE`).

[[new-in-2.5.0]]
== New in Spring Data Redis 2.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
private final RedisSerializer<String> serializer;
private Converter<byte[], String> bytesToString = new DeserializingConverter();
private Converter<String, byte[]> stringToBytes = new SerializingConverter();
private SetConverter<Tuple, StringTuple> tupleToStringTuple = new SetConverter<>(new TupleConverter());
private final TupleConverter tupleConverter = new TupleConverter();
private SetConverter<Tuple, StringTuple> tupleToStringTuple = new SetConverter<>(tupleConverter);
private SetConverter<StringTuple, Tuple> stringTupleToTuple = new SetConverter<>(new StringTupleConverter());
private ListConverter<byte[], String> byteListToStringList = new ListConverter<>(bytesToString);
private MapConverter<byte[], String> byteMapToStringMap = new MapConverter<>(bytesToString);
Expand Down Expand Up @@ -1722,6 +1723,15 @@ public Double zScore(byte[] key, byte[] value) {
return convertAndReturn(delegate.zScore(key, value), Converters.identityConverter());
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zMScore(byte[], byte[][])
*/
@Override
public List<Double> zMScore(byte[] key, byte[]... values) {
return convertAndReturn(delegate.zMScore(key, values), Converters.identityConverter());
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zUnionStore(byte[], org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, org.springframework.data.redis.connection.RedisZSetCommands.Weights, byte[][])
Expand Down Expand Up @@ -2852,6 +2862,126 @@ public Long zLexCount(byte[] key, Range range) {
return delegate.zLexCount(key, range);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMin(byte[])
*/
@Nullable
@Override
public Tuple zPopMin(byte[] key) {
return delegate.zPopMin(key);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMin(String)
*/
@Nullable
@Override
public StringTuple zPopMin(String key) {
return convertAndReturn(delegate.zPopMin(serialize(key)), tupleConverter);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMinMin(byte[], count)
*/
@Nullable
@Override
public Set<Tuple> zPopMin(byte[] key, long count) {
return delegate.zPopMin(key, count);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMin(String, long)
*/
@Nullable
@Override
public Set<StringTuple> zPopMin(String key, long count) {
return convertAndReturn(delegate.zPopMin(serialize(key), count), tupleToStringTuple);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#bZPopMin(byte[], long, java.util.concurrent.TimeUnit)
*/
@Nullable
@Override
public Tuple bZPopMin(byte[] key, long timeout, TimeUnit unit) {
return delegate.bZPopMin(key, timeout, unit);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#bZPopMin(String, long, java.util.concurrent.TimeUnit)
*/
@Nullable
@Override
public StringTuple bZPopMin(String key, long timeout, TimeUnit unit) {
return convertAndReturn(delegate.bZPopMin(serialize(key), timeout, unit), tupleConverter);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMax(byte[])
*/
@Nullable
@Override
public Tuple zPopMax(byte[] key) {
return delegate.zPopMax(key);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMax(String)
*/
@Nullable
@Override
public StringTuple zPopMax(String key) {
return convertAndReturn(delegate.zPopMax(serialize(key)), tupleConverter);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMax(byte[], long)
*/
@Nullable
@Override
public Set<Tuple> zPopMax(byte[] key, long count) {
return delegate.zPopMax(key, count);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMax(String, long)
*/
@Nullable
@Override
public Set<StringTuple> zPopMax(String key, long count) {
return convertAndReturn(delegate.zPopMax(serialize(key), count), tupleToStringTuple);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#bZPopMax(byte[], long, java.util.concurrent.TimeUnit)
*/
@Nullable
@Override
public Tuple bZPopMax(byte[] key, long timeout, TimeUnit unit) {
return delegate.bZPopMax(key, timeout, unit);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.RedisZSetCommands#bZPopMax(String, long, java.util.concurrent.TimeUnit)
*/
@Nullable
@Override
public StringTuple bZPopMax(String key, long timeout, TimeUnit unit) {
return convertAndReturn(delegate.bZPopMax(serialize(key), timeout, unit), tupleConverter);
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection#zIncrBy(java.lang.String, double, java.lang.String)
Expand Down Expand Up @@ -3052,6 +3182,15 @@ public Double zScore(String key, String value) {
return zScore(serialize(key), serialize(value));
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection#zMScore(java.lang.String, java.lang.String[])
*/
@Override
public List<Double> zMScore(String key, String... values) {
return zMScore(serialize(key), serializeMulti(values));
}

/*
* (non-Javadoc)
* @see org.springframework.data.redis.connection.StringRedisConnection#zUnionStore(java.lang.String, org.springframework.data.redis.connection.RedisZSetCommands.Aggregate, int[], java.lang.String[])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,14 @@ public int compareTo(Double o) {
Double a = (o == null ? Double.valueOf(0.0d) : o);
return d.compareTo(a);
}

@Override
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append(getClass().getSimpleName());
sb.append(" [score=").append(score);
sb.append(", value=").append(value == null ? "null" : new String(value));
sb.append(']');
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,48 @@ default Long zLexCount(byte[] key, Range range) {
return zSetCommands().zLexCount(key, range);
}

/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Tuple zPopMin(byte[] key) {
return zSetCommands().zPopMin(key);
}

/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Set<Tuple> zPopMin(byte[] key, long count) {
return zSetCommands().zPopMin(key, count);
}

/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Tuple bZPopMin(byte[] key, long timeout, TimeUnit unit) {
return zSetCommands().bZPopMin(key, timeout, unit);
}

/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Tuple zPopMax(byte[] key) {
return zSetCommands().zPopMax(key);
}

/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Set<Tuple> zPopMax(byte[] key, long count) {
return zSetCommands().zPopMax(key, count);
}

/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default Tuple bZPopMax(byte[] key, long timeout, TimeUnit unit) {
return zSetCommands().bZPopMax(key, timeout, unit);
}

/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
Expand Down Expand Up @@ -1103,6 +1145,13 @@ default Double zScore(byte[] key, byte[] value) {
return zSetCommands().zScore(key, value);
}

/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
default List<Double> zMScore(byte[] key, byte[]... values) {
return zSetCommands().zMScore(key, values);
}

/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
@Override
@Deprecated
Expand Down
Loading