Skip to content

Commit 78e09c5

Browse files
committed
Add support for ZPOPMIN, ZPOPMAX and their blocking variants.
We now support ZPOPMIN, BZPOPMIN, ZPOPMAX and BZPOPMAX through the Template API for all drivers. Closes #2007
1 parent 6b27348 commit 78e09c5

28 files changed

+1856
-21
lines changed

src/main/asciidoc/new-features.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This section briefly covers items that are new and noteworthy in the latest rele
77
== New in Spring Data Redis 2.6
88

99
* 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.
10-
* Support Redis 6.2 commands (`LPOP`/`RPOP` with `count`, `COPY`, `ZMSCORE`).
10+
* Support Redis 6.2 commands (`LPOP`/`RPOP` with `count`, `COPY`, `ZPOPMIN`, `BZPOPMIN`, `ZPOPMAX`, `BZPOPMAX`, `ZMSCORE`).
1111

1212
[[new-in-2.5.0]]
1313
== New in Spring Data Redis 2.5

src/main/java/org/springframework/data/redis/connection/DefaultStringRedisConnection.java

+122-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public class DefaultStringRedisConnection implements StringRedisConnection, Deco
8181
private final RedisSerializer<String> serializer;
8282
private Converter<byte[], String> bytesToString = new DeserializingConverter();
8383
private Converter<String, byte[]> stringToBytes = new SerializingConverter();
84-
private SetConverter<Tuple, StringTuple> tupleToStringTuple = new SetConverter<>(new TupleConverter());
84+
private final TupleConverter tupleConverter = new TupleConverter();
85+
private SetConverter<Tuple, StringTuple> tupleToStringTuple = new SetConverter<>(tupleConverter);
8586
private SetConverter<StringTuple, Tuple> stringTupleToTuple = new SetConverter<>(new StringTupleConverter());
8687
private ListConverter<byte[], String> byteListToStringList = new ListConverter<>(bytesToString);
8788
private MapConverter<byte[], String> byteMapToStringMap = new MapConverter<>(bytesToString);
@@ -2821,6 +2822,126 @@ public Long zLexCount(byte[] key, Range range) {
28212822
return delegate.zLexCount(key, range);
28222823
}
28232824

