I have below code to get the data from Redis asynchronously. By default get() call in lettuce library uses nio-event thread pool.
Code 1:
StatefulRedisConnection<String, String> connection = redisClient.connect();RedisAsyncCommands<String, String> command = connection.async();CompletionStage<String> result = command.get(id) .thenAccept(code -> logger.log(Level.INFO, "Thread Id "+ Thread.currentThread().getName()); //Sample code to print thread ID
Thread Id printed is lettuce-nioEventLoop-6-2.
Code 2:
CompletionStage<String> result = command.get(id) .thenAcceptAsync(code -> { logger.log(Level.INFO, "Thread Id "+ Thread.currentThread().getName()); //my original code}, executors);
Thread Id printed is pool-1-thread-1.
My questions:
- Is there a way to pass my executors?
- Is it recommended approach to use nio-event thread pool to get(using get() call) the data from redis?
Lettuce version: 5.2.2.RELEASE
thanks, Ashok