简体   繁体   中英

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)

: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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM