DEV Community

Valia Havryliuk
Valia Havryliuk

Posted on

Redis client-side cache with async Python

We can’t imagine a modern application that uses cache without Redis, because Redis is the most powerful and fast storage. It also supports different kinds of data structures and provides everything needed to build effective caching. Here I will highlight one feature that was released with Redis 6.0 and explain how you can use it with async python: client-side caching.

What is client-side caching?

Imagine that you have an application that uses Redis to store cache values. To get value from Redis you should connect to a server, build command and pack it, send the data to a socket, wait a bit, receive a response, and unpack it. This is fast, but what if you want get data faster?

What if you could have a copy of some values in your application’s memory? This means that when you write to Redis or get values from it you also store the key and the value in memory. However, you need to keep a consistent copy, because typically you will have more than one copy of the application or you can have another application that can change a value in Redis storage. You need a way to know when a value has expired or someone has rewritten it.

Starting from version 6.0 Redis provides a mechanism to make this simple. The application can subscribe for changes and after that receive messages that values have mutated/expired. Two different strategies are available. You can...

Learn more: https://medium.com/the-pandadoc-tech-blog/redis-client-side-cache-with-async-python-6228a0121a12

Discussion (0)