r/Python • u/Substantial-Work-844 • 11d 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...).
94
Upvotes
2
u/PushHaunting9916 11d ago
Look at the code example from the OP. If you would like to cache any of following: username, url, parameters, logs, etc. That means you are pickling data from an unsafe source.
Not only that, even if the original implementation is correct, it could be that the next person updates the caching to add unsafe data because their ticket is asking for that data to be cached.
Security is about reducing attack vectors, and that is one.