2020import redis .clients .jedis .params .ZParams ;
2121import redis .clients .jedis .params .ZRangeParams ;
2222import redis .clients .jedis .resps .ScanResult ;
23+ import redis .clients .jedis .util .KeyValue ;
2324
2425import java .util .ArrayList ;
2526import java .util .LinkedHashSet ;
3435import org .springframework .data .redis .connection .RedisZSetCommands ;
3536import org .springframework .data .redis .connection .convert .SetConverter ;
3637import org .springframework .data .redis .connection .zset .Aggregate ;
37- import org .springframework .data .redis .connection .zset .DefaultTuple ;
3838import org .springframework .data .redis .connection .zset .Tuple ;
3939import org .springframework .data .redis .connection .zset .Weights ;
4040import org .springframework .data .redis .core .Cursor ;
4646import org .springframework .util .Assert ;
4747
4848/**
49+ * Cluster {@link RedisZSetCommands} implementation for Jedis.
50+ *
4951 * @author Christoph Strobl
5052 * @author Mark Paluch
5153 * @author Clement Ong
5254 * @author Andrey Shlykov
5355 * @author Jens Deppe
5456 * @author Shyngys Sapraliyev
57+ * @author John Blum
5558 * @since 2.0
5659 */
5760class JedisClusterZSetCommands implements RedisZSetCommands {
5861
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+
6165 private final JedisClusterConnection connection ;
6266
6367 JedisClusterZSetCommands (JedisClusterConnection connection ) {
@@ -818,7 +822,7 @@ public Set<byte[]> zDiff(byte[]... sets) {
818822 if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
819823
820824 try {
821- return connection .getCluster ().zdiff (sets );
825+ return JedisConverters . toSet ( connection .getCluster ().zdiff (sets ) );
822826 } catch (Exception ex ) {
823827 throw convertJedisAccessException (ex );
824828 }
@@ -835,7 +839,7 @@ public Set<Tuple> zDiffWithScores(byte[]... sets) {
835839 if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
836840
837841 try {
838- return JedisConverters .toTupleSet ( connection .getCluster ().zdiffWithScores (sets ));
842+ return JedisConverters .toSet ( JedisConverters . toTupleList ( connection .getCluster ().zdiffWithScores (sets ) ));
839843 } catch (Exception ex ) {
840844 throw convertJedisAccessException (ex );
841845 }
@@ -872,7 +876,7 @@ public Set<byte[]> zInter(byte[]... sets) {
872876 if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
873877
874878 try {
875- return connection .getCluster ().zinter (new ZParams (), sets );
879+ return JedisConverters . toSet ( connection .getCluster ().zinter (new ZParams (), sets ) );
876880 } catch (Exception ex ) {
877881 throw convertJedisAccessException (ex );
878882 }
@@ -889,7 +893,8 @@ public Set<Tuple> zInterWithScores(byte[]... sets) {
889893 if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
890894
891895 try {
892- return JedisConverters .toTupleSet (connection .getCluster ().zinterWithScores (new ZParams (), sets ));
896+ return JedisConverters .toSet (JedisConverters .toTupleList (connection .getCluster ()
897+ .zinterWithScores (new ZParams (), sets )));
893898 } catch (Exception ex ) {
894899 throw convertJedisAccessException (ex );
895900 }
@@ -909,8 +914,8 @@ public Set<Tuple> zInterWithScores(Aggregate aggregate, Weights weights, byte[].
909914 if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
910915
911916 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 ) ));
914919 } catch (Exception ex ) {
915920 throw convertJedisAccessException (ex );
916921 }
@@ -971,7 +976,7 @@ public Set<byte[]> zUnion(byte[]... sets) {
971976 if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
972977
973978 try {
974- return connection .getCluster ().zunion (new ZParams (), sets );
979+ return JedisConverters . toSet ( connection .getCluster ().zunion (new ZParams (), sets ) );
975980 } catch (Exception ex ) {
976981 throw convertJedisAccessException (ex );
977982 }
@@ -988,7 +993,8 @@ public Set<Tuple> zUnionWithScores(byte[]... sets) {
988993 if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
989994
990995 try {
991- return JedisConverters .toTupleSet (connection .getCluster ().zunionWithScores (new ZParams (), sets ));
996+ return JedisConverters .toSet (JedisConverters .toTupleList (connection .getCluster ()
997+ .zunionWithScores (new ZParams (), sets )));
992998 } catch (Exception ex ) {
993999 throw convertJedisAccessException (ex );
9941000 }
@@ -1008,10 +1014,11 @@ public Set<Tuple> zUnionWithScores(Aggregate aggregate, Weights weights, byte[].
10081014 if (ClusterSlotHashUtil .isSameSlotForAllKeys (sets )) {
10091015
10101016 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 ) ));
10131019 } catch (Exception ex ) {
10141020 throw convertJedisAccessException (ex );
1021+
10151022 }
10161023 }
10171024
@@ -1126,21 +1133,14 @@ private static ZParams toZParams(Aggregate aggregate, Weights weights) {
11261133 return new ZParams ().weights (weights .toArray ()).aggregate (ZParams .Aggregate .valueOf (aggregate .name ()));
11271134 }
11281135
1129- /**
1130- * Workaround for broken Jedis BZPOP signature.
1131- *
1132- * @param bytes
1133- * @return
1134- */
11351136 @ 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 ) {
11381138
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 ;
11411142 }
11421143
1143- return new DefaultTuple (( byte []) bytes . get ( 1 ), Double . parseDouble ( new String (( byte []) bytes . get ( 2 )))) ;
1144+ return null ;
11441145 }
1145-
11461146}
0 commit comments