django-environ
django-environ copied to clipboard
django-environ doesn't parse redis unix socket location properly
Cache connection string
CACHE_URL="rediscache:///var/run/redis/redis-server.sock?db=3&client_class=django_redis.client.DefaultClient"
is incorrectly parsed as:
{'default': {'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'unix:///var/run/redis/redis-server.sock',
'OPTIONS': {'DB': 3, 'CLIENT_CLASS': 'django_redis.client.DefaultClient'}}}
DB
shouldn't go into OPTIONS
, it should be appeneded to the unix socket url:
unix:///var/run/redis/redis-server.sock?db=3
Because django-environ doesn't report an error, this can have a very dangerous consequences: you can use redis cache for months only to discover that it always used the default first db instead. Potentially this can lead to data loss.
CACHE_URL parsing does not seem to support quoted values (at least not when quoted with '
)
So this maybe works unless there are other issues as well:
CACHE_URL=rediscache:///var/run/redis/redis-server.sock?db=3&client_class=django_redis.client.DefaultClient
@thomasf As far as I remember the problem is not in quoting. Problem is somewhere either in django-environ
or django-redis
. One of the packages or both do not properly handle specifying db when using Unix socketsfor cache. This is probably why the problem went unnoticed - it's very hard to notice that your cache values are stored in a different redis db unless you run several instances of the same app on a single server (my case).
I've tried to find and fix the problem but after wasting three hours just reverted back to using TCP sockets.