Redis-Sentinel integration for Flask
Project description
# Flask-Redis-Sentinel

Flask-Redis-Sentinel provides support for connecting to Redis using Sentinel and also supports connecting to Redis
without it.
* Supports Python 2.7 and 3.3+
* Licensed using Apache License 2.0
## Basic usage
```python
from flask.ext.redis_sentinel import SentinelExtension
redis_sentinel = SentinelExtension()
redis_connection = redis_sentinel.default_connection
# Later when you create application
app = Flask(...)
redis_sentinel.init_app(app)
```
You can configure Redis connection parameters using `REDIS_URL` Flask configuration variable with `redis+sentinel`
URL scheme:
```
redis+sentinel://localhost:26379[,otherhost:26379,...]/mymaster/0
redis+sentinel://localhost:26379[,otherhost:26379,...]/mymaster/0?socket_timeout=0.1
redis+sentinel://localhost:26379[,otherhost:26379,...]/mymaster/0?sentinel_socket_timeout=0.1
redis+sentinel://:sentinel-secret-password@localhost:26379[,otherhost:26379,...]/mymaster/0?sentinel_socket_timeout=0.1
```
The extension also supports URL schemes as supported by redis-py for connecting to an instance directly without Sentinel:
```
redis://[:password]@localhost:6379/0
rediss://[:password]@localhost:6379/0
unix://[:password]@/path/to/socket.sock?db=0
```
Flask-And-Redis style config variables are also supported for easier migration, but the extension will
log a `DeprecationWarning`:
```
REDIS_HOST = 'localhost'
REDIS_PORT = 6379
REDIS_DB = 0
```
In case both `REDIS_URL` and other variables are present, the URL is used.
## Creating multiple connection pools using a single Sentinel cluster
```python
from flask.ext.redis_sentinel import SentinelExtension
redis_sentinel = SentinelExtension()
master1 = redis_sentinel.master_for('service1')
master2 = redis_sentinel.master_for('service2')
slave1 = redis_sentinel.master_for('service1')
```
## Accessing redis-py's Sentinel instance
```python
from flask.ext.redis_sentinel import SentinelExtension
from flask import jsonify, Flask
app = Flask('test')
redis_sentinel = SentinelExtension(app=app)
@app.route('/'):
def index():
slaves = redis_sentinel.sentinel.discover_slaves('service1')
return jsonify(slaves=slaves)
```

Flask-Redis-Sentinel provides support for connecting to Redis using Sentinel and also supports connecting to Redis
without it.
* Supports Python 2.7 and 3.3+
* Licensed using Apache License 2.0
## Basic usage
```python
from flask.ext.redis_sentinel import SentinelExtension
redis_sentinel = SentinelExtension()
redis_connection = redis_sentinel.default_connection
# Later when you create application
app = Flask(...)
redis_sentinel.init_app(app)
```
You can configure Redis connection parameters using `REDIS_URL` Flask configuration variable with `redis+sentinel`
URL scheme:
```
redis+sentinel://localhost:26379[,otherhost:26379,...]/mymaster/0
redis+sentinel://localhost:26379[,otherhost:26379,...]/mymaster/0?socket_timeout=0.1
redis+sentinel://localhost:26379[,otherhost:26379,...]/mymaster/0?sentinel_socket_timeout=0.1
redis+sentinel://:sentinel-secret-password@localhost:26379[,otherhost:26379,...]/mymaster/0?sentinel_socket_timeout=0.1
```
The extension also supports URL schemes as supported by redis-py for connecting to an instance directly without Sentinel:
```
redis://[:password]@localhost:6379/0
rediss://[:password]@localhost:6379/0
unix://[:password]@/path/to/socket.sock?db=0
```
Flask-And-Redis style config variables are also supported for easier migration, but the extension will
log a `DeprecationWarning`:
```
REDIS_HOST = 'localhost'
REDIS_PORT = 6379
REDIS_DB = 0
```
In case both `REDIS_URL` and other variables are present, the URL is used.
## Creating multiple connection pools using a single Sentinel cluster
```python
from flask.ext.redis_sentinel import SentinelExtension
redis_sentinel = SentinelExtension()
master1 = redis_sentinel.master_for('service1')
master2 = redis_sentinel.master_for('service2')
slave1 = redis_sentinel.master_for('service1')
```
## Accessing redis-py's Sentinel instance
```python
from flask.ext.redis_sentinel import SentinelExtension
from flask import jsonify, Flask
app = Flask('test')
redis_sentinel = SentinelExtension(app=app)
@app.route('/'):
def index():
slaves = redis_sentinel.sentinel.discover_slaves('service1')
return jsonify(slaves=slaves)
```
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file Flask-Redis-Sentinel-0.1.0.tar.gz.
File metadata
- Download URL: Flask-Redis-Sentinel-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ecb17722c6e55dc39385061024682871ed0990e85ffc1243808d2351734d82f
|
|
| MD5 |
ac02e4335dedde2a35d21b5a6f99a1d4
|
|
| BLAKE2b-256 |
d866597541b4193dfc03de427401de04b9fb98d07567d4c918df685390b28765
|
File details
Details for the file Flask_Redis_Sentinel-0.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: Flask_Redis_Sentinel-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cb346c179f8b8d5c9f9e28677108df22c1b9fd25e9c5fe970050d4918bc005f
|
|
| MD5 |
4de4e08f51dd7a72492c9a293ee17e22
|
|
| BLAKE2b-256 |
c0b2f5a4401ee5ed9e8c466c20cca9b3984c1e23959106a192a8a7dd7489943a
|