RedisClient Class — netty Architecture
Architecture documentation for the RedisClient class in RedisClient.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 33d3e261_512f_87ff_bec6_a1b9d77ef35b["RedisClient"] 1796382e_4bd3_5888_6d8e_2af759282fb7["RedisClient.java"] 33d3e261_512f_87ff_bec6_a1b9d77ef35b -->|defined in| 1796382e_4bd3_5888_6d8e_2af759282fb7 46136aa8_f5fa_ee1e_f0c6_f327438eb199["main()"] 33d3e261_512f_87ff_bec6_a1b9d77ef35b -->|method| 46136aa8_f5fa_ee1e_f0c6_f327438eb199
Relationship Graph
Source Code
example/src/main/java/io/netty/example/redis/RedisClient.java lines 39–95
public class RedisClient {
private static final String HOST = System.getProperty("host", "127.0.0.1");
private static final int PORT = Integer.parseInt(System.getProperty("port", "6379"));
public static void main(String[] args) throws Exception {
EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
try {
Bootstrap b = new Bootstrap();
b.group(group)
.channel(NioSocketChannel.class)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new RedisDecoder());
p.addLast(new RedisBulkStringAggregator());
p.addLast(new RedisArrayAggregator());
p.addLast(new RedisEncoder());
p.addLast(new RedisClientHandler());
}
});
// Start the connection attempt.
Channel ch = b.connect(HOST, PORT).sync().channel();
// Read commands from the stdin.
System.out.println("Enter Redis commands (quit to end)");
ChannelFuture lastWriteFuture = null;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for (;;) {
final String input = in.readLine();
final String line = input != null ? input.trim() : null;
if (line == null || "quit".equalsIgnoreCase(line)) { // EOF or "quit"
ch.close().sync();
break;
} else if (line.isEmpty()) { // skip `enter` or `enter` with spaces.
continue;
}
// Sends the received line to the server.
lastWriteFuture = ch.writeAndFlush(line);
lastWriteFuture.addListener(future -> {
if (!future.isSuccess()) {
System.err.print("write failed: ");
future.cause().printStackTrace(System.err);
}
});
}
// Wait until all messages are flushed before closing the channel.
if (lastWriteFuture != null) {
lastWriteFuture.sync();
}
} finally {
group.shutdownGracefully();
}
}
}
Source
Frequently Asked Questions
What is the RedisClient class?
RedisClient is a class in the netty codebase, defined in example/src/main/java/io/netty/example/redis/RedisClient.java.
Where is RedisClient defined?
RedisClient is defined in example/src/main/java/io/netty/example/redis/RedisClient.java at line 39.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free