From d4e7774623acd2ada9b318ea02681f2383acacaa Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 12 Jun 2011 20:54:32 -0400 Subject: [PATCH] database connect module --- httpbin/db.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 httpbin/db.py diff --git a/httpbin/db.py b/httpbin/db.py new file mode 100644 index 0000000..f3b4baa --- /dev/null +++ b/httpbin/db.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +""" +dashboard.db +~~~~~~~~~~~~ + +This module provides the Dashboard database interface. + +""" + +from redis import Redis + + +__all__ = ('redis_connect',) + + + +def redis_connect(): + """Connect to appropriate Redis system. Returns Redis instance. """ + + try: + # ep.io configuration + from bundle_config import config + r = Redis( + host = config['redis']['host'], + port = int(config['redis']['port']), + password = config['redis']['password'], + ) + except ImportError: + # TODO: use local settings (env?) + r = Redis(host='localhost', port=6379, db=0) + + return r \ No newline at end of file