Flask-And-RedisSimple as dead support of Redis database for Flask apps | |
Download |
Flask-And-Redis Ranking & Summary
Advertisement
- License:
- BSD License
- Price:
- FREE
- Publisher Name:
- Igor Davydenko
- Publisher web site:
- http://github.com/playpauseandstop/
Flask-And-Redis Tags
Flask-And-Redis Description
Flask-And-Redis is a simple Flask extension that provides support of Redis database for Flask apps.Installationpip install Flask-And-RedisConfigurationAs 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_PATHThen all of these args would be sent to redis.Redis.__init__ method.UsageBasicfrom flask import Flaskfrom flask.ext.redis import Redisapp = Flask(__name__)redis = Redis(app)Test applicationtestapp/app.pyfrom flask import Flask, redirect, url_forfrom flask.ext.redis import Redisfrom testapp import settings# Initialize simple Flask applicationapp = Flask(__name__)app.config.from_object(settings)# Setup Redis conectionredis = Redis(app)# Add two simple views: One for forgetting counter@app.route('/forget-us')def forget_us(): key = app.config redis.delete(key) return redirect(url_for('home'))# Second for remembering visiting counter@app.route('/')def home(): key = app.config counter = redis.incr(key) message = 'Hello, visitor!' if counter != 1: message += "\nThis page viewed %d time(s)." % counter return messagetestapp/settings.pyCOUNTER_KEY = 'testapp:counter'REDIS_HOST = 'localhost'REDIS_PORT = 6379REDIS_DB = 0Bugs, feature requests?If you found some bug in Flask-And-Redis library, please, add new issue to the project's GitHub issues.Product's homepage
Flask-And-Redis Related Software