I am using django 3.0.4 and python 3.6.9. I have to use hset operation to set some values in redis cache.
- My try:
from django.core.cache import caches
cache.set(), cache.get() // these operation are working
But I am not able to use hset and hget operation using this library. There is no proper documentation about this in Django official docs.
Note: I have referred this (Not A copy)
3
Answers
This is how I resolved the issue:
Settings.py:
In views.py ::
Hope this will help. Docs: Django-redis-cache
Hey @Sanu Your importing line is wrong Please import cache not caches. I am surprised how are you running with “caches”.
Simple:
To store in cache:
To fetch. specific key from specific hash:
To fetch all the keys for that
hash
, use:hgetall
returndict
:and to delete the hash set: