1👍
The error you are gettting is not a data retreival error, the data is being retreived, but it is not in correct pickle format.
- When you are setting data manually, it is being set in byte format, not pickled format.
-
When you set data through django-redis, your data is first serialized using cPickle, and then stored into redis as pickled string.
-
When you retreive the data stored through django-redis, it is retreived as the pickle serialized string, and then deserialized into corresponding python datatype.
- Your manually entered data is string type, but not in correct pickle format, hence though it gets retreived, it cannot be converted into corresponding python type, and you get the pickling error.
- The solution is to use django-redis itself in the django shell or your code to store and retreive data, entering data manually breaks the serialization contract.
Example:
>>> from django.core.cache import cache
>>> cache.set("THE_KEY","aman")
True
>>> cache.get("THE_KEY")
'aman'
>>>
dhruv@dhruvpathak:~$ redis-cli
127.0.0.1:6379> keys *
1) ":1:THE_KEY"
127.0.0.1:6379> get ":1:THE_KEY"
"\x80\x02U\x04amanq\x01."
127.0.0.1:6379> set "THE_MANUAL_KEY" "aman"
OK
127.0.0.1:6379> get "THE_MANUAL_KEY"
"aman"
Source:stackexchange.com