[Django]-Django Redis cache values

5👍

Libraries usually use several internal prefixes to store keys in redis, in order not to be mistaken with user defined keys.

For example, django-redis-cache, prepends a “:1:” to every key you save into it.

So for example when you do r.set('foo', 'bar'), it sets the key to, “:1:foo”. Since you don’t know the prefix prepended to your key, you can’t get the key using a normal get, you have to use it’s own API to get.

r.set('foo', 'bar')

r.get('foo') # None
r.get(':1:foo') # bar

So in the end, it returns to the library you use, go read the code for it and see how it exactly saves the keys. redis-cli can be your valuable friend here. Basically set a key with cache.set('foo', 'bar'), and go into redis-cli and check with ‘keys *’ command to see what key was set for foo.

👤SpiXel

Leave a comment