Skip to content

Commit c0c2ce2

Browse files
authored
Return List instead of Set in ZDIFF, ZINTER, ZUNION (#3431)
* Reformat sorted set methods - zdiff, zinter, zunion methods now return List instead of Set - ...store methods are renamed to ...Store - ...card methods are renamed to ...Card * fix javadoc * fix zunion test * breaking change list * Undo method renames * undo javadoc changes * fix
1 parent 7943bfb commit c0c2ce2

15 files changed

+173
-175
lines changed

docs/jedis5-breaking.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
- `blpop(double timeout, byte[]... keys)`
1515
- `brpop(double timeout, byte[]... keys)`
1616

17+
- `zdiff(String... keys)` method now returns `List<String>` (instead of `Set<String>`).
18+
- `zdiff(byte[]... keys)` method now returns `List<byte[]>` (instead of `Set<byte[]>`).
19+
- Both `zdiffWithScores(String... keys)` and `zdiffWithScores(byte[]... keys)` methods now return `List<Tuple>` (instead of `Set<Tuple>`).
20+
21+
- `zinter(ZParams params, String... keys)` method now returns `List<String>` (instead of `Set<String>`).
22+
- `zinter(ZParams params, byte[]... keys)` method now returns `List<byte[]>` (instead of `Set<byte[]>`).
23+
- Both `zinterWithScores(ZParams params, String... keys)` and `zinterWithScores(ZParams params, byte[]... keys)` methods now return `List<Tuple>` (instead of `Set<Tuple>`).
24+
25+
- `zunion(ZParams params, String... keys)` method now returns `List<String>` (instead of `Set<String>`).
26+
- `zunion(ZParams params, byte[]... keys)` method now returns `List<byte[]>` (instead of `Set<byte[]>`).
27+
- Both `zunionWithScores(ZParams params, String... keys)` and `zunionWithScores(ZParams params, byte[]... keys)` methods now return `List<Tuple>` (instead of `Set<Tuple>`).
28+
1729
- `getAgeSeconds()` in `AccessControlLogEntry` now returns `Double` instead of `String`.
1830

1931
- `graphSlowlog(String graphName)` now returns `List<List<Object>>` (instead of `List<List<String>>`).
@@ -30,6 +42,7 @@
3042
- `BYTE_ARRAY` (use `BINARY`)
3143
- `BYTE_ARRAY_LIST` (use `BINARY_LIST`)
3244
- `BINARY_MAP_FROM_PAIRS`
45+
- `STRING_ORDERED_SET`
3346

3447
- `Queable` class is removed.
3548

src/main/java/redis/clients/jedis/BuilderFactory.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -323,21 +323,6 @@ public String toString() {
323323
}
324324
};
325325

