20
20
import redis .clients .jedis .params .ZParams ;
21
21
import redis .clients .jedis .params .ZRangeParams ;
22
22
import redis .clients .jedis .resps .ScanResult ;
23
+ import redis .clients .jedis .util .KeyValue ;
23
24
24
25
import java .util .ArrayList ;
25
26
import java .util .LinkedHashSet ;
34
35
import org .springframework .data .redis .connection .RedisZSetCommands ;
35
36
import org .springframework .data .redis .connection .convert .SetConverter ;
36
37
import org .springframework .data .redis .connection .zset .Aggregate ;
37
- import org .springframework .data .redis .connection .zset .DefaultTuple ;
38
38
import org .springframework .data .redis .connection .zset .Tuple ;
39
39
import org .springframework .data .redis .connection .zset .Weights ;
40
40
import org .springframework .data .redis .core .Cursor ;
46
46
import org .springframework .util .Assert ;
47
47
48
48
/**
49
+ * Cluster {@link RedisZSetCommands} implementation for Jedis.
50
+ *
49
51
* @author Christoph Strobl
50
52
* @author Mark Paluch
51
53
* @author Clement Ong
52
54
* @author Andrey Shlykov
53
55
* @author Jens Deppe
54
56
* @author Shyngys Sapraliyev
57
+ * @author John Blum
55
58
* @since 2.0
56
59
*/
57
60
class JedisClusterZSetCommands implements RedisZSetCommands {
58
61
59
- private static final SetConverter <redis .clients .jedis .resps .Tuple , Tuple > TUPLE_SET_CONVERTER = new SetConverter <>(
60
- JedisConverters ::toTuple );
62
+ private static final SetConverter <redis .clients .jedis .resps .Tuple , Tuple > TUPLE_SET_CONVERTER =
63
+ new SetConverter <>(JedisConverters ::toTuple );
64
+
61
65
private final JedisClusterConnection connection ;
62
66
63
67
JedisClusterZSetCommands (JedisClusterConnection connection ) {
@@ -818,7 +822,7 @@ public Set<byte[]> zDiff(byte[]... sets) {
818
822
if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
819
823
820
824
try {
821
- return connection .getCluster ().zdiff (sets );
825
+ return JedisConverters . toSet ( connection .getCluster ().zdiff (sets ) );
822
826
} catch (Exception ex ) {
823
827
throw convertJedisAccessException (ex );
824
828
}
@@ -835,7 +839,7 @@ public Set<Tuple> zDiffWithScores(byte[]... sets) {
835
839
if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
836
840
837
841
try {
838
- return JedisConverters .toTupleSet ( connection .getCluster ().zdiffWithScores (sets ));
842
+ return JedisConverters .toSet ( JedisConverters . toTupleList ( connection .getCluster ().zdiffWithScores (sets ) ));
839
843
} catch (Exception ex ) {
840
844
throw convertJedisAccessException (ex );
841
845
}
@@ -872,7 +876,7 @@ public Set<byte[]> zInter(byte[]... sets) {
872
876
if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
873
877
874
878
try {
875
- return connection .getCluster ().zinter (new ZParams (), sets );
879
+ return JedisConverters . toSet ( connection .getCluster ().zinter (new ZParams (), sets ) );
876
880
} catch (Exception ex ) {
877
881
throw convertJedisAccessException (ex );
878
882
}
@@ -889,7 +893,8 @@ public Set<Tuple> zInterWithScores(byte[]... sets) {
889
893
if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
890
894
891
895
try {
892
- return JedisConverters .toTupleSet (connection .getCluster ().zinterWithScores (new ZParams (), sets ));
896
+ return JedisConverters .toSet (JedisConverters .toTupleList (connection .getCluster ()
897
+ .zinterWithScores (new ZParams (), sets )));
893
898
} catch (Exception ex ) {
894
899
throw convertJedisAccessException (ex );
895
900
}
@@ -909,8 +914,8 @@ public Set<Tuple> zInterWithScores(Aggregate aggregate, Weights weights, byte[].
909
914
if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
910
915
911
916
try {
912
- return JedisConverters
913
- .toTupleSet ( connection . getCluster (). zinterWithScores (toZParams (aggregate , weights ), sets ));
917
+ return JedisConverters . toSet ( JedisConverters . toTupleList ( connection . getCluster ()
918
+ .zinterWithScores (toZParams (aggregate , weights ), sets ) ));
914
919
} catch (Exception ex ) {
915
920
throw convertJedisAccessException (ex );
916
921
}
@@ -971,7 +976,7 @@ public Set<byte[]> zUnion(byte[]... sets) {
971
976
if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
972
977
973
978
try {
974
- return connection .getCluster ().zunion (new ZParams (), sets );
979
+ return JedisConverters . toSet ( connection .getCluster ().zunion (new ZParams (), sets ) );
975
980
} catch (Exception ex ) {
976
981
throw convertJedisAccessException (ex );
977
982
}
@@ -988,7 +993,8 @@ public Set<Tuple> zUnionWithScores(byte[]... sets) {
988
993
if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
989
994
990
995
try {
991
- return JedisConverters .toTupleSet (connection .getCluster ().zunionWithScores (new ZParams (), sets ));
996
+ return JedisConverters .toSet (JedisConverters .toTupleList (connection .getCluster ()
997
+ .zunionWithScores (new ZParams (), sets )));
992
998
} catch (Exception ex ) {
993
999
throw convertJedisAccessException (ex );
994
1000
}
@@ -1008,10 +1014,11 @@ public Set<Tuple> zUnionWithScores(Aggregate aggregate, Weights weights, byte[].
1008
1014
if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
1009
1015
1010
1016
try {
1011
- return JedisConverters
1012
- .toTupleSet ( connection . getCluster (). zunionWithScores (toZParams (aggregate , weights ), sets ));
1017
+ return JedisConverters . toSet ( JedisConverters . toTupleList ( connection . getCluster ()
1018
+ .zunionWithScores (toZParams (aggregate , weights ), sets ) ));
1013
1019
} catch (Exception ex ) {
1014
1020
throw convertJedisAccessException (ex );
1021
+
1015
1022
}
1016
1023
}
1017
1024
@@ -1126,21 +1133,14 @@ private static ZParams toZParams(Aggregate aggregate, Weights weights) {
1126
1133
return new ZParams ().weights (weights .toArray ()).aggregate (ZParams .Aggregate .valueOf (aggregate .name ()));
1127
1134
}
1128
1135
1129
- /**
1130
- * Workaround for broken Jedis BZPOP signature.
1131
- *
1132
- * @param bytes
1133
- * @return
1134
- */
1135
1136
@ Nullable
1136
- @ SuppressWarnings ("unchecked" )
1137
- private static Tuple toTuple (@ Nullable List <?> bytes ) {
1137
+ private static Tuple toTuple (@ Nullable KeyValue <?, redis .clients .jedis .resps .Tuple > keyValue ) {
1138
1138
1139
- if (bytes == null || bytes .isEmpty ()) {
1140
- return null ;
1139
+ if (keyValue != null ) {
1140
+ redis .clients .jedis .resps .Tuple tuple = keyValue .getValue ();
1141
+ return tuple != null ? JedisConverters .toTuple (tuple ) : null ;
1141
1142
}
1142
1143
1143
- return new DefaultTuple (( byte []) bytes . get ( 1 ), Double . parseDouble ( new String (( byte []) bytes . get ( 2 )))) ;
1144
+ return null ;
1144
1145
}
1145
-
1146
1146
}
0 commit comments