Skip to content

Commit fab4dc7

Browse files
authored
Merge pull request #2025 from DvirDukhan/general_execute_command
General execute command
2 parents c9c118a + 8893040 commit fab4dc7

16 files changed

+21
-22
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
4343
protected Client client = null;
4444
protected Transaction transaction = null;
4545
protected Pipeline pipeline = null;
46+
private final byte[][] dummyArray = new byte[0][];
4647

4748
public BinaryJedis() {
4849
client = new Client();
@@ -4045,9 +4046,12 @@ public List<byte[]> xclaim(byte[] key, byte[] groupname, byte[] consumername,
40454046
return client.getBinaryMultiBulkReply();
40464047
}
40474048

4048-
@Override
40494049
public Object sendCommand(ProtocolCommand cmd, byte[]... args) {
40504050
client.sendCommand(cmd, args);
40514051
return client.getOne();
40524052
}
4053+
4054+
public Object sendCommand(ProtocolCommand cmd) {
4055+
return sendCommand(cmd, dummyArray);
4056+
}
40534057
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2203,7 +2203,6 @@ public Long execute(Jedis connection) {
22032203
}.runBinary(key);
22042204
}
22052205

2206-
@Override
22072206
public Object sendCommand(final byte[] sampleKey, final ProtocolCommand cmd, final byte[]... args) {
22082207
return new JedisClusterCommand<Object>(connectionHandler, maxAttempts) {
22092208
@Override

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo> implements
2020
BinaryJedisCommands {
21+
22+
private final byte[][] dummyArray = new byte[0][];
23+
2124
public BinaryShardedJedis(List<JedisShardInfo> shards) {
2225
super(shards);
2326
}
@@ -1036,12 +1039,14 @@ public List<byte[]> xclaim(byte[] key, byte[] groupname, byte[] consumername, lo
10361039
return j.xclaim(key, groupname, consumername, minIdleTime, newIdleTime, retries, force, ids);
10371040
}
10381041

1039-
@Override
10401042
public Object sendCommand(ProtocolCommand cmd, byte[]... args) {
10411043
// default since no sample key provided in JedisCommands interface
10421044
byte[] sampleKey = args.length > 0 ? args[0] : cmd.getRaw();
1043-
Jedis j = getShard(args[0]);
1045+
Jedis j = getShard(sampleKey);
10441046
return j.sendCommand(cmd, args);
10451047
}
10461048

1049+
public Object sendCommand(ProtocolCommand cmd) {
1050+
return sendCommand(cmd, dummyArray);
1051+
}
10471052
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3830,7 +3830,6 @@ public List<StreamEntry> xclaim(String key, String group, String consumername, l
38303830
return BuilderFactory.STREAM_ENTRY_LIST.build(client.getObjectMultiBulkReply());
38313831
}
38323832

3833-
@Override
38343833
public Object sendCommand(ProtocolCommand cmd, String... args) {
38353834
client.sendCommand(cmd, args);
38363835
return client.getOne();

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2235,7 +2235,6 @@ public Long execute(Jedis connection) {
22352235
}.run(key);
22362236
}
22372237

2238-
@Override
22392238
public Object sendCommand(final String sampleKey, final ProtocolCommand cmd, final String... args) {
22402239
return new JedisClusterCommand<Object>(connectionHandler, maxAttempts) {
22412240
@Override

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,14 +1963,12 @@ public Response<List<byte[]>> xclaim(byte[] key, byte[] group, byte[] consumerna
19631963
return getResponse(BuilderFactory.BYTE_ARRAY_LIST);
19641964
}
19651965

1966-
@Override
19671966
public Response<Object> sendCommand(ProtocolCommand cmd, String... args){
19681967
String key = args.length > 0 ? args[0] : cmd.toString();
19691968
getClient(key).sendCommand(cmd, args);
19701969
return getResponse(BuilderFactory.OBJECT);
19711970
}
19721971

1973-
@Override
19741972
public Response<Object> sendCommand(ProtocolCommand cmd, byte[]... args){
19751973
byte[] key = args.length > 0 ? args[0] : cmd.getRaw();
19761974
getClient(key).sendCommand(cmd, args);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,6 @@ public List<StreamEntry> xclaim(String key, String group, String consumername, l
10551055
return j.xclaim(key, group, consumername, minIdleTime, newIdleTime, retries, force, ids);
10561056
}
10571057

1058-
@Override
10591058
public Object sendCommand(ProtocolCommand cmd, String... args) {
10601059
// default since no sample key provided in JedisCommands interface
10611060
String sampleKey = args.length > 0 ? args[0] : cmd.toString();

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,4 @@ List<GeoRadiusResponse> georadiusByMemberReadonly(byte[] key, byte[] member, dou
350350
List<byte[]> xclaim(byte[] key, byte[] groupname, byte[] consumername, long minIdleTime, long newIdleTime, int retries, boolean force, byte[][] ids);
351351

352352
Long waitReplicas(byte[] key, final int replicas, final long timeout);
353-
354-
Object sendCommand(final byte[] sampleKey, ProtocolCommand cmd, byte[]... args);
355353
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,4 @@ List<GeoRadiusResponse> georadiusByMemberReadonly(byte[] key, byte[] member, dou
356356
List<byte[]> xpending(byte[] key, byte[] groupname, byte[] start, byte[] end, int count, byte[] consumername);
357357

358358
List<byte[]> xclaim(byte[] key, byte[] groupname, byte[] consumername, long minIdleTime, long newIdleTime, int retries, boolean force, byte[][] ids);
359-
360-
Object sendCommand(ProtocolCommand cmd, byte[]... args);
361359
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,4 @@ Response<List<byte[]>> xclaim(byte[] key, byte[] group, byte[] consumername, lon
353353
Response<String> psetex(byte[] key, long milliseconds, byte[] value);
354354

355355
Response<Double> hincrByFloat(byte[] key, byte[] field, double increment);
356-
357-
Response<Object> sendCommand(ProtocolCommand cmd, byte[]... args);
358356
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,4 @@ List<StreamEntry> xclaim( String key, String group, String consumername, long mi
482482
long newIdleTime, int retries, boolean force, StreamEntryID... ids);
483483

484484
Long waitReplicas(final String key, final int replicas, final long timeout);
485-
486-
Object sendCommand(final String sampleKey, ProtocolCommand cmd, String... args);
487485
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,4 @@ List<GeoRadiusResponse> georadiusByMemberReadonly(String key, String member, dou
480480
*/
481481
List<StreamEntry> xclaim( String key, String group, String consumername, long minIdleTime,
482482
long newIdleTime, int retries, boolean force, StreamEntryID... ids);
483-
484-
485-
Object sendCommand(ProtocolCommand cmd, String... args);
486483
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,4 @@ Response<Set<Tuple>> zrangeByScoreWithScores(String key, String min, String max,
353353
Response<String> psetex(String key, long milliseconds, String value);
354354

355355
Response<Double> hincrByFloat(String key, String field, double increment);
356-
357-
Response<Object> sendCommand(ProtocolCommand cmd, String... args);
358356
}

src/test/java/redis/clients/jedis/tests/ShardedJedisTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package redis.clients.jedis.tests;
22

3+
import static org.junit.Assert.assertArrayEquals;
34
import static org.junit.Assert.assertEquals;
45
import static org.junit.Assert.assertNotEquals;
56
import static org.junit.Assert.assertNotSame;
67
import static org.junit.Assert.assertSame;
78
import static org.junit.Assert.assertTrue;
89
import static org.junit.Assert.fail;
10+
import static redis.clients.jedis.Protocol.Command.PING;
911
import static redis.clients.jedis.Protocol.Command.SET;
1012

1113
import java.util.ArrayList;
@@ -21,6 +23,7 @@
2123
import redis.clients.jedis.ShardedJedis;
2224
import redis.clients.jedis.tests.utils.ClientKillerUtil;
2325
import redis.clients.jedis.util.Hashing;
26+
import redis.clients.jedis.util.SafeEncoder;
2427
import redis.clients.jedis.util.Sharded;
2528

2629
public class ShardedJedisTest {
@@ -351,6 +354,8 @@ public void testGeneralCommand(){
351354
assertEquals("bar1", j.get("b"));
352355
j.disconnect();
353356

357+
assertEquals("PONG", SafeEncoder.encode((byte[]) jedis.sendCommand(PING)));
358+
354359
}
355360

356361
}

src/test/java/redis/clients/jedis/tests/commands/AllKindOfValuesCommandsTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import static org.junit.Assert.fail;
1010
import static redis.clients.jedis.Protocol.Command.GET;
1111
import static redis.clients.jedis.Protocol.Command.LRANGE;
12+
import static redis.clients.jedis.Protocol.Command.PING;
1213
import static redis.clients.jedis.Protocol.Command.RPUSH;
1314
import static redis.clients.jedis.Protocol.Command.SET;
1415
import static redis.clients.jedis.ScanParams.SCAN_POINTER_START;
@@ -862,6 +863,8 @@ public void sendCommandTest(){
862863
expected.add("c".getBytes());
863864
for (int i = 0; i < 3; i++)
864865
assertArrayEquals(expected.get(i), list.get(i));
866+
867+
assertEquals("PONG", SafeEncoder.encode((byte[]) jedis.sendCommand(PING)));
865868
}
866869

867870
}

src/test/java/redis/clients/jedis/tests/commands/BinaryValuesCommandsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ public void strlen() {
288288
assertEquals(binaryValue.length, jedis.strlen(bfoo).intValue());
289289
}
290290

291+
@Test
291292
public void sendCommandTest(){
292293
Object obj = jedis.sendCommand(SET, "x".getBytes(), "1".getBytes());
293294
String returnValue = SafeEncoder.encode((byte[]) obj);

0 commit comments

Comments
 (0)