Skip to content

Commit d66962e

Browse files
committed
Extract URL parsing code into a separate library
1 parent ea1d7c3 commit d66962e

9 files changed

+465
-943
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
*.swp
33
*.bak
44
*~
5+
.coverage
56
.idea
6-
Flask_Redis_Sentinel.egg-info
7+
.tox
8+
*.egg-info
79
MANIFEST
810
dist
911
build

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ python:
33
- "2.7"
44
- "3.3"
55
- "3.4"
6+
- "3.5"
67
- "pypy"
78
install:
89
- "pip install ."

README.rst

Lines changed: 31 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
Flask-Redis-Sentinel
2-
====================
1+
Redis-Sentinel-Url
2+
==================
33

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
66
:alt: Travis CI
77

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).
1010

1111
* Supports Python 2.7 and 3.3+
1212
* Licensed using Apache License 2.0
@@ -16,84 +16,42 @@ Installation
1616

1717
Install with pip::
1818

19-
pip install Flask-Redis-Sentinel
19+
pip install Redis-Sentinel-Url
2020

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
4821

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+
--------------------------------------
5524

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::
5726

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[&param2=value=2&...]]
6028

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
6237

63-
from flask.ext.redis_sentinel import SentinelExtension
38+
Basic usage
39+
-----------
6440

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:
7242

7343
.. code-block:: python
7444
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
8946
90-
v0.2.0
91-
~~~~~~
47+
sentinel, client = redis_sentinel_url.connect('redis://localhost/0')
48+
# None, StrictRedis(...)
9249
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(...)
9552
96-
v0.1.0
97-
~~~~~~
53+
sentinel, client = redis_sentinel_url.connect('unix://[:password]@/path/to/socket.sock?db=0')
54+
# None, StrictRedis(...)
9855
99-
* Initial release
56+
sentinel, client = redis_sentinel_url.connect('redis+sentinel://localhost:26379,otherhost:26479/mymaster/0')
57+
# Sentinel(...), StrictRedis(...)

0 commit comments

Comments
 (0)