diff --git a/README.rst b/README.rst index 0625ecda..acc355d2 100644 --- a/README.rst +++ b/README.rst @@ -16,6 +16,7 @@ The following health checks are bundled with this project: - AWS S3 storage - Celery task queue - Celery ping +- Redis - RabbitMQ - Migrations @@ -111,6 +112,8 @@ on django.conf.settings with the required format to connect to your redis server REDIS_URL = redis://localhost:6370 +Additional connection options may be specified by defining a variable ``HEALTHCHECK_REDIS_URL_OPTIONS`` on the settings module. + Setting up monitoring --------------------- diff --git a/docs/settings.rst b/docs/settings.rst index 96be9a44..7d189c98 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -90,3 +90,21 @@ Using `django.settings` you may exert more fine-grained control over the behavio - Number - 3 - Specifies the maximum total time for a task to complete and return a result, including queue time. + +Redis Health Check +------------------ + +The Redis health check allows customising the underlying connection: + +.. list-table:: Additional Settings + :widths: 25 10 10 55 + :header-rows: 1 + + * - Name + - Type + - Default + - Description + * - `HEALTHCHECK_REDIS_URL_OPTIONS` + - Dict + - {} + - Additional arguments which will be passed as keyword arguments to the Redis connection class initialiser. diff --git a/health_check/contrib/redis/backends.py b/health_check/contrib/redis/backends.py index 32e3cffc..ae77ae73 100644 --- a/health_check/contrib/redis/backends.py +++ b/health_check/contrib/redis/backends.py @@ -13,6 +13,7 @@ class RedisHealthCheck(BaseHealthCheckBackend): """Health check for Redis.""" redis_url = getattr(settings, "REDIS_URL", 'redis://localhost/1') + redis_url_options = getattr(settings, "HEALTHCHECK_REDIS_URL_OPTIONS", {}) def check_status(self): """Check Redis service by pinging the redis instance with a redis connection.""" @@ -21,7 +22,7 @@ def check_status(self): logger.debug("Attempting to connect to redis...") try: # conn is used as a context to release opened resources later - with from_url(self.redis_url) as conn: + with from_url(self.redis_url, **self.redis_url_options) as conn: conn.ping() # exceptions may be raised upon ping except ConnectionRefusedError as e: self.add_error(ServiceUnavailable("Unable to connect to Redis: Connection was refused."), e)