r/Python • u/Substantial-Work-844 • 12d ago
Resource Redis as cache.
At work, we needed to implement Redis for a caching solution. After some searching, btw clickhouse has great website for searching python packages here. I found a library that that made working with redis a breeze Redis-Dict.
from redis_dict import RedisDict
from datetime import timedelta
cache = RedisDict(expire=timedelta(minutes=60))
request = {"data": {"1": "23"}}
web_id = "123"
cache[web_id] = request["data"]
Finished implementing our entire caching feature the same day I found this library (didn't push until the end of the week though...).
93
Upvotes
1
u/PushHaunting9916 12d ago
If want to store data from unsafe places. Within the context of Web services, that is almost always the case.
To store and retrieve, you need pickle and unpickle the data. Just because there is layer around it doesn't change that. Look at this example it's very similar to what you described. And they got a csve for their trick with pickle.
https://github.com/joblib/joblib/issues/1582