deep-dive
What is Redis?

Redis stands for REmote DIctionary Server.
Redis is an in-memory NoSQL data store that is commonly used as a cache, database, or message broker. In many architectures, it sits between the application layer and a primary database to reduce database load and improve response times.
Unlike traditional databases that primarily store data on disk, Redis stores data in memory (RAM). Because memory access is significantly faster than disk access, Redis can deliver extremely low latency and high throughput.
If Redis runs purely in memory and the server restarts, the data would normally be lost. However, Redis provides optional persistence mechanisms that allow data to be saved to disk, balancing performance with durability.

Traditional databases such as SQL databases or MongoDB store data in tables or document models. Redis instead stores data using a key–value model, where each key maps to a specific value.
Redis is frequently used for caching, where frequently accessed data is stored temporarily in memory. Keys can be assigned a TTL (Time To Live), which automatically removes the data after a specified time.
Because Redis operates in memory, it is particularly useful for real-time systems, high-traffic applications, and workloads requiring very fast read/write operations.
Redis also supports several data structures, including:
- Strings
- Lists
- Hashes
- Sets
- Sorted Sets
Each data structure has its own set of commands for reading and writing data.
For example, storing a simple key–value pair:
127.0.0.1:6379> SET name "ufraan"
OK
127.0.0.1:6379> GET name
"ufraan"
Redis does not enforce any schema or rigid structure for keys. This gives developers significant flexibility in how data is organized and stored.
Uses
1. Caching
Frequently accessed data can be stored in Redis instead of repeatedly querying the primary database. This reduces database load and significantly improves response times.
2. Leaderboards
Redis sorted sets are commonly used to build real-time leaderboards. Because sorted sets maintain automatic ordering by score, retrieving ranked data becomes efficient.
3. Session Storage
User session information can be stored in Redis with built-in expiration times, making it useful for managing login sessions or authentication tokens.
4. Rate Limiting
Counters with expiration times can be used to limit how often an API endpoint can be accessed, helping prevent abuse or excessive requests.
5. Many Other Use Cases
Redis is also widely used for pub/sub messaging, queues, analytics counters, and real-time data processing.
Redis is best suited for systems where speed, scalability, and low latency are more critical than complex relational queries.
Redis Lists
In addition to simple key–value pairs, Redis supports several data structures. One of the most commonly used is the List.
A Redis list is an ordered collection of elements, stored under a single key.
Elements are stored in the order they are inserted, and new elements can be added to either the left (beginning) or the right (end) of the list.

Lists are often used to implement:
- queues
- stacks
- job processing systems
- message pipelines
Conceptually, a Redis list behaves similarly to an array or linked list, where elements maintain their order.
numbers → [1, 2, 3, 4]
Creating a List
Lists are created automatically when elements are pushed into a key.
Two primary commands are used:
LPUSH→ insert element at the leftRPUSH→ insert element at the right
Example:
127.0.0.1:6379> LPUSH numbers 3
(integer) 1
127.0.0.1:6379> LPUSH numbers 2
(integer) 2
127.0.0.1:6379> LPUSH numbers 1
(integer) 3
The list now becomes:
numbers → [1, 2, 3]
Using RPUSH:
127.0.0.1:6379> RPUSH numbers 4
(integer) 4
Now the list becomes:
numbers → [1, 2, 3, 4]
Retrieving List Elements
To read elements from a list, Redis provides the LRANGE command.
LRANGE key start stop
Example:
127.0.0.1:6379> LRANGE numbers 0 -1
1) "1"
2) "2"
3) "3"
4) "4"
0 refers to the first element.
-1 means the last element of the list, so 0 -1 returns the entire list.
Removing Elements
Elements can also be removed from either end of the list.
LPOP
Removes and returns the leftmost element.
127.0.0.1:6379> LPOP numbers
"1"
List becomes:
numbers → [2, 3, 4]
RPOP
Removes and returns the rightmost element.
127.0.0.1:6379> RPOP numbers
"4"
List becomes:
numbers → [2, 3]
Checking List Length
Redis can also return the number of elements inside a list.
127.0.0.1:6379> LLEN numbers
(integer) 2
Common Use Case: Queue
Redis lists are frequently used to implement queues.
Example:
RPUSH jobs "email_user"
RPUSH jobs "generate_report"
RPUSH jobs "send_notification"
Worker processes can then consume jobs using:
LPOP jobs
This creates a simple FIFO queue (First In, First Out).