22Redis Backends
33------------------
44
5- Provides backends for talking to `Redis <http://redis.io>`_ .
5+ Provides backends for talking to `Redis <http://redis.io>`__ .
66
77"""
88
2222
2323
2424class RedisBackend (BytesBackend ):
25- r"""A `Redis <http://redis.io/>`_ backend, using the
26- `redis-py <http://pypi.python.org/pypi/redis/>`_ driver.
25+ r"""A `Redis <http://redis.io/>`__ backend, using the
26+ `redis-py <http://pypi.python.org/pypi/redis/>`__ driver.
2727
2828 Example configuration::
2929
@@ -73,6 +73,20 @@ class RedisBackend(BytesBackend):
7373 Redis should expire it. This argument is only valid when
7474 ``distributed_lock`` is ``True``.
7575
76+ :param lock_sleep: integer, number of seconds to sleep when failed to
77+ acquire a lock. This argument is only valid when
78+ ``distributed_lock`` is ``True``.
79+
80+ :param lock_blocking: bool, default ``True``. Passed to the Redis client's
81+ lock constructor when ``distributed_lock`` is ``True``.
82+
83+ .. versionadded:: 1.4.1
84+
85+ :param lock_blocking_timeout: int or float, default ``None``. Passed to the
86+ Redis client's lock constructor when ``distributed_lock`` is ``True``.
87+
88+ .. versionadded:: 1.4.1
89+
7690 :param socket_timeout: float, seconds for socket timeout.
7791 Default is None (no timeout).
7892
@@ -91,10 +105,6 @@ class RedisBackend(BytesBackend):
91105
92106 .. versionadded:: 1.3.2
93107
94- :param lock_sleep: integer, number of seconds to sleep when failed to
95- acquire a lock. This argument is only valid when
96- ``distributed_lock`` is ``True``.
97-
98108 :param connection_pool: ``redis.ConnectionPool`` object. If provided,
99109 this object supersedes other connection arguments passed to the
100110 ``redis.StrictRedis`` instance, including url and/or host as well as
@@ -106,17 +116,20 @@ class RedisBackend(BytesBackend):
106116 asynchronous runners, as they run in a different thread than the one
107117 used to create the lock.
108118
119+ :param ssl: boolean, default ``None``. If set, this is passed to the
120+ ``redis.StrictRedis`` constructor as ``ssl``. All additional ``ssl_``
121+ prefixed args should be submitted via the
122+ :paramref:`.RedisBackend.connection_kwargs` dict.
123+
124+ .. versionadded:: 1.4.1
125+
109126 :param connection_kwargs: dict, additional keyword arguments are passed
110127 along to the
111128 ``StrictRedis.from_url()`` method or ``StrictRedis()`` constructor
112129 directly, including parameters like ``ssl``, ``ssl_certfile``,
113130 ``charset``, etc.
114131
115132 .. versionadded:: 1.1.6
116-
117-
118-
119-
120133 """
121134
122135 def __init__ (self , arguments ):
@@ -128,7 +141,6 @@ def __init__(self, arguments):
128141 self .password = arguments .pop ("password" , None )
129142 self .port = arguments .pop ("port" , 6379 )
130143 self .db = arguments .pop ("db" , 0 )
131- self .distributed_lock = arguments .pop ("distributed_lock" , False )
132144 self .socket_timeout = arguments .pop ("socket_timeout" , None )
133145 self .socket_connect_timeout = arguments .pop (
134146 "socket_connect_timeout" , None
@@ -137,8 +149,19 @@ def __init__(self, arguments):
137149 self .socket_keepalive_options = arguments .pop (
138150 "socket_keepalive_options" , None
139151 )
152+
153+ # additional ssl params should be submitted in `connection_kwargs`
154+ self .ssl = arguments .pop ("ssl" , None )
155+
156+ # used by `get_mutex`
157+ self .distributed_lock = arguments .pop ("distributed_lock" , False )
140158 self .lock_timeout = arguments .pop ("lock_timeout" , None )
141159 self .lock_sleep = arguments .pop ("lock_sleep" , 0.1 )
160+ self .lock_blocking = arguments .pop ("lock_blocking" , True )
161+ self .lock_blocking_timeout = arguments .pop (
162+ "lock_blocking_timeout" , None
163+ )
164+
142165 self .thread_local_lock = arguments .pop ("thread_local_lock" , True )
143166 self .connection_kwargs = arguments .pop ("connection_kwargs" , {})
144167
@@ -150,6 +173,7 @@ def __init__(self, arguments):
150173
151174 self .redis_expiration_time = arguments .pop ("redis_expiration_time" , 0 )
152175 self .connection_pool = arguments .pop ("connection_pool" , None )
176+
153177 self ._create_client ()
154178
155179 def _imports (self ):
@@ -179,6 +203,8 @@ def _create_client(self):
179203 args ["socket_keepalive_options" ] = (
180204 self .socket_keepalive_options
181205 )
206+ if self .ssl is not None :
207+ args ["ssl" ] = self .ssl
182208
183209 if self .url is not None :
184210 args .update (url = self .url )
@@ -203,6 +229,8 @@ def get_mutex(self, key):
203229 timeout = self .lock_timeout ,
204230 sleep = self .lock_sleep ,
205231 thread_local = self .thread_local_lock ,
232+ blocking = self .lock_blocking ,
233+ blocking_timeout = self .lock_blocking_timeout ,
206234 )
207235 )
208236 else :
@@ -259,10 +287,10 @@ def locked(self) -> bool:
259287
260288
261289class RedisSentinelBackend (RedisBackend ):
262- """A `Redis <http://redis.io/>`_ backend, using the
263- `redis-py <http://pypi.python.org/pypi/redis/>`_ driver.
290+ """A `Redis <http://redis.io/>`__ backend, using the
291+ `redis-py <http://pypi.python.org/pypi/redis/>`__ driver.
264292 This backend is to be used when using
265- `Redis Sentinel <https://redis.io/docs/management/sentinel/>`_ .
293+ `Redis Sentinel <https://redis.io/docs/management/sentinel/>`__ .
266294
267295 .. versionadded:: 1.0.0
268296
@@ -413,17 +441,17 @@ def _create_client(self):
413441
414442
415443class RedisClusterBackend (RedisBackend ):
416- r"""A `Redis <http://redis.io/>`_ backend, using the
417- `redis-py <http://pypi.python.org/pypi/redis/>`_ driver.
444+ r"""A `Redis <http://redis.io/>`__ backend, using the
445+ `redis-py <http://pypi.python.org/pypi/redis/>`__ driver.
418446 This backend is to be used when connecting to a
419- `Redis Cluster <https://redis.io/docs/management/scaling/>`_ which
447+ `Redis Cluster <https://redis.io/docs/management/scaling/>`__ which
420448 will use the
421449 `RedisCluster Client
422- <https://redis.readthedocs.io/en/stable/connections.html#cluster-client>`_ .
450+ <https://redis.readthedocs.io/en/stable/connections.html#cluster-client>`__ .
423451
424452 .. seealso::
425453
426- `Clustering <https://redis.readthedocs.io/en/stable/clustering.html>`_
454+ `Clustering <https://redis.readthedocs.io/en/stable/clustering.html>`__
427455 in the redis-py documentation.
428456
429457 Requires redis-py version >=4.1.0.
0 commit comments