Skip to main content

Simple as dead support of Redis database for Flask apps.

Project description


Simple as dead support of Redis database for Flask apps.

.. note:: I named this ``Flask-And-Redis``, cause ``Flask-Redis`` name already
`taken <>`_, but that library didn't
match my needs.


* `Python <>`_ 2.6 or higher
* `Flask <>`_ 0.8 or higher
* `redis-py <>`_ 2.4 or higher



$ pip install Flask-And-Redis


``Flask-And-Redis`` is licensed under the `BSD License


As of ``py-redis`` 2.4.11 and 2.6.0 releases you should setup next options in
your settings module:

* ``REDIS_DB``

Later these values would initialize ``redis.Redis`` connection and all public
methods of that instance would be added to ``flask_redis.Redis`` instance for
easy use.

Also this connection would be stored in ``flask_redis.Redis.connection``
attribute and in ``app.extensions['redis']`` dict.


.. versionadded:: 0.2

Some times, your redis settings stored as ``redis://...`` url (like in Heroku
or DotCloud services), so you could to provide just ``REDIS_URL`` setting
and ``Flask-And-Redis`` auto parsed that value and will configure then valid
redis connection.

In case, when ``REDIS_URL`` provided all appropriate configurations, and other
keys are overwritten using their values at the present URI.

Config prefix

.. versionadded:: 0.4

Config prefix allows you to determine the set of configuration variables used
to configure ``redis.Redis`` connection. By default, config prefix ``REDIS``
would be used.

So when you want to initialize several ``redis`` connections, you need to::

from flask import flask
from flask.ext.redis import Redis

app = Flask(__app__)
app.config['REDIS_HOST'] = 'localhost'
app.config['REDIS_PORT'] = 6379
app.config['REDIS_DB'] = 0
redis1 = Redis(app)

app.config['REDIS2_URL'] = 'redis://localhost:6379/1'
redis2 = Redis(app, 'REDIS2')


In regular case all of you need is import ``Redis`` instance and initialize it
with ``app`` instance, like::

from flask import Flask
from flask.ext.redis import Redis

app = Flask(__name__)
redis = Redis(app)

If you use application factories you could use ``init_app`` method,

.. versionadded:: 0.3


redis = Redis()
# The later on
app = create_app('config.cfg')

Also later you can get ``redis`` connection from ``app.extensions['redis']``
dict, where ``key`` is config prefix and ``value`` is worked redis connection

Bugs, feature requests?

If you found some bug in ``Flask-And-Redis`` library, please, add new issue to
the project's `GitHub issues



+ Big refactor of ``Redis`` instance. Do not inherit ``redis.Redis`` class,
store active redis connection in ``Redis.connection`` attribute and
``app.extensions['redis']`` dict.
+ Add support of ``config_prefix`` keyword argument for ``Redis`` or
``init_app`` methods.
+ Support multiple redis connections in test application.


+ Fix problem while parsing ``REDIS_URL`` value, strip unnecessary slashes from
database path (like ``redis://localhost:6379/12/``).


+ Checked compability with ``redis-py`` version 2.6.0.
+ Added ``redis`` as install requirement in ````.


+ Move from ``flask_redis`` package to python module.
+ Little improvements for storing ``_flask_app`` attribute to ``Redis``


+ Implement ``init_app`` method.


+ Convert ``REDIS_PORT`` to an ``int`` instance.


+ Added support of ``REDIS_URL`` setting. By default, ``Redis`` will try to
guess host, port, user, password and db settings from that value.


* Initial release.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
Flask-And-Redis-0.4.tar.gz (5.2 kB) Copy SHA256 hash SHA256 Source None Sep 29, 2012

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page