@@ -29,6 +29,7 @@ progress in implementing the recommendations.
2929 {{< checklist-item "#retries" >}}Retries{{< /checklist-item >}}
3030 {{< checklist-item "#health-checks" >}}Health checks{{< /checklist-item >}}
3131 {{< checklist-item "#exception-handling" >}}Exception handling{{< /checklist-item >}}
32+ {{< checklist-item "#timeouts" >}}Timeouts{{< /checklist-item >}}
3233{{< /checklist >}}
3334
3435## Recommendations
@@ -170,3 +171,29 @@ module. The list below describes some of the most common exceptions.
170171- ` WatchError ` : Thrown when a
171172 [ watched key] ({{< relref "/develop/clients/redis-py/transpipe#watch-keys-for-changes" >}}) is
172173 modified during a transaction.
174+
175+ ### Timeouts
176+
177+ After you issue a command or a connection attempt, the client will wait
178+ for a response from the server. If the server doesn't respond within a
179+ certain time limit, the client will throw a ` TimeoutError ` . By default,
180+ the timeout happens after 10 seconds for both connections and commands, but you
181+ can set your own timeouts using the ` socket_connect_timeout ` and ` socket_timeout ` parameters
182+ when you connect:
183+
184+ ``` py
185+ # Set a 15-second timeout for connections and a
186+ # 5-second timeout for commands.
187+ r = Redis(
188+ socket_connect_timeout = 15 ,
189+ socket_timeout = 5 ,
190+ .
191+ .
192+ )
193+ ```
194+
195+ Take care to set the timeouts to appropriate values for your use case.
196+ If you use timeouts that are too short, then ` redis-py ` might retry
197+ commands that would have succeeded if given more time. However, if the
198+ timeouts are too long, your app might spend too long waiting for a
199+ response that will never arrive.
0 commit comments