Skip to content

Commit 1dda7a7

Browse files
mp911dechristophstrobl
authored andcommitted
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 ac226de commit 1dda7a7

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`, `GETEX`, `GETDEL`, `ZMSCORE`).
10+
* Support Redis 6.2 commands (`LPOP`/`RPOP` with `count`, `COPY`, `GETEX`, `GETDEL`, `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);
@@ -2861,6 +2862,126 @@ public Long zLexCount(byte[] key, Range range) {
28612862
return delegate.zLexCount(key, range);
28622863
}
28632864

2865+
/*
2866+
* (non-Javadoc)
2867+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMin(byte[])
2868+
*/
2869+
@Nullable
2870+
@Override
2871+
public Tuple zPopMin(byte[] key) {
2872+
return delegate.zPopMin(key);
2873+
}
2874+
2875+
/*
2876+
* (non-Javadoc)
2877+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMin(String)
2878+
*/
2879+
@Nullable
2880+
@Override
2881+
public StringTuple zPopMin(String key) {
2882+
return convertAndReturn(delegate.zPopMin(serialize(key)), tupleConverter);
2883+
}
2884+
2885+
/*
2886+
* (non-Javadoc)
2887+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMinMin(byte[], count)
2888+
*/
2889+
@Nullable
2890+
@Override
2891+
public Set<Tuple> zPopMin(byte[] key, long count) {
2892+
return delegate.zPopMin(key, count);
2893+
}
2894+
2895+
/*
2896+
* (non-Javadoc)
2897+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMin(String, long)
2898+
*/
2899+
@Nullable
2900+
@Override
2901+
public Set<StringTuple> zPopMin(String key, long count) {
2902+
return convertAndReturn(delegate.zPopMin(serialize(key), count), tupleToStringTuple);
2903+
}
2904+
2905+
/*
2906+
* (non-Javadoc)
2907+
* @see org.springframework.data.redis.connection.RedisZSetCommands#bZPopMin(byte[], long, java.util.concurrent.TimeUnit)
2908+
*/
2909+
@Nullable
2910+
@Override
2911+
public Tuple bZPopMin(byte[] key, long timeout, TimeUnit unit) {
2912+
return delegate.bZPopMin(key, timeout, unit);
2913+
}
2914+
2915+
/*
2916+
* (non-Javadoc)
2917+
* @see org.springframework.data.redis.connection.RedisZSetCommands#bZPopMin(String, long, java.util.concurrent.TimeUnit)
2918+
*/
2919+
@Nullable
2920+
@Override
2921+
public StringTuple bZPopMin(String key, long timeout, TimeUnit unit) {
2922+
return convertAndReturn(delegate.bZPopMin(serialize(key), timeout, unit), tupleConverter);
2923+
}
2924+
2925+
/*
2926+
* (non-Javadoc)
2927+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMax(byte[])
2928+
*/
2929+
@Nullable
2930+
@Override
2931+
public Tuple zPopMax(byte[] key) {
2932+
return delegate.zPopMax(key);
2933+
}
2934+
2935+
/*
2936+
* (non-Javadoc)
2937+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMax(String)
2938+
*/
2939+
@Nullable
2940+
@Override
2941+
public StringTuple zPopMax(String key) {
2942+
return convertAndReturn(delegate.zPopMax(serialize(key)), tupleConverter);
2943+
}
2944+
2945+
/*
2946+
* (non-Javadoc)
2947+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMax(byte[], long)
2948+
*/
2949+
@Nullable
2950+
@Override
2951+
public Set<Tuple> zPopMax(byte[] key, long count) {
2952+
return delegate.zPopMax(key, count);
2953+
}
2954+
2955+
/*
2956+
* (non-Javadoc)
2957+
* @see org.springframework.data.redis.connection.RedisZSetCommands#zPopMax(String, long)
2958+
*/
2959+
@Nullable
2960+
@Override
2961+
public Set<StringTuple> zPopMax(String key, long count) {
2962+
return convertAndReturn(delegate.zPopMax(serialize(key), count), tupleToStringTuple);
2963+
}
2964+
2965+
/*
2966+
* (non-Javadoc)
2967+
* @see org.springframework.data.redis.connection.RedisZSetCommands#bZPopMax(byte[], long, java.util.concurrent.TimeUnit)
2968+
*/
2969+
@Nullable
2970+
@Override
2971+
public Tuple bZPopMax(byte[] key, long timeout, TimeUnit unit) {
2972+
return delegate.bZPopMax(key, timeout, unit);
2973+
}
2974+
2975+
/*
2976+
* (non-Javadoc)
2977+
* @see org.springframework.data.redis.connection.RedisZSetCommands#bZPopMax(String, long, java.util.concurrent.TimeUnit)
2978+
*/
2979+
@Nullable
2980+
@Override
2981+
public StringTuple bZPopMax(String key, long timeout, TimeUnit unit) {
2982+
return convertAndReturn(delegate.bZPopMax(serialize(key), timeout, unit), tupleConverter);
2983+
}
2984+
28642985
/*
28652986
* (non-Javadoc)
28662987
* @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
@@ -942,6 +942,48 @@ default Long zLexCount(byte[] key, Range range) {
942942
return zSetCommands().zLexCount(key, range);
943943
}
944944

945+
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
946+
@Override
947+
@Deprecated
948+
default Tuple zPopMin(byte[] key) {
949+
return zSetCommands().zPopMin(key);
950+
}
951+
952+
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
953+
@Override
954+
@Deprecated
955+
default Set<Tuple> zPopMin(byte[] key, long count) {
956+
return zSetCommands().zPopMin(key, count);
957+
}
958+
959+
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
960+
@Override
961+
@Deprecated
962+
default Tuple bZPopMin(byte[] key, long timeout, TimeUnit unit) {
963+
return zSetCommands().bZPopMin(key, timeout, unit);
964+
}
965+
966+
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
967+
@Override
968+
@Deprecated
969+
default Tuple zPopMax(byte[] key) {
970+
return zSetCommands().zPopMax(key);
971+
}
972+
973+
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
974+
@Override
975+
@Deprecated
976+
default Set<Tuple> zPopMax(byte[] key, long count) {
977+
return zSetCommands().zPopMax(key, count);
978+
}
979+
980+
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
981+
@Override
982+
@Deprecated
983+
default Tuple bZPopMax(byte[] key, long timeout, TimeUnit unit) {
984+
return zSetCommands().bZPopMax(key, timeout, unit);
985+
}
986+
945987
/** @deprecated in favor of {@link RedisConnection#zSetCommands()}}. */
946988
@Override
947989
@Deprecated

0 commit comments

Comments
 (0)