From fea7b85dde375a228f485d27737de66592b28848 Mon Sep 17 00:00:00 2001 From: Terence Honles Date: Mon, 8 Nov 2021 16:54:24 +0100 Subject: Export Sentinel, and SSL like other classes (#1671) --- README.md | 14 +++++++++++++- redis/__init__.py | 10 ++++++++++ redis/sentinel.py | 4 +++- 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) -- cgit v1.2.1