Junior
What is Redis and what is it used for?
sobes.tech AI
Answer from AI
Redis (Remote Dictionary Server) is a fast, distributed, in-memory key-value data store. It is used as:
- Cache: Its high read/write speed makes it ideal for caching frequently used data, reducing load on primary databases.
- Message Broker: Supports Pub/Sub patterns and list operations, useful for implementing message queues and real-time systems.
- Session Store: Due to its speed and support for distributed scenarios, suitable for storing user sessions in web applications.
- Distributed Locking: Commands like
SET NXwith TTL can be used to implement simple distributed locking. - Rate Limiter: Using atomic operations on strings or lists, mechanisms to limit the number of requests from clients can be implemented.
Key features:
- In-Memory Data Structure Store: Stores data in RAM for maximum access speed. Supports persistence (RDB and AOF) for data recovery after restart.
- Support for various data structures: Strings, lists, sets, hashes, sorted sets, bitmaps, hyperloglogs.
- Atomic operations: Most Redis operations are atomic, simplifying work in multithreaded environments.
- Scalability: Supports replication (Master-Replica) and clustering for horizontal scaling and high availability.
Example Redis command:
// Set the value of the key "mykey" to "hello" with a TTL of 60 seconds
SET mykey "hello" EX 60