2825+
/*
2826+
* (non-Javadoc)
2827+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMin(byte[])
2828+
*/
2829+
@Nullable
2830+
@Override
2831+
public Tuple zPopMin(byte[] key) {
2832+
return delegate.zPopMin(key);
2833+
}
2834+
2835+
/*
2836+
* (non-Javadoc)
2837+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMin(String)
2838+
*/
2839+
@Nullable
2840+
@Override
2841+
public StringTuple zPopMin(String key) {
2842+
return convertAndReturn(delegate.zPopMin(serialize(key)), tupleConverter);
2843+
}
2844+
2845+
/*
2846+
* (non-Javadoc)
2847+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMinMin(byte[], count)
2848+
*/
2849+
@Nullable
2850+
@Override
2851+
public Set<Tuple> zPopMin(byte[] key, long count) {
2852+
return delegate.zPopMin(key, count);
2853+
}
2854+
2855+
/*
2856+
* (non-Javadoc)
2857+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMin(String, long)
2858+
*/
2859+
@Nullable
2860+
@Override
2861+
public Set<StringTuple> zPopMin(String key, long count) {
2862+
return convertAndReturn(delegate.zPopMin(serialize(key), count), tupleToStringTuple);
2863+
}
2864+
2865+
/*
2866+
* (non-Javadoc)
2867+
* @see org.springframework.data.redis.connection.RedisZSetCommands#bZPopMin(byte[], long, java.util.concurrent.TimeUnit)
2868+
*/
2869+
@Nullable
2870+
@Override
2871+
public Tuple bZPopMin(byte[] key, long timeout, TimeUnit unit) {
2872+
return delegate.bZPopMin(key, timeout, unit);
2873+
}
2874+
2875+
/*
2876+
* (non-Javadoc)
2877+
* @see org.springframework.data.redis.connection.RedisZSetCommands#bZPopMin(String, long, java.util.concurrent.TimeUnit)
2878+
*/
2879+
@Nullable
2880+
@Override
2881+
public StringTuple bZPopMin(String key, long timeout, TimeUnit unit) {
2882+
return convertAndReturn(delegate.bZPopMin(serialize(key), timeout, unit), tupleConverter);
2883+
}
2884+
2885+
/*
2886+
* (non-Javadoc)
2887+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMax(byte[])
2888+
*/
2889+
@Nullable
2890+
@Override
2891+
public Tuple zPopMax(byte[] key) {
2892+
return delegate.zPopMax(key);
2893+
}
2894+
2895+
/*
2896+
* (non-Javadoc)
2897+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMax(String)
2898+
*/
2899+
@Nullable
2900+
@Override
2901+
public StringTuple zPopMax(String key) {
2902+
return convertAndReturn(delegate.zPopMax(serialize(key)), tupleConverter);
2903+
}
2904+
2905+
/*
2906+
* (non-Javadoc)
2907+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMax(byte[], long)
2908+
*/
2909+
@Nullable
2910+
@Override
2911+
public Set<Tuple> zPopMax(byte[] key, long count) {
2912+
return delegate.zPopMax(key, count);
2913+
}
2914+
2915+
/*
2916+
* (non-Javadoc)
2917+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMax(String, long)
2918+
*/
2919+
@Nullable
2920+
@Override
2921+
public Set<StringTuple> zPopMax(String key, long count) {
2922+
return convertAndReturn(delegate.zPopMax(serialize(key), count), tupleToStringTuple);
2923+
}
2924+
2925+
/*
2926+
* (non-Javadoc)
2927+
* @see org.springframework.data.redis.connection.RedisZSetCommands#bZPopMax(byte[], long, java.util.concurrent.TimeUnit)
2928+
*/
2929+
@Nullable
2930+
@Override
2931+
public Tuple bZPopMax(byte[] key, long timeout, TimeUnit unit) {
2932+
return delegate.bZPopMax(key, timeout, unit);
2933+
}
2934+
2935+
/*
2936+
* (non-Javadoc)
2937+
* @see org.springframework.data.redis.connection.RedisZSetCommands#bZPopMax(String, long, java.util.concurrent.TimeUnit)
2938+
*/
2939+
@Nullable
2940+
@Override
2941+
public StringTuple bZPopMax(String key, long timeout, TimeUnit unit) {
2942+
return convertAndReturn(delegate.bZPopMax(serialize(key), timeout, unit), tupleConverter);
2943+
}
2944+
28242945
/*
28252946
* (non-Javadoc)
28262947
* @see org.springframework.data.redis.connection.StringRedisConnection#zIncrBy(java.lang.String, double, java.lang.String)

src/main/java/org/springframework/data/redis/connection/DefaultTuple.java

+10
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,14 @@ public int compareTo(Double o) {
8989
Double a = (o == null ? Double.valueOf(0.0d) : o);
9090
return d.compareTo(a);
9191
}
92+
93+
@Override
94+
public String toString() {
95+
StringBuffer sb = new StringBuffer();
96+
sb.append(getClass().getSimpleName());
97+
sb.append(" [score=").append(score);
98+
sb.append(", value=").append(value == null ? "null" : new String(value));
99+
sb.append(']');
100+
return sb.toString();
101+
}
92102
}

src/main/java/org/springframework/data/redis/connection/DefaultedRedisConnection.java

+42
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,48 @@ default Long zLexCount(byte[] key, Range range) {
928928
return zSetCommands().zLexCount(key, range);
929929
}
930930

931+
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
932+
@Override
933+
@Deprecated
934+
default Tuple zPopMin(byte[] key) {
935+
return zSetCommands().zPopMin(key);
936+
}
937+
938+
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
939+
@Override
940+
@Deprecated
941+
default Set<Tuple> zPopMin(byte[] key, long count) {
942+
return zSetCommands().zPopMin(key, count);
943+
}
944+
945+
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
946+
@Override
947+
@Deprecated
948+
default Tuple bZPopMin(byte[] key, long timeout, TimeUnit unit) {
949+
return zSetCommands().bZPopMin(key, timeout, unit);
950+
}
951+
952+
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
953+
@Override
954+
@Deprecated
955+
default Tuple zPopMax(byte[] key) {
956+
return zSetCommands().zPopMax(key);
957+
}
958+
959+
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
960+
@Override
961+
@Deprecated
962+
default Set<Tuple> zPopMax(byte[] key, long count) {
963+
return zSetCommands().zPopMax(key, count);
964+
}
965+
966+
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
967+
@Override
968+
@Deprecated
969+
default Tuple bZPopMax(byte[] key, long timeout, TimeUnit unit) {
970+
return zSetCommands().bZPopMax(key, timeout, unit);
971+
}
972+
931973
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
932974
@Override
933975
@Deprecated

0 commit comments

Comments
 (0)