Feature - RedisNode.getMemoryStatistics() method added. #3329

pull/3332/head^2
Nikita Koksharov 4 years ago
parent 670c29dc4d
commit b738d12648

@ -29,6 +29,13 @@ import java.util.concurrent.TimeUnit;
*/
public interface RedisNode {
/**
* Returns Redis memory statistics
*
* @return statistics info map
*/
Map<String, String> getMemoryStatistics();
/**
* Returns current Redis server time in seconds
*

@ -29,6 +29,13 @@ import java.util.concurrent.TimeUnit;
*/
public interface RedisNodeAsync {
/**
* Returns Redis memory statistics
*
* @return statistics info map
*/
RFuture<Map<String, String>> getMemoryStatisticsAsync();
/**
* Returns current Redis server time in seconds
*
@ -57,7 +64,7 @@ public interface RedisNodeAsync {
* Returns information about Redis node.
*
* @param section - section of information
* @return information
* @return information map
*/
RFuture<Map<String, String>> infoAsync(RedisNode.InfoSection section);

@ -438,6 +438,7 @@ public interface RedisCommands {
RedisStrictCommand<Long> OBJECT_IDLETIME = new RedisStrictCommand<Long>("OBJECT", "IDLETIME", new LongReplayConvertor());
RedisStrictCommand<Long> MEMORY_USAGE = new RedisStrictCommand<Long>("MEMORY", "USAGE", new LongReplayConvertor());
RedisStrictCommand<Map<String, String>> MEMORY_STATS = new RedisStrictCommand<>("MEMORY", "STATS", new StringMapReplayDecoder());
RedisStrictCommand<Boolean> RENAMENX = new RedisStrictCommand<Boolean>("RENAMENX", new BooleanReplayConvertor());
RedisStrictCommand<Void> RENAME = new RedisStrictCommand<Void>("RENAME", new VoidReplayConvertor());
RedisStrictCommand<Boolean> MOVE = new RedisStrictCommand<Boolean>("MOVE", new BooleanReplayConvertor());

@ -0,0 +1,48 @@
/**
* Copyright (c) 2013-2020 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson.client.protocol.decoder;
import org.redisson.client.handler.State;
import org.redisson.client.protocol.Decoder;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author Nikita Koksharov
*
*/
public class StringMapReplayDecoder implements MultiDecoder<Map<String, String>> {
@Override
public Map<String, String> decode(List<Object> parts, State state) {
Map<String, String> result = new LinkedHashMap<>(parts.size()/2);
for (int i = 0; i < parts.size(); i++) {
if (i % 2 != 0) {
result.put(parts.get(i-1).toString(), parts.get(i).toString());
}
}
return result;
}
@Override
public Decoder<Object> getDecoder(int paramNum, State state) {
return null;
}
}

@ -221,6 +221,16 @@ public class RedisNode implements RedisClusterMaster, RedisClusterSlave, RedisMa
return commandExecutor.get(infoAsync(section));
}
@Override
public Map<String, String> getMemoryStatistics() {
return commandExecutor.get(getMemoryStatisticsAsync());
}
@Override
public RFuture<Map<String, String>> getMemoryStatisticsAsync() {
return commandExecutor.readAsync(client, StringCodec.INSTANCE, RedisCommands.MEMORY_STATS);
}
@Override
public RFuture<String> clusterIdAsync() {
return commandExecutor.readAsync(client, StringCodec.INSTANCE, RedisCommands.CLUSTER_MYID);

@ -60,6 +60,16 @@ public class SentinelRedisNode implements RedisSentinel, RedisSentinelAsync {
return client.getAddr();
}
@Override
public Map<String, String> getMemoryStatistics() {
return getMemoryStatisticsAsync().syncUninterruptibly().getNow();
}
@Override
public RFuture<Map<String, String>> getMemoryStatisticsAsync() {
return executeAsync(null, StringCodec.INSTANCE, -1, RedisCommands.MEMORY_STATS);
}
@Override
public RFuture<Boolean> pingAsync() {
return pingAsync(1, TimeUnit.SECONDS);

@ -73,6 +73,13 @@ public class RedissonRedisNodesTest extends BaseTest {
assertThat(keyspaceResponse).isEmpty();
}
@Test
public void testMemoryStatistics() {
RedisSingle nodes = redisson.getRedisNodes(RedisNodes.SINGLE);
Map<String, String> stats = nodes.getInstance().getMemoryStatistics();
assertThat(stats.get("keys.count")).isEqualTo("0");
}
@Test
public void testTime() {
RedisSingle nodes = redisson.getRedisNodes(RedisNodes.SINGLE);

Loading…
Cancel
Save