bradmontgomery / django-redis-metrics

Metrics for django apps backed by Redis.
http://django-redis-metrics.readthedocs.io
MIT License
93 stars 24 forks source link

Support pluggable Redis backends such as django-redis #49

Closed smaccona closed 8 years ago

smaccona commented 8 years ago

As it currently stands, django-redis-metrics offers basic Redis support for a single connection to a single Redis database. While this is fine for simple standalone installations, it does not support environments where something like Redis Sentinel is being used for multiple master/slave discovery.

django-redis has support for arbitrary Redis connection classes, so that different classes can be plugged into the cache system to allow it to take advantage of things like Redis Sentinel or Hiredis.

django-redis also exposes a simple django_redis.get_redis_connection() which will return whatever Redis client is configured in your cache configuration.

I propose a feature which can take advantage of this:

Here's an example:

REDIS_METRICS = {
   'CONNECTION_CLASS': 'django_redis.get_redis_connection',
   'MIN_GRANULARITY': 'daily',
   'MAX_GRANULARITY': 'yearly',
   'MONDAY_FIRST_DAY_OF_WEEK': False,
}

This will call get_redis_connection() from the django_redis package to get a Redis client (which in turn may have something like django-redis-sentinel configured as its own default client class). You may of course use your own class/function, as long as it returns a Redis client.

I will make a PR for this functionality as it is relatively straightforward to implement.

bradmontgomery commented 8 years ago

New version is up on pypi: https://pypi.python.org/pypi/django-redis-metrics/1.1.0

thanks again for this work!