diff gpp/antispam/rate_limit.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 32cec6cd8808
children 6a265b5768ca
line wrap: on
line diff
--- a/gpp/antispam/rate_limit.py	Sun Dec 04 03:05:21 2011 +0000
+++ b/gpp/antispam/rate_limit.py	Sun Dec 04 19:53:27 2011 +0000
@@ -8,14 +8,11 @@
 import redis
 from django.conf import settings
 
+from core.services import get_redis_connection
+
 
 logger = logging.getLogger(__name__)
 
-# Redis connection and database settings
-HOST = getattr(settings, 'RATE_LIMIT_REDIS_HOST', 'localhost')
-PORT = getattr(settings, 'RATE_LIMIT_REDIS_PORT', 6379)
-DB = getattr(settings, 'RATE_LIMIT_REDIS_DB', 0)
-
 
 # This exception is thrown upon any Redis error. This insulates client code from
 # knowing that we are using Redis and will allow us to use something else in the
@@ -37,7 +34,7 @@
     Create and return a Redis connection. Returns None on failure.
     """
     try:
-        conn = redis.Redis(host=HOST, port=PORT, db=DB)
+        conn = get_redis_connection()
     except redis.RedisError, e:
         logger.error("rate limit: %s" % e)
         raise RateLimiterUnavailable