Junior — Middle
Could you list the main use cases of Redis?
sobes.tech AI
Answer from AI
Redis is a high-performance in-memory data store often used for:
- Caching: speeding up access to frequently used data, reducing load on the database.
- Session storage: saving user state in web applications.
- Message queues: implementing task queues using Redis data structures (e.g., lists).
- Counting and analytics: storing counters, ratings, and real-time statistics.
- Pub/Sub: message exchange between system components.
Example of using Redis for caching in Python with the redis-py library:
import redis
r = redis.Redis(host='localhost', port=6379, db=0)
# Setting a value with a key
r.set('user:1', 'John Doe')
# Getting a value by key
user = r.get('user:1')
print(user.decode('utf-8')) # John Doe