@@ -52,6 +52,8 @@ class RedisBackend(BytesBackend):
5252
5353 :param username: string, default is no username.
5454
55+ .. versionadded:: 1.3.1
56+
5557 :param password: string, default is no password.
5658
5759 :param port: integer, default is ``6379``.
@@ -74,6 +76,21 @@ class RedisBackend(BytesBackend):
7476 :param socket_timeout: float, seconds for socket timeout.
7577 Default is None (no timeout).
7678
79+ :param socket_connect_timeout: float, seconds for socket connection
80+ timeout. Default is None (no timeout).
81+
82+ .. versionadded:: 1.3.2
83+
84+ :param socket_keepalive: boolean, when True, socket keepalive is enabled.
85+ Default is False.
86+
87+ .. versionadded:: 1.3.2
88+
89+ :param socket_keepalive_options: dict, socket keepalive options.
90+ Default is None (no options).
91+
92+ .. versionadded:: 1.3.2
93+
7794 :param lock_sleep: integer, number of seconds to sleep when failed to
7895 acquire a lock. This argument is only valid when
7996 ``distributed_lock`` is ``True``.
@@ -95,9 +112,10 @@ class RedisBackend(BytesBackend):
95112 directly, including parameters like ``ssl``, ``ssl_certfile``,
96113 ``charset``, etc.
97114
98- .. versionadded:: 1.1.6 Added ``connection_kwargs`` parameter.
115+ .. versionadded:: 1.1.6
116+
117+
99118
100- .. versionadded:: 1.3.1 Added ``username`` parameter.
101119
102120 """
103121
@@ -112,6 +130,13 @@ def __init__(self, arguments):
112130 self .db = arguments .pop ("db" , 0 )
113131 self .distributed_lock = arguments .pop ("distributed_lock" , False )
114132 self .socket_timeout = arguments .pop ("socket_timeout" , None )
133+ self .socket_connect_timeout = arguments .pop (
134+ "socket_connect_timeout" , None
135+ )
136+ self .socket_keepalive = arguments .pop ("socket_keepalive" , False )
137+ self .socket_keepalive_options = arguments .pop (
138+ "socket_keepalive_options" , None
139+ )
115140 self .lock_timeout = arguments .pop ("lock_timeout" , None )
116141 self .lock_sleep = arguments .pop ("lock_sleep" , 0.1 )
117142 self .thread_local_lock = arguments .pop ("thread_local_lock" , True )
@@ -144,8 +169,16 @@ def _create_client(self):
144169 else :
145170 args = {}
146171 args .update (self .connection_kwargs )
147- if self .socket_timeout :
172+ if self .socket_timeout is not None :
148173 args ["socket_timeout" ] = self .socket_timeout
174+ if self .socket_connect_timeout is not None :
175+ args ["socket_connect_timeout" ] = self .socket_connect_timeout
176+ if self .socket_keepalive :
177+ args ["socket_keepalive" ] = True
178+ if self .socket_keepalive_options is not None :
179+ args [
180+ "socket_keepalive_options"
181+ ] = self .socket_keepalive_options
149182
150183 if self .url is not None :
151184 args .update (url = self .url )
@@ -256,6 +289,8 @@ class RedisSentinelBackend(RedisBackend):
256289
257290 :param username: string, default is no username.
258291
292+ .. versionadded:: 1.3.1
293+
259294 :param password: string, default is no password.
260295
261296 :param db: integer, default is ``0``.
@@ -276,6 +311,21 @@ class RedisSentinelBackend(RedisBackend):
276311 :param socket_timeout: float, seconds for socket timeout.
277312 Default is None (no timeout).
278313
314+ .. versionadded:: 1.3.2
315+
316+ :param socket_connect_timeout: float, seconds for socket connection
317+ timeout. Default is None (no timeout).
318+
319+ .. versionadded:: 1.3.2
320+
321+ :param socket_keepalive: boolean, when True, socket keepalive is enabled
322+ Default is False.
323+
324+ .. versionadded:: 1.3.2
325+
326+ :param socket_keepalive_options: dict, socket keepalive options.
327+ Default is {} (no options).
328+
279329 :param sentinels: is a list of sentinel nodes. Each node is represented by
280330 a pair (hostname, port).
281331 Default is None (not in sentinel mode).
@@ -303,7 +353,6 @@ class RedisSentinelBackend(RedisBackend):
303353 asynchronous runners, as they run in a different thread than the one
304354 used to create the lock.
305355
306- .. versionadded:: 1.3.1 Added ``username`` parameter.
307356
308357 """
309358
@@ -343,6 +392,16 @@ def _create_client(self):
343392 sentinel_kwargs .setdefault ("db" , self .db )
344393 if self .socket_timeout is not None :
345394 connection_kwargs .setdefault ("socket_timeout" , self .socket_timeout )
395+ if self .socket_connect_timeout is not None :
396+ connection_kwargs .setdefault (
397+ "socket_connect_timeout" , self .socket_connect_timeout
398+ )
399+ if self .socket_keepalive :
400+ connection_kwargs .setdefault ("socket_keepalive" , True )
401+ if self .socket_keepalive_options is not None :
402+ connection_kwargs .setdefault (
403+ "socket_keepalive_options" , self .socket_keepalive_options
404+ )
346405
347406 sentinel = redis .sentinel .Sentinel (
348407 self .sentinels ,
@@ -463,6 +522,12 @@ class RedisClusterBackend(RedisBackend):
463522 :param socket_timeout: float, seconds for socket timeout.
464523 Default is None (no timeout).
465524
525+ :param socket_connect_timeout: float, seconds for socket connection
526+ timeout. Default is None (no timeout).
527+
528+ :param socket_keepalive: boolean, when True, socket keepalive is enabled
529+ Default is False.
530+
466531 :param lock_sleep: integer, number of seconds to sleep when failed to
467532 acquire a lock. This argument is only valid when
468533 ``distributed_lock`` is ``True``.
0 commit comments