From 103d0f6fd4adf8a33b5d2b7b47efd033067fe52e Mon Sep 17 00:00:00 2001 From: Rui Gu Date: Wed, 6 Apr 2016 23:41:08 +0100 Subject: [PATCH] added server info command to RedisClient --- .../java/org/redisson/client/RedisClient.java | 43 +++++++++++++++++-- .../client/protocol/RedisCommands.java | 1 + 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/redisson/client/RedisClient.java b/src/main/java/org/redisson/client/RedisClient.java index 2aa64575591..723d146af5a 100644 --- a/src/main/java/org/redisson/client/RedisClient.java +++ b/src/main/java/org/redisson/client/RedisClient.java @@ -37,9 +37,13 @@ import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.GlobalEventExecutor; import io.netty.util.concurrent.ImmediateEventExecutor; import io.netty.util.concurrent.Promise; +import java.util.Map; +import java.util.concurrent.ExecutionException; +import org.redisson.client.protocol.RedisCommands; public class RedisClient { @@ -62,10 +66,10 @@ public RedisClient(EventLoopGroup group, Class socketCh @Override protected void initChannel(Channel ch) throws Exception { ch.pipeline().addFirst(new ConnectionWatchdog(bootstrap, channels), - new CommandEncoder(), - new CommandsListEncoder(), - new CommandsQueue(), - new CommandDecoder()); + new CommandEncoder(), + new CommandsListEncoder(), + new CommandsQueue(), + new CommandDecoder()); } }); @@ -150,6 +154,37 @@ public ChannelGroupFuture shutdownAsync() { return channels.close(); } + /** + * Execute INFO SERVER operation. + * + * @return Map extracted from each response line splitting by ':' symbol + */ + public Map serverInfo() { + try { + return serverInfoAsync().sync().get(); + } catch (Exception e) { + throw new RedisConnectionException("Unable to retrieve server into from: " + addr, e); + } + } + + /** + * Asynchronously execute INFO SERVER operation. + * + * @return A future for a map extracted from each response line splitting by + * ':' symbol + */ + public Future> serverInfoAsync() { + final RedisConnection connection = connect(); + Promise> async = (Promise) connection.async(RedisCommands.SERVER_INFO); + async.addListener(new GenericFutureListener>>() { + @Override + public void operationComplete(Promise> future) throws Exception { + connection.closeAsync(); + } + }); + return async; + } + @Override public String toString() { return "[addr=" + addr + "]"; diff --git a/src/main/java/org/redisson/client/protocol/RedisCommands.java b/src/main/java/org/redisson/client/protocol/RedisCommands.java index e3737d25991..9125f6aeb88 100644 --- a/src/main/java/org/redisson/client/protocol/RedisCommands.java +++ b/src/main/java/org/redisson/client/protocol/RedisCommands.java @@ -251,4 +251,5 @@ public interface RedisCommands { RedisStrictCommand INFO_REPLICATION = new RedisStrictCommand("INFO", "replication", new StringDataDecoder()); RedisStrictCommand> INFO_PERSISTENCE = new RedisStrictCommand>("INFO", "persistence", new StringMapDataDecoder()); + RedisStrictCommand> SERVER_INFO = new RedisStrictCommand>("INFO", "SERVER", new StringMapDataDecoder()); }