summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerence Honles <terence@honles.com>2021-11-08 16:54:24 +0100
committerGitHub <noreply@github.com>2021-11-08 17:54:24 +0200
commitfea7b85dde375a228f485d27737de66592b28848 (patch)
tree9faee58304479a7c66ce0755c838b07f402a03ae
parent325fcd9e15bf0125f9a60012d7eb7824e7b4ab33 (diff)
downloadredis-py-fea7b85dde375a228f485d27737de66592b28848.tar.gz
Export Sentinel, and SSL like other classes (#1671)
-rw-r--r--README.md14
-rw-r--r--redis/__init__.py10
-rw-r--r--redis/sentinel.py4
3 files changed, 26 insertions, 2 deletions
diff --git a/README.md b/README.md
index a01f820..f03053e 100644
--- a/README.md
+++ b/README.md
@@ -365,7 +365,7 @@ Connecting redis-py to the Sentinel instance(s) is easy. You can use a
Sentinel connection to discover the master and slaves network addresses:
``` pycon
->>> from redis.sentinel import Sentinel
+>>> from redis import Sentinel
>>> sentinel = Sentinel([('localhost', 26379)], socket_timeout=0.1)
>>> sentinel.discover_master('mymaster')
('127.0.0.1', 6379)
@@ -373,6 +373,18 @@ Sentinel connection to discover the master and slaves network addresses:
[('127.0.0.1', 6380)]
```
+To connect to a sentinel which uses SSL ([see SSL
+connections](#ssl-connections) for more examples of SSL configurations):
+
+``` pycon
+>>> from redis import Sentinel
+>>> sentinel = Sentinel([('localhost', 26379)],
+ ssl=True,
+ ssl_ca_certs='/etc/ssl/certs/ca-certificates.crt')
+>>> sentinel.discover_master('mymaster')
+('127.0.0.1', 6379)
+```
+
You can also create Redis client connections from a Sentinel instance.
You can connect to either the master (for write operations) or a slave
(for read-only operations).
diff --git a/redis/__init__.py b/redis/__init__.py
index 003f8a2..603f846 100644
--- a/redis/__init__.py
+++ b/redis/__init__.py
@@ -6,6 +6,12 @@ from redis.connection import (
SSLConnection,
UnixDomainSocketConnection
)
+from redis.sentinel import (
+ Sentinel,
+ SentinelConnectionPool,
+ SentinelManagedConnection,
+ SentinelManagedSSLConnection,
+)
from redis.utils import from_url
from redis.exceptions import (
AuthenticationError,
@@ -51,6 +57,10 @@ __all__ = [
'Redis',
'RedisError',
'ResponseError',
+ 'Sentinel',
+ 'SentinelConnectionPool',
+ 'SentinelManagedConnection',
+ 'SentinelManagedSSLConnection',
'SSLConnection',
'StrictRedis',
'TimeoutError',
diff --git a/redis/sentinel.py b/redis/sentinel.py
index 740d92f..17dd75b 100644
--- a/redis/sentinel.py
+++ b/redis/sentinel.py
@@ -80,7 +80,9 @@ class SentinelConnectionPool(ConnectionPool):
def __init__(self, service_name, sentinel_manager, **kwargs):
kwargs['connection_class'] = kwargs.get(
- 'connection_class', SentinelManagedConnection)
+ 'connection_class',
+ SentinelManagedSSLConnection if kwargs.pop('ssl', False)
+ else SentinelManagedConnection)
self.is_master = kwargs.pop('is_master', True)
self.check_connection = kwargs.pop('check_connection', False)
super().__init__(**kwargs)