You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
involves storing the results from read-only commands in a local cache. If the
58
+
same command is executed again later, the results can be obtained from the cache,
59
+
without contacting the server. This improves command execution time on the client,
60
+
while also reducing network traffic and server load. See
61
+
[Connect using client-side caching]({{< relref "/develop/clients/jedis/connect#connect-using-client-side-caching" >}})
62
+
for more information and example code.
20
63
21
64
### Timeouts
22
65
23
-
To set a timeout for a connection, use the `JedisPooled` or `JedisPool` constructor with the `timeout` parameter, or use `JedisClientConfig` with the `socketTimeout` and `connectionTimeout` parameters:
66
+
If a network or server error occurs while your code is opening a
67
+
connection or issuing a command, it can end up hanging indefinitely.
68
+
You can prevent this from happening by setting timeouts for socket
69
+
reads and writes and for opening connections.
70
+
71
+
To set a timeout for a connection, use the `JedisPooled` or `JedisPool` constructor with the `timeout` parameter, or use `JedisClientConfig` with the `socketTimeout` and `connectionTimeout` parameters.
72
+
(The socket timeout is the maximum time allowed for reading or writing data while executing a
73
+
command. The connection timeout is the maximum time allowed for establishing a new connection.)
Copy file name to clipboardExpand all lines: content/develop/clients/lettuce/produsage.md
+25Lines changed: 25 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,31 @@ In some cases, the defaults are based on environment-specific settings (e.g., op
29
29
For more details on setting specific timeouts, see the [Lettuce reference guide](https://redis.github.io/lettuce/).
30
30
{{% /alert %}}
31
31
32
+
### Prerequisites
33
+
34
+
To set TCP-level timeouts, you need to ensure you have one of [Netty Native Transports](https://netty.io/wiki/native-transports.html) installed. The most common one is `netty-transport-native-epoll`, which is used for Linux systems. You can add it to your project by including the following dependency in your `pom.xml` file:
Once you have the native transport dependency, you can verify that by using the following code:
46
+
47
+
```java
48
+
logger.info("Lettuce epool is available: {}", EpollProvider.isAvailable());
49
+
```
50
+
51
+
If the snippet above returns `false`, you need to enable debugging logging for `io.lettuce.core` and `io.netty` to see why the native transport is not available.
52
+
53
+
For more information on using Netty Native Transport, see the [Lettuce reference guide](https://redis.github.io/lettuce/advanced-usage/#native-transports).
54
+
55
+
### Setting timeouts
56
+
32
57
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.
0 commit comments