Skip to content

Commit bc5cb3c

Browse files
committed
now made DB optional, added new test cases
1 parent 31db5f0 commit bc5cb3c

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ python:
66
env:
77
- FLASK_VERSION=0.9 REDIS_VERSION=2.6.2
88
- FLASK_VERSION=0.9 REDIS_VERSION=2.7.4
9+
- FLASK_VERSION=0.9 REDIS_VERSION=2.10.3
910
- FLASK_VERSION=0.10 REDIS_VERSION=2.6.2
1011
- FLASK_VERSION=0.10 REDIS_VERSION=2.7.4
12+
- FLASK_VERSION=0.10 REDIS_VERSION=2.10.3
1113
install:
1214
- "pip install -r requirements.txt"
1315
- "pip install -I Flask==$FLASK_VERSION"
@@ -19,3 +21,5 @@ matrix:
1921
env: FLASK_VERSION=0.9 REDIS_VERSION=2.6.2
2022
- python: "3.3"
2123
env: FLASK_VERSION=0.9 REDIS_VERSION=2.7.4
24+
- python: "3.3"
25+
env: FLASK_VERSION=0.9 REDIS_VERSION=2.10.3

flask_redis.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
class Redis(object):
77

8-
converters = {'port': int}
9-
108
def __init__(self, app=None, config_prefix=None):
119
"""
1210
Constructor for non-factory Flask applications
@@ -29,13 +27,9 @@ def init_app(self, app):
2927
)
3028

3129
self.app.config.setdefault(self.key('URL'), 'redis://localhost:6379')
32-
self.app.config.setdefault(self.key('DATABASE'), 0)
3330

3431
db = self.app.config.get(self.key('DATABASE'))
3532

36-
if not str(db).isdigit() or not isinstance(db, int):
37-
raise ValueError('A valid DB must be supplied')
38-
3933
self.connection = connection = RedisClass.from_url(
4034
self.app.config.get(self.key('URL')),
4135
db=db,

test_flask_redis.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,15 @@ def test_custom_prefix(self):
3232
self.app.config['DB2_DATABASE'] = 1
3333
self.db2_redis.init_app(self.app)
3434

35+
self.db3_redis = Redis(config_prefix='DB3')
36+
self.app.config['DB3_URL'] = "redis://localhost:6379"
37+
self.db3_redis.init_app(self.app)
38+
39+
self.db4_redis = Redis(config_prefix='DB4')
40+
self.app.config['DB4_URL'] = "redis://localhost:6379/5"
41+
self.db4_redis.init_app(self.app)
42+
3543
assert self.db1_redis.get('potato') is None
3644
assert self.db2_redis.get('potato') is None
45+
assert self.db3_redis.get('potato') is None
46+
assert self.db4_redis.get('potato') is None

0 commit comments

Comments
 (0)