lettuce底层通过netty实现了多线程安全,即一个tcp连接可以同时处理多个redis操作,
我现在比较疑问的是,lettuce怎么保证返回的结果能够对应各自发送的redis操作。
@Test
public void testLettuce() throws InterruptedException {
RedisClient redisClient = RedisClient.create("redis://zex1240888747@10.21.7.72:6379/0");
StatefulRedisConnection<String, String> connection = redisClient.connect();
RedisCommands<String, String> syncCommands = connection.sync();
ThreadPoolExecutor t = (ThreadPoolExecutor)Executors.newFixedThreadPool(2);
t.submit(()->{
String key1 = syncCommands.set("key1","111");
});
t.submit(()->{
String key2 = syncCommands.set("key2", "Hello, Redis!");
});
Thread.sleep(2000);
connection.close();
redisClient.shutdown();
}
代码,如上,他们的返回结果有可能同时返回,那么他是怎么保证key1和key2分别对应的是key1和key2的返回结果,请各位大神帮我解疑。