Skip to content

Commit 3bc6ddf

Browse files
committed
export Sentinel at the top level and expose SSL the same way as Redis
Now that `Sentinel` needs to be used specifically instead of via `Redis`, this change exports the class at the top level like the `Redis` client is, and also allows the shorthand of `ssl=True` to set the connection class to the `SentinelManagedSSLConnection`.
1 parent bba7518 commit 3bc6ddf

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,14 +365,26 @@ Connecting redis-py to the Sentinel instance(s) is easy. You can use a
365365
Sentinel connection to discover the master and slaves network addresses:
366366

367367
``` pycon
368-
>>> from redis.sentinel import Sentinel
368+
>>> from redis import Sentinel
369369
>>> sentinel = Sentinel([('localhost', 26379)], socket_timeout=0.1)
370370
>>> sentinel.discover_master('mymaster')
371371
('127.0.0.1', 6379)
372372
>>> sentinel.discover_slaves('mymaster')
373373
[('127.0.0.1', 6380)]
374374
```
375375

376+
To connect to a sentinel which uses SSL ([see SSL
377+
connections](#ssl-connections) for more examples of SSL configurations):
378+
379+
``` pycon
380+
>>> from redis import Sentinel
381+
>>> sentinel = Sentinel([('localhost', 26379)],
382+
ssl=True,
383+
ssl_ca_certs='/etc/ssl/certs/ca-certificates.crt')
384+
>>> sentinel.discover_master('mymaster')
385+
('127.0.0.1', 6379)
386+
```
387+
376388
You can also create Redis client connections from a Sentinel instance.
377389
You can connect to either the master (for write operations) or a slave
378390
(for read-only operations).

redis/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
SSLConnection,
77
UnixDomainSocketConnection
88
)
9+
from redis.sentinel import (
10+
Sentinel,
11+
SentinelConnectionPool,
12+
SentinelManagedConnection,
13+
SentinelManagedSSLConnection,
14+
)
915
from redis.utils import from_url
1016
from redis.exceptions import (
1117
AuthenticationError,
@@ -51,6 +57,10 @@ def int_or_str(value):
5157
'Redis',
5258
'RedisError',
5359
'ResponseError',
60+
'Sentinel',
61+
'SentinelConnectionPool',
62+
'SentinelManagedConnection',
63+
'SentinelManagedSSLConnection',
5464
'SSLConnection',
5565
'StrictRedis',
5666
'TimeoutError',

redis/sentinel.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ class SentinelConnectionPool(ConnectionPool):
8080

8181
def __init__(self, service_name, sentinel_manager, **kwargs):
8282
kwargs['connection_class'] = kwargs.get(
83-
'connection_class', SentinelManagedConnection)
83+
'connection_class',
84+
SentinelManagedSSLConnection if kwargs.pop('ssl', False)
85+
else SentinelManagedConnection)
8486
self.is_master = kwargs.pop('is_master', True)
8587
self.check_connection = kwargs.pop('check_connection', False)
8688
super().__init__(**kwargs)

0 commit comments

Comments
 (0)