Skip to content

Commit

Permalink
added server info command to RedisClient
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui Gu committed Apr 6, 2016
1 parent 40930d0 commit 103d0f6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
43 changes: 39 additions & 4 deletions src/main/java/org/redisson/client/RedisClient.java
Expand Up @@ -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 {

Expand All @@ -62,10 +66,10 @@ public RedisClient(EventLoopGroup group, Class<? extends SocketChannel> 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());
}
});

Expand Down Expand Up @@ -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<String, String> 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<Map<String, String>> serverInfoAsync() {
final RedisConnection connection = connect();
Promise<Map<String, String>> async = (Promise) connection.async(RedisCommands.SERVER_INFO);
async.addListener(new GenericFutureListener<Promise<Map<String, String>>>() {
@Override
public void operationComplete(Promise<Map<String, String>> future) throws Exception {
connection.closeAsync();
}
});
return async;
}

@Override
public String toString() {
return "[addr=" + addr + "]";
Expand Down
Expand Up @@ -251,4 +251,5 @@ public interface RedisCommands {

RedisStrictCommand<String> INFO_REPLICATION = new RedisStrictCommand<String>("INFO", "replication", new StringDataDecoder());
RedisStrictCommand<Map<String, String>> INFO_PERSISTENCE = new RedisStrictCommand<Map<String, String>>("INFO", "persistence", new StringMapDataDecoder());
RedisStrictCommand<Map<String, String>> SERVER_INFO = new RedisStrictCommand<Map<String, String>>("INFO", "SERVER", new StringMapDataDecoder());
}

0 comments on commit 103d0f6

Please sign in to comment.