| |
@@ -8,7 +8,7 @@
|
| |
import pickle
|
| |
from datetime import timedelta
|
| |
from uuid import uuid4
|
| |
- from redis import Redis
|
| |
+ from redis import StrictRedis
|
| |
from werkzeug.datastructures import CallbackDict
|
| |
from flask.sessions import SessionInterface, SessionMixin
|
| |
|
| |
@@ -28,9 +28,8 @@
|
| |
serializer = pickle
|
| |
session_class = RedisSession
|
| |
|
| |
- def __init__(self, redis=None, prefix='session:'):
|
| |
- if redis is None:
|
| |
- redis = Redis()
|
| |
+ def __init__(self, redis, prefix='session:'):
|
| |
+ assert isinstance(redis, StrictRedis)
|
| |
self.redis = redis
|
| |
self.prefix = prefix
|
| |
|
| |
@@ -68,10 +67,7 @@
|
| |
|
| |
time_exp = int(redis_exp.total_seconds())
|
| |
key_exp = self.prefix + session.sid
|
| |
- if isinstance(self.redis, Redis):
|
| |
- self.redis.setex(key_exp, val, time_exp)
|
| |
- else:
|
| |
- self.redis.setex(key_exp, time_exp, val)
|
| |
+ self.redis.setex(key_exp, time_exp, val)
|
| |
|
| |
response.set_cookie(app.session_cookie_name, session.sid,
|
| |
expires=cookie_exp, httponly=True,
|
| |
To avoid additional version checking/API checking, use StrictRedis
which has consistent setex() API across v2/3.
Per upstream docs:
2.X users that are using the Redis class will have to make
changes if they use any of the following commands:
- SETEX: The argument order has changed. The new order is (name,
time, value).