Skip to content

Commit 4316877

Browse files
authored
More RESP3 breaking and testing changes (#3399)
1 parent f517c05 commit 4316877

17 files changed

+61
-127
lines changed

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

+5-38
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
import java.util.*;
55
import java.util.stream.Collectors;
66

7-
import redis.clients.jedis.resps.StreamConsumerFullInfo;
8-
import redis.clients.jedis.resps.StreamFullInfo;
9-
import redis.clients.jedis.resps.StreamGroupFullInfo;
7+
import redis.clients.jedis.resps.*;
108
import redis.clients.jedis.resps.LCSMatchResult.MatchedPosition;
119
import redis.clients.jedis.resps.LCSMatchResult.Position;
12-
import redis.clients.jedis.resps.*;
1310
import redis.clients.jedis.util.DoublePrecision;
1411
import redis.clients.jedis.util.JedisByteHashMap;
1512
import redis.clients.jedis.util.KeyValue;
@@ -200,36 +197,6 @@ public String toString() {
200197
}
201198
};
202199

203-
// TODO: remove
204-
public static final Builder<byte[]> BYTE_ARRAY = new Builder<byte[]>() {
205-
@Override
206-
public byte[] build(Object data) {
207-
return ((byte[]) data);
208-
}
209-
210-
@Override
211-
public String toString() {
212-
return "byte[]";
213-
}
214-
};
215-
216-
// TODO: remove
217-
public static final Builder<List<byte[]>> BYTE_ARRAY_LIST = new Builder<List<byte[]>>() {
218-
@Override
219-
@SuppressWarnings("unchecked")
220-
public List<byte[]> build(Object data) {
221-
if (null == data) {
222-
return null;
223-
}
224-
return (List<byte[]>) data;
225-
}
226-
227-
@Override
228-
public String toString() {
229-
return "List<byte[]>";
230-
}
231-
};
232-
233200
public static final Builder<byte[]> BINARY = new Builder<byte[]>() {
234201
@Override
235202
public byte[] build(Object data) {
@@ -308,7 +275,7 @@ public Map<byte[], byte[]> build(Object data) {
308275

309276
@Override
310277
public String toString() {
311-
return "Map<String, String>";
278+
return "Map<byte[], byte[]>";
312279
}
313280
};
314281

@@ -977,7 +944,7 @@ private Map<String, Builder> createDecoderMap() {
977944
tempMappingFunctions.put(AccessControlLogEntry.CONTEXT, STRING);
978945
tempMappingFunctions.put(AccessControlLogEntry.OBJECT, STRING);
979946
tempMappingFunctions.put(AccessControlLogEntry.USERNAME, STRING);
980-
// tempMappingFunctions.put(AccessControlLogEntry.AGE_SECONDS, STRING);
947+
tempMappingFunctions.put(AccessControlLogEntry.AGE_SECONDS, DOUBLE);
981948
tempMappingFunctions.put(AccessControlLogEntry.CLIENT_INFO, STRING);
982949
tempMappingFunctions.put(AccessControlLogEntry.ENTRY_ID, LONG);
983950
tempMappingFunctions.put(AccessControlLogEntry.TIMESTAMP_CREATED, LONG);
@@ -1174,7 +1141,7 @@ public List<Map.Entry<String, List<StreamEntry>>> build(Object data) {
11741141
List<Object> stream = (List<Object>) streamObj;
11751142
String streamKey = STRING.build(stream.get(0));
11761143
List<StreamEntry> streamEntries = STREAM_ENTRY_LIST.build(stream.get(1));
1177-
result.add(new AbstractMap.SimpleEntry<>(streamKey, streamEntries));
1144+
result.add(KeyValue.of(streamKey, streamEntries));
11781145
}
11791146

11801147
return result;
@@ -1198,7 +1165,7 @@ public List<Map.Entry<String, List<StreamEntry>>> build(Object data) {
11981165
while (iter.hasNext()) {
11991166
String streamKey = STRING.build(iter.next());
12001167
List<StreamEntry> streamEntries = STREAM_ENTRY_LIST.build(iter.next());
1201-
result.add(new AbstractMap.SimpleEntry<>(streamKey, streamEntries));
1168+
result.add(KeyValue.of(streamKey, streamEntries));
12021169
}
12031170

12041171
return result;

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

+4-27
Original file line numberDiff line numberDiff line change
@@ -1482,39 +1482,16 @@ public final CommandObject<KeyedZSetElement> bzpopmin(double timeout, String...
14821482
BuilderFactory.KEYED_ZSET_ELEMENT);
14831483
}
14841484

1485-
public final CommandObject<List<byte[]>> bzpopmax(double timeout, byte[]... keys) {
1485+
public final CommandObject<List<Object>> bzpopmax(double timeout, byte[]... keys) {
14861486
return new CommandObject<>(commandArguments(BZPOPMAX).blocking().keys((Object[]) keys)
1487-
.add(timeout), getBZPopBuilder());
1487+
.add(timeout), BuilderFactory.RAW_OBJECT_LIST);
14881488
}
14891489

1490-
public final CommandObject<List<byte[]>> bzpopmin(double timeout, byte[]... keys) {
1490+
public final CommandObject<List<Object>> bzpopmin(double timeout, byte[]... keys) {
14911491
return new CommandObject<>(commandArguments(BZPOPMIN).blocking().keys((Object[]) keys)
1492-
.add(timeout), getBZPopBuilder());
1492+
.add(timeout), BuilderFactory.RAW_OBJECT_LIST);
14931493
}
14941494

1495-
private Builder<List<byte[]>> getBZPopBuilder() {
1496-
if (proto == RedisProtocol.RESP3) return DUMMY_BZPOP_BUILDER;
1497-
return BuilderFactory.BINARY_LIST;
1498-
}
1499-
1500-
// TODO: remove
1501-
private static final Builder<List<byte[]>> DUMMY_BZPOP_BUILDER = new Builder<List<byte[]>>() {
1502-
@Override
1503-
public List<byte[]> build(Object data) {
1504-
if (data == null) return null;
1505-
List<Object> input = (List<Object>) data;
1506-
List<byte[]> output = new ArrayList<>(input.size());
1507-
for (Object in : input) {
1508-
if (in instanceof Double) {
1509-
output.add(Protocol.toByteArray((Double) in));
1510-
} else {
1511-
output.add((byte[]) in);
1512-
}
1513-
}
1514-
return output;
1515-
}
1516-
};
1517-
15181495
public final CommandObject<Long> zcount(String key, double min, double max) {
15191496
return new CommandObject<>(commandArguments(ZCOUNT).key(key).add(min).add(max), BuilderFactory.LONG);
15201497
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2630,12 +2630,12 @@ public KeyValue<byte[], List<byte[]>> blmpop(long timeout, ListDirection directi
26302630
}
26312631

26322632
@Override
2633-
public List<byte[]> bzpopmax(final double timeout, final byte[]... keys) {
2633+
public List<Object> bzpopmax(final double timeout, final byte[]... keys) {
26342634
return connection.executeCommand(commandObjects.bzpopmax(timeout, keys));
26352635
}
26362636

26372637
@Override
2638-
public List<byte[]> bzpopmin(final double timeout, final byte[]... keys) {
2638+
public List<Object> bzpopmin(final double timeout, final byte[]... keys) {
26392639
return connection.executeCommand(commandObjects.bzpopmin(timeout, keys));
26402640
}
26412641

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2946,12 +2946,12 @@ public Response<ScanResult<Tuple>> zscan(byte[] key, byte[] cursor, ScanParams p
29462946
}
29472947

29482948
@Override
2949-
public Response<List<byte[]>> bzpopmax(double timeout, byte[]... keys) {
2949+
public Response<List<Object>> bzpopmax(double timeout, byte[]... keys) {
29502950
return appendCommand(commandObjects.bzpopmax(timeout, keys));
29512951
}
29522952

29532953
@Override
2954-
public Response<List<byte[]>> bzpopmin(double timeout, byte[]... keys) {
2954+
public Response<List<Object>> bzpopmin(double timeout, byte[]... keys) {
29552955
return appendCommand(commandObjects.bzpopmin(timeout, keys));
29562956
}
29572957

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2899,12 +2899,12 @@ public Response<ScanResult<Tuple>> zscan(byte[] key, byte[] cursor, ScanParams p
28992899
}
29002900

29012901
@Override
2902-
public Response<List<byte[]>> bzpopmax(double timeout, byte[]... keys) {
2902+
public Response<List<Object>> bzpopmax(double timeout, byte[]... keys) {
29032903
return appendCommand(commandObjects.bzpopmax(timeout, keys));
29042904
}
29052905

29062906
@Override
2907-
public Response<List<byte[]>> bzpopmin(double timeout, byte[]... keys) {
2907+
public Response<List<Object>> bzpopmin(double timeout, byte[]... keys) {
29082908
return appendCommand(commandObjects.bzpopmin(timeout, keys));
29092909
}
29102910

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
import redis.clients.jedis.util.IOUtils;
99

1010
/**
11+
* WARNING: RESP3 is not properly implemented for ShardedPipeline.
12+
*
1113
* @deprecated Sharding/Sharded feature will be removed in next major release.
1214
*/
1315
@Deprecated
14-
// TODO: RESP3
1516
public class ShardedPipeline extends MultiNodePipelineBase {
1617

1718
private final ShardedConnectionProvider provider;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2996,12 +2996,12 @@ public Response<ScanResult<Tuple>> zscan(byte[] key, byte[] cursor, ScanParams p
29962996
}
29972997

29982998
@Override
2999-
public Response<List<byte[]>> bzpopmax(double timeout, byte[]... keys) {
2999+
public Response<List<Object>> bzpopmax(double timeout, byte[]... keys) {
30003000
return appendCommand(commandObjects.bzpopmax(timeout, keys));
30013001
}
30023002

30033003
@Override
3004-
public Response<List<byte[]>> bzpopmin(double timeout, byte[]... keys) {
3004+
public Response<List<Object>> bzpopmin(double timeout, byte[]... keys) {
30053005
return appendCommand(commandObjects.bzpopmin(timeout, keys));
30063006
}
30073007

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2339,12 +2339,12 @@ public KeyedZSetElement bzpopmin(double timeout, String... keys) {
23392339
}
23402340

23412341
@Override
2342-
public List<byte[]> bzpopmax(double timeout, byte[]... keys) {
2342+
public List<Object> bzpopmax(double timeout, byte[]... keys) {
23432343
return executeCommand(commandObjects.bzpopmax(timeout, keys));
23442344
}
23452345

23462346
@Override
2347-
public List<byte[]> bzpopmin(double timeout, byte[]... keys) {
2347+
public List<Object> bzpopmin(double timeout, byte[]... keys) {
23482348
return executeCommand(commandObjects.bzpopmin(timeout, keys));
23492349
}
23502350

src/main/java/redis/clients/jedis/commands/SortedSetBinaryCommands.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ default ScanResult<Tuple> zscan(byte[] key, byte[] cursor) {
130130

131131
ScanResult<Tuple> zscan(byte[] key, byte[] cursor, ScanParams params);
132132

133-
List<byte[]> bzpopmax(double timeout, byte[]... keys);
133+
List<Object> bzpopmax(double timeout, byte[]... keys);
134134

135-
List<byte[]> bzpopmin(double timeout, byte[]... keys);
135+
List<Object> bzpopmin(double timeout, byte[]... keys);
136136

137137
Set<byte[]> zdiff(byte[]... keys);
138138

src/main/java/redis/clients/jedis/commands/SortedSetPipelineBinaryCommands.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ default Response<ScanResult<Tuple>> zscan(byte[] key, byte[] cursor) {
131131

132132
Response<ScanResult<Tuple>> zscan(byte[] key, byte[] cursor, ScanParams params);
133133

134-
Response<List<byte[]>> bzpopmax(double timeout, byte[]... keys);
134+
Response<List<Object>> bzpopmax(double timeout, byte[]... keys);
135135

136-
Response<List<byte[]>> bzpopmin(double timeout, byte[]... keys);
136+
Response<List<Object>> bzpopmin(double timeout, byte[]... keys);
137137

138138
Response<Set<byte[]>> zdiff(byte[]... keys);
139139

src/main/java/redis/clients/jedis/resps/AccessControlLogEntry.java

+6-29
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package redis.clients.jedis.resps;
22

33
import java.io.Serializable;
4-
import java.util.*;
5-
import redis.clients.jedis.util.DoublePrecision;
4+
import java.util.LinkedHashMap;
5+
import java.util.Map;
66

77
/**
88
* This class holds information about an Access Control Log entry (returned by ACL LOG command) They
@@ -25,13 +25,12 @@ public class AccessControlLogEntry implements Serializable {
2525
public static final String TIMESTAMP_CREATED = "timestamp-created";
2626
public static final String TIMESTAMP_LAST_UPDATED = "timestamp-last-updated";
2727

28-
private long count;
28+
private final long count;
2929
private final String reason;
3030
private final String context;
3131
private final String object;
3232
private final String username;
33-
private final String ageSeconds; // TODO: RESP3
34-
private final Double ageSecondsAsDouble;
33+
private final Double ageSeconds;
3534
private final Map<String, String> clientInfo;
3635
private final Map<String, Object> logEntry;
3736
private final long entryId;
@@ -44,25 +43,7 @@ public AccessControlLogEntry(Map<String, Object> map) {
4443
context = (String) map.get(CONTEXT);
4544
object = (String) map.get(OBJECT);
4645
username = (String) map.get(USERNAME);
47-
48-
Object ageSecondsObj = map.get(AGE_SECONDS);
49-
if (ageSecondsObj == null) {
50-
ageSeconds = null;
51-
ageSecondsAsDouble = null;
52-
} else if (ageSecondsObj instanceof Double) {
53-
ageSecondsAsDouble = (Double) ageSecondsObj;
54-
ageSeconds = ageSecondsAsDouble.toString();
55-
} else {
56-
ageSeconds = (String) ageSecondsObj;
57-
Double _ageSecondsDouble;
58-
try {
59-
_ageSecondsDouble = DoublePrecision.parseFloatingPointNumber(ageSeconds);
60-
} catch (NumberFormatException nfe) {
61-
_ageSecondsDouble = null;
62-
}
63-
ageSecondsAsDouble = _ageSecondsDouble;
64-
}
65-
46+
ageSeconds = (Double) map.get(AGE_SECONDS);
6647
clientInfo = getMapFromRawClientInfo((String) map.get(CLIENT_INFO));
6748
logEntry = map;
6849
entryId = (long) map.get(ENTRY_ID);
@@ -90,14 +71,10 @@ public String getUsername() {
9071
return username;
9172
}
9273

93-
public String getAgeSeconds() {
74+
public Double getAgeSeconds() {
9475
return ageSeconds;
9576
}
9677

97-
public Double getAgeSecondsDouble() {
98-
return ageSecondsAsDouble;
99-
}
100-
10178
public Map<String, String> getClientInfo() {
10279
return clientInfo;
10380
}

src/test/java/redis/clients/jedis/JedisTest.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,16 @@ public void connectWithConfig() {
6060
}
6161

6262
@Test
63-
public void connectWithConfigInterface() {
63+
public void connectWithEmptyConfigInterface() {
6464
try (Jedis jedis = new Jedis(hnp, new JedisClientConfig() {
6565
})) {
6666
jedis.auth("foobared");
6767
assertEquals("PONG", jedis.ping());
6868
}
69+
}
70+
71+
@Test
72+
public void connectWithConfigInterface() {
6973
try (Jedis jedis = new Jedis(hnp, new JedisClientConfig() {
7074
@Override
7175
public String getPassword() {
@@ -77,13 +81,21 @@ public String getPassword() {
7781
}
7882

7983
@Test
80-
public void resp3() {
84+
public void resp3Protocol() {
8185
try (Jedis jedis = new Jedis(hnp, DefaultJedisClientConfig.builder()
8286
.protocol(RedisProtocol.RESP3).user("default").password("foobared").build())) {
8387
assertEquals("PONG", jedis.ping());
8488
}
8589
}
8690

91+
@Test
92+
public void resp3Shortcut() {
93+
try (Jedis jedis = new Jedis(hnp, DefaultJedisClientConfig.builder().resp3()
94+
.user("default").password("foobared").build())) {
95+
assertEquals("PONG", jedis.ping());
96+
}
97+
}
98+
8799
@Test
88100
public void timeoutConnection() throws Exception {
89101
Jedis jedis = new Jedis("localhost", 6379, 15000);

src/test/java/redis/clients/jedis/commands/jedis/SortedSetCommandsTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1541,10 +1541,10 @@ public void bzpopmax() {
15411541
jedis.zadd(bfoo, 1d, ba);
15421542
jedis.zadd(bfoo, 10d, bb);
15431543
jedis.zadd(bbar, 0.1d, bc);
1544-
List<byte[]> actual = jedis.bzpopmax(0, bfoo, bbar);
1544+
List<Object> actual = jedis.bzpopmax(0, bfoo, bbar);
15451545
assertEquals(3, actual.size());
1546-
assertArrayEquals(bfoo, actual.get(0));
1547-
assertArrayEquals(bb, actual.get(1));
1546+
assertArrayEquals(bfoo, (byte[]) actual.get(0));
1547+
assertArrayEquals(bb, (byte[]) actual.get(1));
15481548
assertEquals(10d, BuilderFactory.DOUBLE.build(actual.get(2)), 1e-10);
15491549
}
15501550

@@ -1559,10 +1559,10 @@ public void bzpopmin() {
15591559
jedis.zadd(bfoo, 1d, ba);
15601560
jedis.zadd(bfoo, 10d, bb);
15611561
jedis.zadd(bbar, 0.1d, bc);
1562-
List<byte[]> actual = jedis.bzpopmin(0, bbar, bfoo);
1562+
List<Object> actual = jedis.bzpopmin(0, bbar, bfoo);
15631563
assertEquals(3, actual.size());
1564-
assertArrayEquals(bbar, actual.get(0));
1565-
assertArrayEquals(bc, actual.get(1));
1564+
assertArrayEquals(bbar, (byte[]) actual.get(0));
1565+
assertArrayEquals(bc, (byte[]) actual.get(1));
15661566
assertEquals(0.1d, BuilderFactory.DOUBLE.build(actual.get(2)), 1e-10);
15671567
}
15681568

0 commit comments

Comments
 (0)