Node.time method added. #457

pull/653/head
Nikita 9 years ago
parent 5723bbcef8
commit 4a7dd13825

@ -25,6 +25,13 @@ import java.net.InetSocketAddress;
*/
public interface Node {
/**
* Returns current Redis server time in seconds
*
* @return
*/
long time();
/**
* Returns node type
*

@ -41,9 +41,11 @@ import org.redisson.client.protocol.convertor.VoidReplayConvertor;
import org.redisson.client.protocol.decoder.ClusterNodesDecoder;
import org.redisson.client.protocol.decoder.FlatNestedMultiDecoder;
import org.redisson.client.protocol.decoder.KeyValueObjectDecoder;
import org.redisson.client.protocol.decoder.ListMultiDecoder;
import org.redisson.client.protocol.decoder.ListResultReplayDecoder;
import org.redisson.client.protocol.decoder.ListScanResult;
import org.redisson.client.protocol.decoder.ListScanResultReplayDecoder;
import org.redisson.client.protocol.decoder.LongMultiDecoder;
import org.redisson.client.protocol.decoder.MapScanResult;
import org.redisson.client.protocol.decoder.MapScanResultReplayDecoder;
import org.redisson.client.protocol.decoder.NestedMultiDecoder;
@ -272,6 +274,7 @@ public interface RedisCommands {
RedisCommand<Object> PUNSUBSCRIBE = new RedisCommand<Object>("PUNSUBSCRIBE", new PubSubStatusDecoder());
RedisStrictCommand<List<ClusterNodeInfo>> CLUSTER_NODES = new RedisStrictCommand<List<ClusterNodeInfo>>("CLUSTER", "NODES", new ClusterNodesDecoder());
RedisStrictCommand<List<String>> TIME = new RedisStrictCommand<List<String>>("TIME", new StringListReplayDecoder());
RedisStrictCommand<Map<String, String>> CLUSTER_INFO = new RedisStrictCommand<Map<String, String>>("CLUSTER", "INFO", new StringMapDataDecoder());
RedisStrictCommand<List<String>> SENTINEL_GET_MASTER_ADDR_BY_NAME = new RedisStrictCommand<List<String>>("SENTINEL", "GET-MASTER-ADDR-BY-NAME", new StringListReplayDecoder());

@ -16,12 +16,15 @@
package org.redisson.connection;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.Map;
import org.redisson.api.ClusterNode;
import org.redisson.api.NodeType;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.RedisException;
import org.redisson.client.codec.LongCodec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.misc.RPromise;
@ -100,6 +103,21 @@ public class RedisClientEntry implements ClusterNode {
return true;
}
public long time() {
RedisConnection c = null;
try {
c = connect();
List<String> parts = c.sync(RedisCommands.TIME);
return Long.valueOf(parts.get(0));
} catch (Exception e) {
throw new RedisException(e.getMessage(), e);
} finally {
if (c != null) {
c.closeAsync();
}
}
}
@Override
public Map<String, String> info() {
RedisConnection c = null;

@ -226,8 +226,18 @@ public class RedissonTest {
Assert.assertTrue(r.isShutdown());
}
// @Test
public void test() {
@Test
public void testTime() {
NodesGroup<Node> nodes = redisson.getNodesGroup();
Assert.assertEquals(1, nodes.getNodes().size());
Iterator<Node> iter = nodes.getNodes().iterator();
Node node1 = iter.next();
assertThat(node1.time()).isGreaterThan(100000L);
}
@Test
public void testPing() {
NodesGroup<Node> nodes = redisson.getNodesGroup();
Assert.assertEquals(1, nodes.getNodes().size());
Iterator<Node> iter = nodes.getNodes().iterator();

Loading…
Cancel
Save