1
- Flask- Redis-Sentinel
2
- ====================
1
+ Redis-Sentinel-Url
2
+ ==================
3
3
4
- .. image :: https://travis-ci.org/Infinario/flask- redis-sentinel.svg
5
- :target: https://travis-ci.org/Infinario/flask- redis-sentinel
4
+ .. image :: https://travis-ci.org/exponea/ redis-sentinel-url .svg
5
+ :target: https://travis-ci.org/exponea/ redis-sentinel-url
6
6
:alt: Travis CI
7
7
8
- Flask- Redis-Sentinel provides support for connecting to Redis using Sentinel and also supports connecting to Redis
9
- without it .
8
+ Redis-Sentinel-Url provides parser and connection factory for ` redis:// ` and ` redis+sentinel:// ` URLs (the latter
9
+ being defined by this package) .
10
10
11
11
* Supports Python 2.7 and 3.3+
12
12
* Licensed using Apache License 2.0
@@ -16,84 +16,42 @@ Installation
16
16
17
17
Install with pip::
18
18
19
- pip install Flask- Redis-Sentinel
19
+ pip install Redis-Sentinel-Url
20
20
21
- Basic usage
22
- -----------
23
-
24
- .. code-block :: python
25
-
26
- from flask.ext.redis_sentinel import SentinelExtension
27
-
28
- redis_sentinel = SentinelExtension()
29
- redis_connection = redis_sentinel.default_connection
30
-
31
- # Later when you create application
32
- app = Flask(... )
33
- redis_sentinel.init_app(app)
34
-
35
- You can configure Redis connection parameters using `REDIS_URL ` Flask configuration variable with `redis+sentinel `
36
- URL scheme::
37
-
38
- redis+sentinel://localhost:26379[,otherhost:26379,...]/mymaster/0
39
- redis+sentinel://localhost:26379[,otherhost:26379,...]/mymaster/0?socket_timeout=0.1
40
- redis+sentinel://localhost:26379[,otherhost:26379,...]/mymaster/0?sentinel_socket_timeout=0.1
41
- redis+sentinel://:sentinel-secret-password@localhost:26379[,otherhost:26379,...]/mymaster/0?sentinel_socket_timeout=0.1
42
-
43
- The extension also supports URL schemes as supported by redis-py for connecting to an instance directly without Sentinel::
44
-
45
- redis://[:password]@localhost:6379/0
46
- rediss://[:password]@localhost:6379/0
47
- unix://[:password]@/path/to/socket.sock?db=0
48
21
49
- Flask-And-Redis style config variables are also supported for easier migration, but the extension will
50
- log a `DeprecationWarning `::
51
-
52
- REDIS_HOST = 'localhost'
53
- REDIS_PORT = 6379
54
- REDIS_DB = 0
22
+ URL scheme for connecting via Sentinel
23
+ --------------------------------------
55
24
56
- In case both ` REDIS_URL ` and other variables are present, the URL is used.
25
+ This package defines ` redis+sentinel:// ` scheme for connecting to Redis via Sentinel::
57
26
58
- Creating multiple connection pools using a single Sentinel cluster
59
- ------------------------------------------------------------------
27
+ redis+sentinel://[:sentinel_password@]host:port[,host2:port2,...][/service_name[/db]][?param1=value1[¶m2=value=2&...]]
60
28
61
- .. code-block :: python
29
+ - You can specify multiple sentinel host:port pairs separated by comma.
30
+ - If `service_name ` is provided, it is used to create a default client
31
+ - `service_name ` and `db ` can also be specified as URL parameters (URL parameters take precedence)
32
+ - Client options (keyword arguments to `redis.StrictRedis `) are specified as URL parameters
33
+ - Options for connecting to Sentinel (keyword arguments to `redis.sentinel.Sentinel `) are specified
34
+ with `sentinel_ ` prefix
35
+ - There is special `client_type ` option to specify whether the default client should be `master ` (the default) or
36
+ `slave ` service when connecting via Sentinel
62
37
63
- from flask.ext.redis_sentinel import SentinelExtension
38
+ Basic usage
39
+ -----------
64
40
65
- redis_sentinel = SentinelExtension()
66
- master1 = redis_sentinel.master_for(' service1' )
67
- master2 = redis_sentinel.master_for(' service2' )
68
- slave1 = redis_sentinel.slave_for(' service1' )
69
-
70
- Accessing redis-py's Sentinel instance
71
- --------------------------------------
41
+ Supports schemes supported by `redis.StrictRedis.from_url ` and also `redis+sentinel:// ` scheme described above:
72
42
73
43
.. code-block :: python
74
44
75
- from flask.ext.redis_sentinel import SentinelExtension
76
- from flask import jsonify, Flask
77
-
78
- app = Flask(' test' )
79
-
80
- redis_sentinel = SentinelExtension(app = app)
81
-
82
- @app.route (' /' ):
83
- def index ():
84
- slaves = redis_sentinel.sentinel.discover_slaves(' service1' )
85
- return jsonify(slaves = slaves)
86
-
87
- Change log
88
- ----------
45
+ import redis_sentinel_url
89
46
90
- v0.2.0
91
- ~~~~~~
47
+ sentinel, client = redis_sentinel_url.connect( ' redis://localhost/0 ' )
48
+ # None, StrictRedis(...)
92
49
93
- * Use config variables other than ` REDIS_{HOST, PORT, DB} ` even if ` REDIS_URL ` is used
94
- * Minor refactoring
50
+ sentinel, client = redis_sentinel_url.connect( ' rediss://localhost/0 ' )
51
+ # None, StrictRedis(...)
95
52
96
- v0.1.0
97
- ~~~~~~
53
+ sentinel, client = redis_sentinel_url.connect( ' unix://[:password]@/path/to/socket.sock?db=0 ' )
54
+ # None, StrictRedis(...)
98
55
99
- * Initial release
56
+ sentinel, client = redis_sentinel_url.connect(' redis+sentinel://localhost:26379,otherhost:26479/mymaster/0' )
57
+ # Sentinel(...), StrictRedis(...)
0 commit comments