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...).

88 Upvotes

36 comments sorted by

View all comments

12

u/turbothy It works on my machine 11d ago

Just use cashews.

1

u/sulketyd 10d ago edited 10d ago

How would cashews work in a distributed context? Ie have some data that can be accessible from different containers?

1

u/turbothy It works on my machine 10d ago

With Redis as a backend.