Junior — Middle
Can you explain what Redis is and what it is used for?
sobes.tech AI
Answer from AI
Redis is a high-performance in-memory open-source data store, often used as a database, cache, and message broker.
Main characteristics of Redis:
- Stores data in memory, providing very fast operations.
- Supports various data structures: strings, lists, sets, hashes, sorted sets, etc.
- Allows efficient operations on these structures.
Applications of Redis:
- Caching data to speed up access.
- Storing user sessions.
- Implementing queues and publish/subscribe systems.
- Supporting counters and rankings.
Example of using Redis in Python with redis-py library:
import redis
r = redis.Redis(host='localhost', port=6379, db=0)
r.set('key', 'value')
print(r.get('key')) # b'value'
Redis is widely used for real-time analytics, caching, message queuing, and pub/sub systems.