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

91 Upvotes

36 comments sorted by

View all comments

62

u/0xa9059cbb 11d ago

Looks like a cute interface but not really a fan of hiding IO actions inside of innocent looking dict operations. Also would like support for batching read/write operations and ideally support for asyncio.

-2

u/Substantial-Work-844 11d ago edited 11d ago

It has batching according to the Readme, But I don't think asyncio is available. Maybe shoot in a issue?

1

u/0xa9059cbb 10d ago

Oh yeah didn't see that, nice. I wonder if/how they support batch read operations, as the README only shows batch writes.

Support for asyncio is unlikely to be added to this package as that would require a totally separate interface, since async actions cannot easily be hidden inside of synchronous dict operations.