Feature - getConfig, setConfig methods added to RedisNode interface. #2843

pull/2853/head
Nikita Koksharov 5 years ago
parent b13a7b5d9f
commit e53b53640b

@ -62,6 +62,28 @@ public interface RedisNode {
enum InfoSection {ALL, DEFAULT, SERVER, CLIENTS, MEMORY, PERSISTENCE, STATS, REPLICATION, CPU, COMMANDSTATS, CLUSTER, KEYSPACE}
/**
* Returns information about Redis node.
*
* @param section - section of information
* @return information
*/
Map<String, String> info(RedisNode.InfoSection section);
/**
* Get value of Redis configuration parameter.
*
* @param parameter - name of parameter
* @return value of parameter
*/
Map<String, String> getConfig(String parameter);
/**
* Set value of Redis configuration parameter.
*
* @param parameter - name of parameter
* @param value - value of parameter
*/
void setConfig(String parameter, String value);
}

@ -53,6 +53,29 @@ public interface RedisNodeAsync {
*/
RFuture<Boolean> pingAsync(long timeout, TimeUnit timeUnit);
/**
* Returns information about Redis node.
*
* @param section - section of information
* @return information
*/
RFuture<Map<String, String>> infoAsync(RedisNode.InfoSection section);
/**
* Get value of Redis configuration parameter.
*
* @param parameter - name of parameter
* @return value of parameter
*/
RFuture<Map<String, String>> getConfigAsync(String parameter);
/**
* Set value of Redis configuration parameter.
*
* @param parameter - name of parameter
* @param value - value of parameter
* @return void
*/
RFuture<Void> setConfigAsync(String parameter, String value);
}

@ -439,6 +439,7 @@ public interface RedisCommands {
RedisStrictCommand<Void> CLUSTER_MEET = new RedisStrictCommand<Void>("CLUSTER", "MEET");
RedisStrictCommand<List<String>> CONFIG_GET = new RedisStrictCommand<List<String>>("CONFIG", "GET", new StringListReplayDecoder());
RedisStrictCommand<Map<String, String>> CONFIG_GET_MAP = new RedisStrictCommand<>("CONFIG", "GET", new ObjectMapReplayDecoder());
RedisStrictCommand<Void> CONFIG_SET = new RedisStrictCommand<Void>("CONFIG", "SET", new VoidReplayConvertor());
RedisStrictCommand<Void> CONFIG_RESETSTAT = new RedisStrictCommand<Void>("CONFIG", "RESETSTAT", new VoidReplayConvertor());
RedisStrictCommand<List<String>> CLIENT_LIST = new RedisStrictCommand<List<String>>("CLIENT", "LIST", new StringToListConvertor());

@ -27,14 +27,14 @@ import org.redisson.client.protocol.Decoder;
* @author Nikita Koksharov
*
*/
public class ObjectMapReplayDecoder implements MultiDecoder<Map<Object, Object>> {
public class ObjectMapReplayDecoder<K, V> implements MultiDecoder<Map<K, V>> {
@Override
public Map<Object, Object> decode(List<Object> parts, State state) {
Map<Object, Object> result = new LinkedHashMap<Object, Object>(parts.size()/2);
public Map<K, V> decode(List<Object> parts, State state) {
Map<K, V> result = new LinkedHashMap<>(parts.size()/2);
for (int i = 0; i < parts.size(); i++) {
if (i % 2 != 0) {
result.put(parts.get(i-1), parts.get(i));
result.put((K) parts.get(i-1), (V) parts.get(i));
}
}
return result;

@ -28,7 +28,7 @@ import org.redisson.client.protocol.Decoder;
* @author Nikita Koksharov
*
*/
public class StreamObjectMapReplayDecoder extends ObjectMapReplayDecoder {
public class StreamObjectMapReplayDecoder extends ObjectMapReplayDecoder<Object, Object> {
private Decoder<Object> codec;

@ -317,4 +317,24 @@ public class RedisNode implements RedisClusterMaster, RedisClusterSlave, RedisMa
throw new IllegalStateException();
}
@Override
public Map<String, String> getConfig(String parameter) {
return commandExecutor.get(getConfigAsync(parameter));
}
@Override
public void setConfig(String parameter, String value) {
commandExecutor.get(setConfigAsync(parameter, value));
}
@Override
public RFuture<Map<String, String>> getConfigAsync(String parameter) {
return commandExecutor.readAsync(client, StringCodec.INSTANCE, RedisCommands.CONFIG_GET_MAP, parameter);
}
@Override
public RFuture<Void> setConfigAsync(String parameter, String value) {
return commandExecutor.writeAsync(client, StringCodec.INSTANCE, RedisCommands.CONFIG_SET, parameter, value);
}
}

@ -247,4 +247,25 @@ public class SentinelRedisNode implements RedisSentinel, RedisSentinelAsync {
public RFuture<Void> failoverAsync(String masterName) {
return executeAsync(null, null, -1, RedisCommands.SENTINEL_FAILOVER, masterName);
}
@Override
public Map<String, String> getConfig(String parameter) {
return getConfigAsync(parameter).syncUninterruptibly().getNow();
}
@Override
public void setConfig(String parameter, String value) {
setConfigAsync(parameter, value).syncUninterruptibly().getNow();
}
@Override
public RFuture<Map<String, String>> getConfigAsync(String parameter) {
return executeAsync(null, StringCodec.INSTANCE, -1, RedisCommands.CONFIG_GET_MAP, parameter);
}
@Override
public RFuture<Void> setConfigAsync(String parameter, String value) {
return executeAsync(null, StringCodec.INSTANCE, -1, RedisCommands.CONFIG_SET, parameter, value);
}
}

@ -83,6 +83,14 @@ public class RedissonRedisNodesTest extends BaseTest {
assertThat(time.getMicroseconds()).isGreaterThan(10000);
}
@Test
public void testConfig() {
RedisSingle nodes = redisson.getRedisNodes(RedisNodes.SINGLE);
assertThat(nodes.getInstance().getConfig("appendonly").get("appendonly")).isEqualTo("no");
nodes.getInstance().setConfig("appendonly", "yes");
assertThat(nodes.getInstance().getConfig("appendonly").get("appendonly")).isEqualTo("yes");
}
@Test
public void testSentinelFailover() throws IOException, InterruptedException {
RedisRunner.RedisProcess master = new RedisRunner()

Loading…
Cancel
Save