Simple as dead support of Redis database for Flask apps.
Project description
Simple as dead support of Redis database for Flask apps.
Requirements
Installation
$ pip install Flask-And-Redis
License
Flask-And-Redis is licensed under the BSD License.
Configuration
As of py-redis 2.4.11 release you should setup next options in your settings module:
REDIS_HOST
REDIS_PORT
REDIS_DB
REDIS_PASSWORD
REDIS_SOCKET_TIMEOUT
REDIS_CONNECTION_POOL
REDIS_CHARSET
REDIS_ERRORS
REDIS_UNIX_SOCKET_PATH
Then all of these args would be sent to redis.Redis.__init__ method.
Usage
Basic
from flask import Flask from flask.ext.redis import Redis app = Flask(__name__) redis = Redis(app)
Test application
testapp/app.py
from flask import Flask, redirect, url_for from flask.ext.redis import Redis from testapp import settings # Initialize simple Flask application app = Flask(__name__) app.config.from_object(settings) # Setup Redis conection redis = Redis(app) # Add two simple views: One for forgetting counter @app.route('/forget-us') def forget_us(): key = app.config['COUNTER_KEY'] redis.delete(key) return redirect(url_for('home')) # Second for remembering visiting counter @app.route('/') def home(): key = app.config['COUNTER_KEY'] counter = redis.incr(key) message = 'Hello, visitor!' if counter != 1: message += "\nThis page viewed %d time(s)." % counter return message
testapp/settings.py
COUNTER_KEY = 'testapp:counter' REDIS_HOST = 'localhost' REDIS_PORT = 6379 REDIS_DB = 0
Bugs, feature requests?
If you found some bug in Flask-And-Redis library, please, add new issue to the project’s GitHub issues.
Changelog
0.2.1
Convert REDIS_PORT to an int instance.
0.2
Added support of REDIS_URL setting. By default, Redis will try to guess host, port, user, password and db settings from that value.
0.1
Initial release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file Flask-And-Redis-0.2.1.tar.gz
.
File metadata
- Download URL: Flask-And-Redis-0.2.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7aee947d1a72813100af26e3336102078f8f5fb7d6c9e428b0b3fb45a33788b7 |
|
MD5 | 369ca3cdb7c237297303248c5488c273 |
|
BLAKE2b-256 | 36c54a411201992ab70e0f5e89f24df01267771760e3d2020e43c70fcc957b53 |