Skip to content

Commit e1a2693

Browse files
DOC-4543 finished Lettuce stuff
1 parent e321bbe commit e1a2693

File tree

3 files changed

+91
-70
lines changed

3 files changed

+91
-70
lines changed

content/develop/clients/lettuce/_index.md

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -83,73 +83,10 @@ public class ConnectBasicTest {
8383
}
8484
```
8585

86-
### Timeouts
86+
## More information
8787

88-
Lettuce provides timeouts for many operations, such as command execution, SSL handshake, and Sentinel discovery. By default, Lettuce uses a global timeout value of 60 seconds for these operations, but you can override the global timeout value with individual timeout values for each operation.
88+
The [Lettuce reference guide](https://redis.github.io/lettuce/) has more examples
89+
and an API reference. You may also be interested in the
90+
[Project Reactor](https://projectreactor.io/) library that Lettuce uses.
8991

90-
{{% alert title="Tip" color="warning" %}}
91-
Choosing suitable timeout values is crucial for your application's performance and stability and is specific to each environment.
92-
Configuring timeouts is only necessary if you have issues with the default values.
93-
In some cases, the defaults are based on environment-specific settings (e.g., operating system settings), while in other cases, they are built into the Lettuce driver.
94-
For more details on setting specific timeouts, see the [Lettuce reference guide](https://redis.github.io/lettuce/).
95-
{{% /alert %}}
96-
97-
Below is an example of setting socket-level timeouts. The `TCP_USER_TIMEOUT` setting is useful for scenarios where the server stops responding without acknowledging the last request, while the `KEEPALIVE` setting is good for detecting dead connections where there is no traffic between the client and the server.
98-
99-
```java
100-
RedisURI redisURI = RedisURI.Builder
101-
.redis("localhost")
102-
// set the global default from the default 60 seconds to 30 seconds
103-
.withTimeout(Duration.ofSeconds(30))
104-
.build();
105-
106-
try (RedisClient client = RedisClient.create(redisURI)) {
107-
// or set specific timeouts for things such as the TCP_USER_TIMEOUT and TCP_KEEPALIVE
108-
109-
// A good general rule of thumb is to follow the rule
110-
// TCP_USER_TIMEOUT = TCP_KEEP_IDLE+TCP_KEEPINTVL * TCP_KEEPCNT
111-
// in this case, 20 = 5 + 5 * 3
112-
113-
SocketOptions.TcpUserTimeoutOptions tcpUserTimeout = SocketOptions.TcpUserTimeoutOptions.builder()
114-
.tcpUserTimeout(Duration.ofSeconds(20))
115-
.enable().build();
116-
117-
SocketOptions.KeepAliveOptions keepAliveOptions = SocketOptions.KeepAliveOptions.builder()
118-
.interval(Duration.ofSeconds(5))
119-
.idle(Duration.ofSeconds(5))
120-
.count(3).enable().build();
121-
122-
SocketOptions socketOptions = SocketOptions.builder()
123-
.tcpUserTimeout(tcpUserTimeout)
124-
.keepAlive(keepAliveOptions)
125-
.build();
126-
127-
client.setOptions(ClientOptions.builder()
128-
.socketOptions(socketOptions)
129-
.build());
130-
131-
StatefulRedisConnection<String, String> connection = client.connect();
132-
System.out.println(connection.sync().ping());
133-
}
134-
```
135-
136-
137-
## DNS cache and Redis
138-
139-
When you connect to a Redis server with multiple endpoints, such as [Redis Enterprise Active-Active](https://redis.com/redis-enterprise/technology/active-active-geo-distribution/), you *must*
140-
disable the JVM's DNS cache. If a server node or proxy fails, the IP address for any database
141-
affected by the failure will change. When this happens, your app will keep
142-
trying to use the stale IP address if DNS caching is enabled.
143-
144-
Use the following code to disable the DNS cache:
145-
146-
```java
147-
java.security.Security.setProperty("networkaddress.cache.ttl","0");
148-
java.security.Security.setProperty("networkaddress.cache.negative.ttl", "0");
149-
```
150-
151-
## Learn more
152-
153-
- [Lettuce reference documentation](https://redis.github.io/lettuce/)
154-
- [Redis commands]({{< relref "/commands" >}})
155-
- [Project Reactor](https://projectreactor.io/)
92+
See also the other pages in this section for more information and examples:

content/develop/clients/lettuce/connect.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class ConnectBasicTest {
4646
}
4747
```
4848