326-
public static final Builder<Set<String>> STRING_ORDERED_SET = new Builder<Set<String>>() {
327-
@Override
328-
@SuppressWarnings("unchecked")
329-
public Set<String> build(Object data) {
330-
if (null == data) return null;
331-
return ((List<Object>) data).stream().map(STRING::build)
332-
.collect(Collectors.toCollection(LinkedHashSet::new));
333-
}
334-
335-
@Override
336-
public String toString() {
337-
return "Set<String>";
338-
}
339-
};
340-
341326
public static final Builder<Map<String, String>> STRING_MAP = new Builder<Map<String, String>>() {
342327
@Override
343328
@SuppressWarnings("unchecked")

src/main/java/redis/clients/jedis/CommandObjects.java

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,51 +1804,53 @@ public final CommandObject<ScanResult<Tuple>> zscan(byte[] key, byte[] cursor, S
18041804
return new CommandObject<>(commandArguments(ZSCAN).key(key).add(cursor).addParams(params), BuilderFactory.ZSCAN_RESPONSE);
18051805
}
18061806

1807-
public final CommandObject<Set<String>> zdiff(String... keys) {
1808-
return new CommandObject<>(commandArguments(ZDIFF).add(keys.length).keys((Object[]) keys), BuilderFactory.STRING_ORDERED_SET);
1807+
public final CommandObject<List<String>> zdiff(String... keys) {
1808+
return new CommandObject<>(commandArguments(ZDIFF).add(keys.length).keys((Object[]) keys),
1809+
BuilderFactory.STRING_LIST);
18091810
}
18101811

1811-
public final CommandObject<Set<Tuple>> zdiffWithScores(String... keys) {
1812+
public final CommandObject<List<Tuple>> zdiffWithScores(String... keys) {
18121813
return new CommandObject<>(commandArguments(ZDIFF).add(keys.length).keys((Object[]) keys)
1813-
.add(WITHSCORES), getTupleSetBuilder());
1814+
.add(WITHSCORES), getTupleListBuilder());
18141815
}
18151816

18161817
public final CommandObject<Long> zdiffStore(String dstkey, String... keys) {
1817-
return new CommandObject<>(commandArguments(ZDIFFSTORE).key(dstkey).add(keys.length).keys((Object[]) keys), BuilderFactory.LONG);
1818+
return new CommandObject<>(commandArguments(ZDIFFSTORE).key(dstkey)
1819+
.add(keys.length).keys((Object[]) keys), BuilderFactory.LONG);
18181820
}
18191821

1820-
public final CommandObject<Set<byte[]>> zdiff(byte[]... keys) {
1821-
return new CommandObject<>(commandArguments(ZDIFF).add(keys.length).keys((Object[]) keys), BuilderFactory.BINARY_SET);
1822+
public final CommandObject<List<byte[]>> zdiff(byte[]... keys) {
1823+
return new CommandObject<>(commandArguments(ZDIFF).add(keys.length).keys((Object[]) keys), BuilderFactory.BINARY_LIST);
18221824
}
18231825

1824-
public final CommandObject<Set<Tuple>> zdiffWithScores(byte[]... keys) {
1826+
public final CommandObject<List<Tuple>> zdiffWithScores(byte[]... keys) {
18251827
return new CommandObject<>(commandArguments(ZDIFF).add(keys.length).keys((Object[]) keys)
1826-
.add(WITHSCORES), getTupleSetBuilder());
1828+
.add(WITHSCORES), getTupleListBuilder());
18271829
}
18281830

18291831
public final CommandObject<Long> zdiffStore(byte[] dstkey, byte[]... keys) {
18301832
return new CommandObject<>(commandArguments(ZDIFFSTORE).key(dstkey)
18311833
.add(keys.length).keys((Object[]) keys), BuilderFactory.LONG);
18321834
}
18331835

1834-
public final CommandObject<Long> zinterstore(String dstkey, String... sets) {
1835-
return new CommandObject<>(commandArguments(ZINTERSTORE).key(dstkey)
1836-
.add(sets.length).keys((Object[]) sets), BuilderFactory.LONG);
1836+
public final CommandObject<List<String>> zinter(ZParams params, String... keys) {
1837+
return new CommandObject<>(commandArguments(ZINTER).add(keys.length).keys((Object[]) keys)
1838+
.addParams(params), BuilderFactory.STRING_LIST);
18371839
}
18381840

1839-
public final CommandObject<Long> zinterstore(String dstkey, ZParams params, String... sets) {
1840-
return new CommandObject<>(commandArguments(ZINTERSTORE).key(dstkey)
1841-
.add(sets.length).keys((Object[]) sets).addParams(params), BuilderFactory.LONG);
1841+
public final CommandObject<List<Tuple>> zinterWithScores(ZParams params, String... keys) {
1842+
return new CommandObject<>(commandArguments(ZINTER).add(keys.length).keys((Object[]) keys)
1843+
.addParams(params).add(WITHSCORES), getTupleListBuilder());
18421844
}
18431845

1844-
public final CommandObject<Set<String>> zinter(ZParams params, String... keys) {
1845-
return new CommandObject<>(commandArguments(ZINTER).add(keys.length).keys((Object[]) keys)
1846-
.addParams(params), BuilderFactory.STRING_ORDERED_SET);
1846+
public final CommandObject<Long> zinterstore(String dstkey, String... keys) {
1847+
return new CommandObject<>(commandArguments(ZINTERSTORE).key(dstkey)
1848+
.add(keys.length).keys((Object[]) keys), BuilderFactory.LONG);
18471849
}
18481850

1849-
public final CommandObject<Set<Tuple>> zinterWithScores(ZParams params, String... keys) {
1850-
return new CommandObject<>(commandArguments(ZINTER).add(keys.length).keys((Object[]) keys)
1851-
.addParams(params).add(WITHSCORES), getTupleSetBuilder());
1851+
public final CommandObject<Long> zinterstore(String dstkey, ZParams params, String... keys) {
1852+
return new CommandObject<>(commandArguments(ZINTERSTORE).key(dstkey)
1853+
.add(keys.length).keys((Object[]) keys).addParams(params), BuilderFactory.LONG);
18521854
}
18531855

18541856
public final CommandObject<Long> zintercard(String... keys) {
@@ -1881,14 +1883,14 @@ public final CommandObject<Long> zintercard(long limit, byte[]... keys) {
18811883
.keys((Object[]) keys).add(LIMIT).add(limit), BuilderFactory.LONG);
18821884
}
18831885

1884-
public final CommandObject<Set<byte[]>> zinter(ZParams params, byte[]... keys) {
1886+
public final CommandObject<List<byte[]>> zinter(ZParams params, byte[]... keys) {
18851887
return new CommandObject<>(commandArguments(ZINTER).add(keys.length).keys((Object[]) keys)
1886-
.addParams(params), BuilderFactory.BINARY_SET);
1888+
.addParams(params), BuilderFactory.BINARY_LIST);
18871889
}
18881890

1889-
public final CommandObject<Set<Tuple>> zinterWithScores(ZParams params, byte[]... keys) {
1891+
public final CommandObject<List<Tuple>> zinterWithScores(ZParams params, byte[]... keys) {
18901892
return new CommandObject<>(commandArguments(ZINTER).add(keys.length).keys((Object[]) keys)
1891-
.addParams(params).add(WITHSCORES), getTupleSetBuilder());
1893+
.addParams(params).add(WITHSCORES), getTupleListBuilder());
18921894
}
18931895

18941896
public final CommandObject<Long> zunionstore(String dstkey, String... sets) {
@@ -1901,14 +1903,14 @@ public final CommandObject<Long> zunionstore(String dstkey, ZParams params, Stri
19011903
.add(sets.length).keys((Object[]) sets).addParams(params), BuilderFactory.LONG);
19021904
}
19031905

1904-
public final CommandObject<Set<String>> zunion(ZParams params, String... keys) {
1906+
public final CommandObject<List<String>> zunion(ZParams params, String... keys) {
19051907
return new CommandObject<>(commandArguments(ZUNION).add(keys.length).keys((Object[]) keys)
1906-
.addParams(params), BuilderFactory.STRING_ORDERED_SET);
1908+
.addParams(params), BuilderFactory.STRING_LIST);
19071909
}
19081910

1909-
public final CommandObject<Set<Tuple>> zunionWithScores(ZParams params, String... keys) {
1911+
public final CommandObject<List<Tuple>> zunionWithScores(ZParams params, String... keys) {
19101912
return new CommandObject<>(commandArguments(ZUNION).add(keys.length).keys((Object[]) keys)
1911-
.addParams(params).add(WITHSCORES), getTupleSetBuilder());
1913+
.addParams(params).add(WITHSCORES), getTupleListBuilder());
19121914
}
19131915

19141916
public final CommandObject<Long> zunionstore(byte[] dstkey, byte[]... sets) {
@@ -1921,14 +1923,14 @@ public final CommandObject<Long> zunionstore(byte[] dstkey, ZParams params, byte
19211923
.add(sets.length).keys((Object[]) sets).addParams(params), BuilderFactory.LONG);
19221924
}
19231925

1924-
public final CommandObject<Set<byte[]>> zunion(ZParams params, byte[]... keys) {
1926+
public final CommandObject<List<byte[]>> zunion(ZParams params, byte[]... keys) {
19251927
return new CommandObject<>(commandArguments(ZUNION).add(keys.length).keys((Object[]) keys)
1926-
.addParams(params), BuilderFactory.BINARY_SET);
1928+
.addParams(params), BuilderFactory.BINARY_LIST);
19271929
}
19281930

1929-
public final CommandObject<Set<Tuple>> zunionWithScores(ZParams params, byte[]... keys) {
1931+
public final CommandObject<List<Tuple>> zunionWithScores(ZParams params, byte[]... keys) {
19301932
return new CommandObject<>(commandArguments(ZUNION).add(keys.length).keys((Object[]) keys)
1931-
.addParams(params).add(WITHSCORES), getTupleSetBuilder());
1933+
.addParams(params).add(WITHSCORES), getTupleListBuilder());
19321934
}
19331935

19341936
public final CommandObject<KeyValue<String, List<Tuple>>> zmpop(SortedSetOption option, String... keys) {

src/main/java/redis/clients/jedis/Jedis.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,13 +2688,13 @@ public long zcount(final byte[] key, final byte[] min, final byte[] max) {
26882688
}
26892689

26902690
@Override
2691-
public Set<byte[]> zdiff(final byte[]... keys) {
2691+
public List<byte[]> zdiff(final byte[]... keys) {
26922692
checkIsInMultiOrPipeline();
26932693
return connection.executeCommand(commandObjects.zdiff(keys));
26942694
}
26952695

26962696
@Override
2697-
public Set<Tuple> zdiffWithScores(final byte[]... keys) {
2697+
public List<Tuple> zdiffWithScores(final byte[]... keys) {
26982698
checkIsInMultiOrPipeline();
26992699
return connection.executeCommand(commandObjects.zdiffWithScores(keys));
27002700
}
@@ -3048,26 +3048,26 @@ public long zremrangeByScore(final byte[] key, final byte[] min, final byte[] ma
30483048

30493049
/**
30503050
* Add multiple sorted sets, This command is similar to ZUNIONSTORE, but instead of storing the
3051-
resulting sorted set, it is returned to the connection.
3051+
* resulting sorted set, it is returned to the connection.
30523052
* @param params
30533053
* @param keys
30543054
* @return The result of the union
30553055
*/
30563056
@Override
3057-
public Set<byte[]> zunion(final ZParams params, final byte[]... keys) {
3057+
public List<byte[]> zunion(final ZParams params, final byte[]... keys) {
30583058
checkIsInMultiOrPipeline();
30593059
return connection.executeCommand(commandObjects.zunion(params, keys));
30603060
}
30613061

30623062
/**
3063-
* Add multiple sorted sets with scores, This command is similar to ZUNIONSTORE, but instead of storing the
3064-
* resulting sorted set, it is returned to the connection.
3063+
* Add multiple sorted sets with scores, This command is similar to ZUNIONSTORE, but instead of
3064+
* storing the resulting sorted set, it is returned to the connection.
30653065
* @param params
30663066
* @param keys
30673067
* @return The result of the union with their scores
30683068
*/
30693069
@Override
3070-
public Set<Tuple> zunionWithScores(final ZParams params, final byte[]... keys) {
3070+
public List<Tuple> zunionWithScores(final ZParams params, final byte[]... keys) {
30713071
checkIsInMultiOrPipeline();
30723072
return connection.executeCommand(commandObjects.zunionWithScores(params, keys));
30733073
}
@@ -3144,7 +3144,7 @@ public long zunionstore(final byte[] dstkey, final ZParams params, final byte[].
31443144
* @return The result of the intersection
31453145
*/
31463146
@Override
3147-
public Set<byte[]> zinter(final ZParams params, final byte[]... keys) {
3147+
public List<byte[]> zinter(final ZParams params, final byte[]... keys) {
31483148
checkIsInMultiOrPipeline();
31493149
return connection.executeCommand(commandObjects.zinter(params, keys));
31503150
}
@@ -3157,7 +3157,7 @@ public Set<byte[]> zinter(final ZParams params, final byte[]... keys) {
31573157
* @return The result of the intersection with scores
31583158
*/
31593159
@Override
3160-
public Set<Tuple> zinterWithScores(final ZParams params, final byte[]... keys) {
3160+
public List<Tuple> zinterWithScores(final ZParams params, final byte[]... keys) {
31613161
checkIsInMultiOrPipeline();
31623162
return connection.executeCommand(commandObjects.zinterWithScores(params, keys));
31633163
}
@@ -6248,7 +6248,7 @@ public long sinterstore(final String dstkey, final String... keys) {
62486248
}
62496249

62506250
/**
6251-
* This command works exactly like {@link Jedis#sinter(String[]) SINTER} but instead of returning
6251+
* This command works exactly like {@link Jedis#sinter(String...) SINTER} but instead of returning
62526252
* the result set, it returns just the cardinality of the result.
62536253
* <p>
62546254
* Time complexity O(N*M) worst case where N is the cardinality of the smallest
@@ -6262,7 +6262,7 @@ public long sintercard(String... keys) {
62626262
}
62636263

62646264
/**
6265-
* This command works exactly like {@link Jedis#sinter(String[]) SINTER} but instead of returning
6265+
* This command works exactly like {@link Jedis#sinter(String...) SINTER} but instead of returning
62666266
* the result set, it returns just the cardinality of the result.
62676267
* <p>
62686268
* Time complexity O(N*M) worst case where N is the cardinality of the smallest
@@ -6434,13 +6434,13 @@ public Double zaddIncr(final String key, final double score, final String member
64346434
}
64356435

64366436
@Override
6437-
public Set<String> zdiff(String... keys) {
6437+
public List<String> zdiff(String... keys) {
64386438
checkIsInMultiOrPipeline();
64396439
return connection.executeCommand(commandObjects.zdiff(keys));
64406440
}
64416441

64426442
@Override
6443-
public Set<Tuple> zdiffWithScores(String... keys) {
6443+
public List<Tuple> zdiffWithScores(String... keys) {
64446444
checkIsInMultiOrPipeline();
64456445
return connection.executeCommand(commandObjects.zdiffWithScores(keys));
64466446
}
@@ -7426,7 +7426,7 @@ public long zremrangeByScore(final String key, final String min, final String ma
74267426
* @return A set with members of the resulting set
74277427
*/
74287428
@Override
7429-
public Set<String> zunion(ZParams params, String... keys) {
7429+
public List<String> zunion(ZParams params, String... keys) {
74307430
checkIsInMultiOrPipeline();
74317431
return connection.executeCommand(commandObjects.zunion(params, keys));
74327432
}
@@ -7439,7 +7439,7 @@ public Set<String> zunion(ZParams params, String... keys) {
74397439
* @return A set with members of the resulting set with scores
74407440
*/
74417441
@Override
7442-
public Set<Tuple> zunionWithScores(ZParams params, String... keys) {
7442+
public List<Tuple> zunionWithScores(ZParams params, String... keys) {
74437443
checkIsInMultiOrPipeline();
74447444
return connection.executeCommand(commandObjects.zunionWithScores(params, keys));
74457445
}
@@ -7525,7 +7525,7 @@ public long zunionstore(final String dstkey, final ZParams params, final String.
75257525
* @return A set with members of the resulting set
75267526
*/
75277527
@Override
7528-
public Set<String> zinter(final ZParams params, final String... keys) {
7528+
public List<String> zinter(final ZParams params, final String... keys) {
75297529
checkIsInMultiOrPipeline();
75307530
return connection.executeCommand(commandObjects.zinter(params, keys));
75317531
}
@@ -7538,7 +7538,7 @@ public Set<String> zinter(final ZParams params, final String... keys) {
75387538
* @return A set with members of the resulting set with scores
75397539
*/
75407540
@Override
7541-
public Set<Tuple> zinterWithScores(final ZParams params, final String... keys) {
7541+
public List<Tuple> zinterWithScores(final ZParams params, final String... keys) {
75427542
checkIsInMultiOrPipeline();
75437543
return connection.executeCommand(commandObjects.zinterWithScores(params, keys));
75447544
}

0 commit comments

Comments
 (0)