Skip to content

Commit

Permalink
Support CONFIG SET multiple params (#2949)
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed Mar 16, 2022
1 parent 436aa92 commit 44be77d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
14 changes: 14 additions & 0 deletions src/main/java/redis/clients/jedis/Jedis.java
Original file line number Diff line number Diff line change
Expand Up @@ -3639,6 +3639,13 @@ public String configSet(final byte[] parameter, final byte[] value) {
return connection.getStatusCodeReply();
}

@Override
public String configSet(final byte[]... parameterValues) {
checkIsInMultiOrPipeline();
connection.sendCommand(CONFIG, joinParameters(Keyword.SET.getRaw(), parameterValues));
return connection.getStatusCodeReply();
}

@Override
public long strlen(final byte[] key) {
checkIsInMultiOrPipeline();
Expand Down Expand Up @@ -7867,6 +7874,13 @@ public String configSet(final String parameter, final String value) {
return connection.getStatusCodeReply();
}

@Override
public String configSet(final String... parameterValues) {
checkIsInMultiOrPipeline();
connection.sendCommand(CONFIG, joinParameters(Keyword.SET.name(), parameterValues));
return connection.getStatusCodeReply();
}

public long publish(final String channel, final String message) {
checkIsInMultiOrPipeline();
connection.sendCommand(PUBLISH, channel, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public interface ConfigCommands {
*/
String configSet(String parameter, String value);

String configSet(String... parameterValues);

/**
* Used in order to reconfigure the Redis server at run time without
* the need to restart.
Expand All @@ -61,6 +63,8 @@ public interface ConfigCommands {
*/
String configSet(byte[] parameter, byte[] value);

String configSet(byte[]... parameterValues);

/**
* Resets the statistics reported by Redis using the INFO command.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static redis.clients.jedis.util.SafeEncoder.encode;

import java.util.HashSet;
import java.util.List;
Expand All @@ -27,7 +29,6 @@
import redis.clients.jedis.exceptions.JedisDataException;
import redis.clients.jedis.HostAndPorts;
import redis.clients.jedis.util.AssertUtil;
import redis.clients.jedis.util.SafeEncoder;

public class ControlCommandsTest extends JedisCommandsTestBase {

Expand Down Expand Up @@ -198,13 +199,12 @@ public void onCommand(String command) {
public void configGet() {
List<String> info = jedis.configGet("m*");
assertNotNull(info);
info = jedis.configGet("zset-max-ziplist-entries", "maxmemory");
assertNotNull(info);
assertEquals(4, info.size());
assertFalse(info.isEmpty());
assertTrue(info.size() % 2 == 0);
List<byte[]> infoBinary = jedis.configGet("m*".getBytes());
assertNotNull(infoBinary);
infoBinary = jedis.configGet("zset-max-ziplist-entries".getBytes(), "maxmemory".getBytes());
assertEquals(4, infoBinary.size());
assertFalse(infoBinary.isEmpty());
assertTrue(infoBinary.size() % 2 == 0);
}

@Test
Expand All @@ -217,15 +217,28 @@ public void configSet() {
}

@Test
public void configGetSetBinary() {
byte[] maxmemory = SafeEncoder.encode("maxmemory");
public void configSetBinary() {
byte[] maxmemory = encode("maxmemory");
List<byte[]> info = jedis.configGet(maxmemory);
assertArrayEquals(maxmemory, info.get(0));
byte[] memory = info.get(1);
assertEquals("OK", jedis.configSet(maxmemory, Protocol.toByteArray(200)));
assertEquals("OK", jedis.configSet(maxmemory, memory));
}

@Test
public void configGetSetMulti() {
String[] params = new String[]{"hash-max-listpack-entries", "set-max-intset-entries", "zset-max-listpack-entries"};
List<String> info = jedis.configGet(params);
assertEquals(6, info.size());
assertEquals("OK", jedis.configSet(info.toArray(new String[6])));

byte[][] bparams = new byte[][]{encode("hash-max-listpack-entries"), encode("set-max-intset-entries"), encode("zset-max-listpack-entries")};
List<byte[]> binfo = jedis.configGet(bparams);
assertEquals(6, binfo.size());
assertEquals("OK", jedis.configSet(binfo.toArray(new byte[6][])));
}

@Test
public void waitReplicas() {
assertEquals(1, jedis.waitReplicas(1, 100));
Expand Down

0 comments on commit 44be77d

Please sign in to comment.