Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 7d8951845505746e564923c3f3104b17883b3d85 1 parent 2061d2f
Igor Davydenko authored
Showing with 14 additions and 1 deletion.
  1. +1 −0  README.rst
  2. +7 −1 flask_redis/__init__.py
  3. +6 −0 testapp/tests.py
1  README.rst
View
@@ -125,6 +125,7 @@ Changelog
0.2
---
++ 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.
8 flask_redis/__init__.py
View
@@ -45,6 +45,7 @@ def __init__(self, app):
REDIS_URL = os.environ.get('REDISTOGO_URL', REDIS_URL)
"""
+ converters = {'port': int}
url = app.config.get('REDIS_URL')
if url:
@@ -70,7 +71,12 @@ def __init__(self, app):
if not redis_arg in app.config:
continue
- kwargs.update({arg: app.config.get(redis_arg)})
+ value = app.config.get(redis_arg)
+
+ if arg in converters:
+ value = converters[arg](value)
+
+ kwargs.update({arg: value})
super(Redis, self).__init__(**kwargs)
setattr(self, '_flask_app', app)
6 testapp/tests.py
View
@@ -80,6 +80,12 @@ def test_default_behaviour(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, 'Hello, visitor!')
+ def test_default_behaviour_string_port(self):
+ app.config['REDIS_PORT'] = str(app.config['REDIS_PORT'])
+
+ obj = Redis(app)
+ obj.ping()
+
def test_default_behaviour_url(self):
host = app.config.pop('REDIS_HOST')
port = app.config.pop('REDIS_PORT')
Please sign in to comment.
Something went wrong with that request. Please try again.