File tree Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Expand file tree Collapse file tree 3 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -365,14 +365,26 @@ Connecting redis-py to the Sentinel instance(s) is easy. You can use a
365
365
Sentinel connection to discover the master and slaves network addresses:
366
366
367
367
``` pycon
368
- >>> from redis.sentinel import Sentinel
368
+ >>> from redis import Sentinel
369
369
>>> sentinel = Sentinel([(' localhost' , 26379 )], socket_timeout = 0.1 )
370
370
>>> sentinel.discover_master(' mymaster' )
371
371
('127.0.0.1', 6379)
372
372
>>> sentinel.discover_slaves(' mymaster' )
373
373
[('127.0.0.1', 6380)]
374
374
```
375
375
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
+
376
388
You can also create Redis client connections from a Sentinel instance.
377
389
You can connect to either the master (for write operations) or a slave
378
390
(for read-only operations).
Original file line number Diff line number Diff line change 6
6
SSLConnection ,
7
7
UnixDomainSocketConnection
8
8
)
9
+ from redis .sentinel import (
10
+ Sentinel ,
11
+ SentinelConnectionPool ,
12
+ SentinelManagedConnection ,
13
+ SentinelManagedSSLConnection ,
14
+ )
9
15
from redis .utils import from_url
10
16
from redis .exceptions import (
11
17
AuthenticationError ,
@@ -51,6 +57,10 @@ def int_or_str(value):
51
57
'Redis' ,
52
58
'RedisError' ,
53
59
'ResponseError' ,
60
+ 'Sentinel' ,
61
+ 'SentinelConnectionPool' ,
62
+ 'SentinelManagedConnection' ,
63
+ 'SentinelManagedSSLConnection' ,
54
64
'SSLConnection' ,
55
65
'StrictRedis' ,
56
66
'TimeoutError' ,
Original file line number Diff line number Diff line change @@ -80,7 +80,9 @@ class SentinelConnectionPool(ConnectionPool):
80
80
81
81
def __init__ (self , service_name , sentinel_manager , ** kwargs ):
82
82
kwargs ['connection_class' ] = kwargs .get (
83
- 'connection_class' , SentinelManagedConnection )
83
+ 'connection_class' ,
84
+ SentinelManagedSSLConnection if kwargs .pop ('ssl' , False )
85
+ else SentinelManagedConnection )
84
86
self .is_master = kwargs .pop ('is_master' , True )
85
87
self .check_connection = kwargs .pop ('check_connection' , False )
86
88
super ().__init__ (** kwargs )
You can’t perform that action at this time.
0 commit comments