djangocachingredisdjango-cachedjango-redis

Django and redis adding :1 to keys


I'm using django-redis to store some data on my website, and I have a problem where Redis is adding :1 at the beginning so my key looks like this: :1:my_key

I'm not sure why is it doing this, I've read the documentation on django-redis and I couldn't find anything related, so my guess it has something to do with redis but I can't figure out what.

In my settings.py I have the regular:

CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://xxxxx/0",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
       }
   }
}

And in my tasks.py I set keys like the documentation says:

from django.core.cache import cache
cache.set(my_key, my_value, 3600)

So now I can't get the values using the cache.get(my_key)


Solution

  • :1 it's version

    cache.set(key, value, timeout=DEFAULT_TIMEOUT, version=None)

    You can remove it by set empty string:

    cache.set("foo", "bar",version='')

    In the redis you will get:

    ::foo