Skip to content

Commit e321bbe

Browse files
DOC-4543 more Lettuce stuff:
1 parent 29750f4 commit e321bbe

File tree

1 file changed

+1
-64
lines changed

1 file changed

+1
-64
lines changed

content/develop/clients/lettuce/_index.md

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class ConnectBasicTest {
6767
RedisURI uri = RedisURI.Builder
6868
.redis("localhost", 6379)
6969
.build();
70-
70+
7171
RedisClient client = RedisClient.create(uri);
7272
StatefulRedisConnection<String, String> connection = client.connect();
7373
RedisCommands<String, String> commands = connection.sync();
@@ -133,69 +133,6 @@ try (RedisClient client = RedisClient.create(redisURI)) {
133133
}
134134
```
135135

136-
### Connection pooling
137-
138-
A typical approach with Lettuce is to create a single `RedisClient` instance and reuse it to establish connections to your Redis server(s).
139-
These connections are multiplexed; that is, multiple commands can be run concurrently over a single or a small set of connections, making explicit pooling less practical.
140-
See
141-
[Connection pools and multiplexing]({{< relref "/develop/connect/clients/pools-and-muxing" >}})
142-
for more information.
143-
144-
Lettuce provides pool config to be used with Lettuce asynchronous connection methods.
145-
146-
```java
147-
package org.example;
148-
import io.lettuce.core.RedisClient;
149-
import io.lettuce.core.RedisURI;
150-
import io.lettuce.core.TransactionResult;
151-
import io.lettuce.core.api.StatefulRedisConnection;
152-
import io.lettuce.core.api.async.RedisAsyncCommands;
153-
import io.lettuce.core.codec.StringCodec;
154-
import io.lettuce.core.support.*;
155-
156-
import java.util.concurrent.CompletableFuture;
157-
import java.util.concurrent.CompletionStage;
158-
159-
public class Pool {
160-
public static void main(String[] args) {
161-
RedisClient client = RedisClient.create();
162-
163-
String host = "localhost";
164-
int port = 6379;
165-
166-
CompletionStage<BoundedAsyncPool<StatefulRedisConnection<String, String>>> poolFuture
167-
= AsyncConnectionPoolSupport.createBoundedObjectPoolAsync(
168-
() -> client.connectAsync(StringCodec.UTF8, RedisURI.create(host, port)),
169-
BoundedPoolConfig.create());
170-
171-
// await poolFuture initialization to avoid NoSuchElementException: Pool exhausted when starting your application
172-
AsyncPool<StatefulRedisConnection<String, String>> pool = poolFuture.toCompletableFuture()
173-
.join();
174-
175-
// execute work
176-
CompletableFuture<TransactionResult> transactionResult = pool.acquire()
177-
.thenCompose(connection -> {
178-
179-
RedisAsyncCommands<String, String> async = connection.async();
180-
181-
async.multi();
182-
async.set("key", "value");
183-
async.set("key2", "value2");
184-
System.out.println("Executed commands in pipeline");
185-
return async.exec().whenComplete((s, throwable) -> pool.release(connection));
186-
});
187-
transactionResult.join();
188-
189-
// terminating
190-
pool.closeAsync();
191-
192-
// after pool completion
193-
client.shutdownAsync();
194-
}
195-
}
196-
```
197-
198-
In this setup, `LettuceConnectionFactory` is a custom class you would need to implement, adhering to Apache Commons Pool's `PooledObjectFactory` interface, to manage lifecycle events of pooled `StatefulRedisConnection` objects.
199136

200137
## DNS cache and Redis
201138

0 commit comments

Comments
 (0)