| 1 |
Example |
| 2 |
--------------------- |
| 3 |
|
| 4 |
Here is an example of how to configure a redis backend: |
| 5 |
|
| 6 |
.. code-block:: python |
| 7 |
|
| 8 |
app.config['SESSION_TYPE'] = 'redis' |
| 9 |
app.config['SESSION_REDIS'] = Redis.from_url('redis://127.0.0.1:6379') |
| 10 |
|
| 11 |
We are not supplying something like ``SESSION_REDIS_HOST`` and |
| 12 |
``SESSION_REDIS_PORT``, instead you should configure ``SESSION_REDIS`` to your own :meth:`redis.Redis` instance. |
| 13 |
This gives you more flexibility, such as using the same instance for cache purposes too, then you do not need to keep |
| 14 |
two instances in the same process. |
| 15 |
|
| 16 |
If you do not set ``SESSION_REDIS``, Flask-Session will assume you are developing locally and create a |
| 17 |
:meth:`redis.Redis` instance for you. It is expected you supply an instance of |
| 18 |
:meth:`redis.Redis` in production. |
| 19 |
|
| 20 |
.. note:: |
| 21 |
|
| 22 |
By default, sessions in Flask-Session are permanent with an expiration of 31 days. |