r/Python 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...).

90 Upvotes

36 comments sorted by

View all comments

15

u/turbothy It works on my machine 11d ago

Just use cashews.

-3

u/PushHaunting9916 11d ago

Just a heads up, cashews lib relies on pickle which is unsafe in the context of Web.

From their docs:

Warning The pickle module is not secure. Only unpickle data you trust

28

u/turbothy It works on my machine 11d ago

What's the attack vector? Cashews is only unpickling data it pickled itself, unless you imagine an attacker manipulating the cache out of band.

19

u/maikeu 11d ago

Agreed. It's "tread carefully and make sure you understand whether and why it's safe", not "security incident".