How to use lettuce in the right way
See original GitHub issueBug Report
When the server is under a lot of pressure, call lettucePool.acquire().get(1, TimeUnit.SECONDS)
and the program has the following exception.
Exception
java.util.NoSuchElementException: Pool exhausted
...
Other exception stack information
Java code
// config RedisClusterClient
ClientResources clientResources = DefaultClientResources.builder()
.ioThreadPoolSize(3 * Runtime.getRuntime().availableProcessors())
.computationThreadPoolSize(4)
.reconnectDelay(Delay.constant(Duration.ofSeconds(1)))
.build();
RedisClusterClient clusterClient = RedisClusterClient.create(clientResources, redisURIS);
ClusterTopologyRefreshOptions topologyRefreshOptions = ClusterTopologyRefreshOptions
.builder()
.enableAdaptiveRefreshTrigger(ClusterTopologyRefreshOptions.RefreshTrigger.MOVED_REDIRECT,ClusterTopologyRefreshOptions.RefreshTrigger.PERSISTENT_RECONNECTS)
.adaptiveRefreshTriggersTimeout(Duration.ofMinutes(3))
.build();
clusterClient.setOptions(ClusterClientOptions.builder()
.topologyRefreshOptions(topologyRefreshOptions)
.autoReconnect(true)
.pingBeforeActivateConnection(true)
.build());
// config lettucePool
// maxIdle = 8
// minIdle = 1
// maxActive = 8
// testOnCreate = true
final BoundedPoolConfig boundedPoolConfig = BoundedPoolConfig
.builder()
.minIdle(minIdle)
.maxIdle(maxIdle)
.maxTotal(maxActive)
.testOnCreate(testOnCreate)
.testOnAcquire(true).build();
final BoundedAsyncPool<StatefulRedisClusterConnection<String, String>> lettucePool =
AsyncConnectionPoolSupport.createBoundedObjectPool(() -> clusterClient.connectAsync(StringCodec.UTF8), boundedPoolConfig);
===============================================================
// way of use
@Autowired
BoundedAsyncPool<StatefulRedisClusterConnection<String, String>> lettucePool;
// way of use
final StatefulRedisClusterConnection<String, String> connection = lettucePool.acquire().get(1, TimeUnit.SECONDS);
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to Use Up Lettuce & Other Greens Before They Go Bad ...
This is one of my favorite ways to use up lettuce before it goes bad. Cut into wedges or thick slices, dressed with...
Read more >The Very Best Way to Use Up Lots of Lettuce - Roots & Boots
Harvest lettuce. · Wash thoroughly. · You can dry the lettuce, but it's not necessary. · Stuff it into a high powered blender....
Read more >38 Lettuce Recipes That Go Beyond Salad | Bon Appétit
Lettuce Show You How Versatile Tender Greens Can Be With These 38 Recipes · Classic Caesar Salad · Little Gem Salad with Lemon...
Read more >How to Use Your Garden Lettuces - 4 Ideas to use ... - YouTube
Is it that time of year when you are wondering how to use your garden lettuces for something other than salads?
Read more >How to Harvest Lettuce so it Keeps on Growing ... - YouTube
Growing your own fresh, tasty salads for several months is easy when you know how to harvest lettuce so it keeps on growing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Lettuce connection are designed to be long-lived and they are thread-safe. If you use Redis Cluster with simple GET and SET commands, then you don’t need pooling at all. The only thing to do is injecting
StatefulRedisClusterConnection
into your code and simply using it.Thank you very much for your reply. I will try your suggestion.