Search code examples
pythondjangoredisdjango-redis

Django Redis appends same annotaion on key


I am using Django-Redis to store some simple data.

Everything works fine for me, but I am wondering why Django-Redis prepends to every key that I save the string :1:.

SET Key and Value (working)

cache.set("foo", "bar", timeout=100)

GET Key and Value (working)

print cache.get("foo") 

Redis CLI

 1) ":1:foo"

GET Key in CLI

GET foo
Result: (nil) 
GET :1:foo
Result: "\x80\x02U\x06barXq\x01."

Best regards


Solution

  • This is actually part of the Django cache API. Specifically, the cache backend transforms the key with a cache prefix (in your case, the empty string) and a version number (in your case, 1).

    The former allows servers to use a namespace to control collisions if they share the same cache backend, and the latter allows you to use versioning to avoid having to flush the database when you change the format of your cached data.