diff gpp/core/services.py @ 508:6f5fff924877

Created a centralized spot to get a Redis connection so that settings can be managed in one place.
author Brian Neal <bgneal@gmail.com>
date Sun, 04 Dec 2011 19:53:27 +0000
parents
children f72ace06658a
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/core/services.py	Sun Dec 04 19:53:27 2011 +0000
@@ -0,0 +1,21 @@
+"""
+This module provides a common way for the various apps to integrate with services
+that are installed at this site.
+
+"""
+from django.conf import settings
+import redis
+
+# Redis connection and database settings
+
+REDIS_HOST = getattr(settings, 'REDIS_HOST', 'localhost')
+REDIS_PORT = getattr(settings, 'REDIS_PORT', 6379)
+REDIS_DB = getattr(settings, 'REDIS_DB', 0)
+
+
+def get_redis_connection(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB):
+    """
+    Create and return a Redis connection using the supplied parameters.
+
+    """
+    return redis.Redis(host=host, port=port, db=db)