49-
### Asynchronous connection
49+
## Asynchronous connection
5050

5151
```java
5252
package org.example;
@@ -89,7 +89,7 @@ public class Async {
8989

9090
Learn more about asynchronous Lettuce API in [the reference guide](https://redis.github.io/lettuce/#asynchronous-api).
9191

92-
### Reactive connection
92+
## Reactive connection
9393

9494
```java
9595
package org.example;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
categories:
3+
- docs
4+
- develop
5+
- stack
6+
- oss
7+
- rs
8+
- rc
9+
- oss
10+
- kubernetes
11+
- clients
12+
description: Get your Lettuce app ready for production
13+
linkTitle: Production usage
14+
title: Production usage
15+
weight: 3
16+
---
17+
18+
The following sections explain how to handle situations that may occur
19+
in your production environment.
20+
21+
## Timeouts
22+
23+
Lettuce provides timeouts for many operations, such as command execution, SSL handshake, and Sentinel discovery. By default, Lettuce uses a global timeout value of 60 seconds for these operations, but you can override the global timeout value with individual timeout values for each operation.
24+
25+
{{% alert title="Tip" color="warning" %}}
26+
Choosing suitable timeout values is crucial for your application's performance and stability and is specific to each environment.
27+
Configuring timeouts is only necessary if you have issues with the default values.
28+
In some cases, the defaults are based on environment-specific settings (e.g., operating system settings), while in other cases, they are built into the Lettuce driver.
29+
For more details on setting specific timeouts, see the [Lettuce reference guide](https://redis.github.io/lettuce/).
30+
{{% /alert %}}
31+
32+
Below is an example of setting socket-level timeouts. The `TCP_USER_TIMEOUT` setting is useful for scenarios where the server stops responding without acknowledging the last request, while the `KEEPALIVE` setting is good for detecting dead connections where there is no traffic between the client and the server.
33+
34+
```java
35+
RedisURI redisURI = RedisURI.Builder
36+
.redis("localhost")
37+
// set the global default from the default 60 seconds to 30 seconds
38+
.withTimeout(Duration.ofSeconds(30))
39+
.build();
40+
41+
try (RedisClient client = RedisClient.create(redisURI)) {
42+
// or set specific timeouts for things such as the TCP_USER_TIMEOUT and TCP_KEEPALIVE
43+
44+
// A good general rule of thumb is to follow the rule
45+
// TCP_USER_TIMEOUT = TCP_KEEP_IDLE+TCP_KEEPINTVL * TCP_KEEPCNT
46+
// in this case, 20 = 5 + 5 * 3
47+
48+
SocketOptions.TcpUserTimeoutOptions tcpUserTimeout = SocketOptions.TcpUserTimeoutOptions.builder()
49+
.tcpUserTimeout(Duration.ofSeconds(20))
50+
.enable().build();
51+
52+
SocketOptions.KeepAliveOptions keepAliveOptions = SocketOptions.KeepAliveOptions.builder()
53+
.interval(Duration.ofSeconds(5))
54+
.idle(Duration.ofSeconds(5))
55+
.count(3).enable().build();
56+
57+
SocketOptions socketOptions = SocketOptions.builder()
58+
.tcpUserTimeout(tcpUserTimeout)
59+
.keepAlive(keepAliveOptions)
60+
.build();
61+
62+
client.setOptions(ClientOptions.builder()
63+
.socketOptions(socketOptions)
64+
.build());
65+
66+
StatefulRedisConnection<String, String> connection = client.connect();
67+
System.out.println(connection.sync().ping());
68+
}
69+
```
70+
71+
72+
## DNS cache and Redis
73+
74+
When you connect to a Redis server with multiple endpoints, such as [Redis Enterprise Active-Active](https://redis.com/redis-enterprise/technology/active-active-geo-distribution/), you *must*
75+
disable the JVM's DNS cache. If a server node or proxy fails, the IP address for any database
76+
affected by the failure will change. When this happens, your app will keep
77+
trying to use the stale IP address if DNS caching is enabled.
78+
79+
Use the following code to disable the DNS cache:
80+
81+
```java
82+
java.security.Security.setProperty("networkaddress.cache.ttl","0");
83+
java.security.Security.setProperty("networkaddress.cache.negative.ttl", "0");
84+
```

0 commit comments

Comments
 (0)