1
1
import warnings
2
- from redis import Redis as _Redis
2
+ try :
3
+ import redis
4
+ except ImportError :
5
+ # We can allow custom provider only usage without redis-py being installed
6
+ redis = None
3
7
4
8
__all__ = ('Redis' , 'FlaskRedis' )
5
9
__version__ = '0.0.6'
6
10
7
11
8
12
class FlaskRedis (object ):
9
- def __init__ (self , app = None , config_prefix = 'REDIS' ):
13
+ def __init__ (self , app = None , strict = False , config_prefix = 'REDIS' ):
10
14
self ._provider_class = None
11
15
self ._redis_client = None
12
16
self .config_prefix = config_prefix
13
17
14
18
if app is not None :
15
- self .init_app (app )
19
+ self .init_app (app , strict )
16
20
17
21
@classmethod
18
22
def from_custom_provider (cls , provider , app = None , ** kwargs ):
@@ -27,9 +31,11 @@ def from_custom_provider(cls, provider, app=None, **kwargs):
27
31
instance .init_app (app )
28
32
return instance
29
33
30
- def init_app (self , app ):
34
+ def init_app (self , app , strict = False ):
31
35
if self ._provider_class is None :
32
- self ._provider_class = _Redis
36
+ self ._provider_class = (
37
+ redis .StrictRedis if strict else redis .Redis
38
+ )
33
39
34
40
redis_url = app .config .get (
35
41
'{0}_URL' .format (self .config_prefix ), 'redis://localhost:6379/0'
0 commit comments