Logo Sujal Magar
Learn Redis

Learn Redis

February 16, 2026
2 min read
Table of Contents

1. Introduction

Redis (Remote Dictionary Server) is an in-memory key-value data store used as a database, cache, and message broker.

Data is stored in RAM, making Redis extremely fast.


2. Key Features

  • In-memory storage
  • Persistence options
  • Pub/Sub messaging
  • Data structures support
  • High performance

3. Data Structures

  • Strings
r.set("name", "Alice")
  • Hashes
r.hset("user:1", mapping={"name": "Alice"})
  • Lists
r.rpush("tasks", "task1")
  • Sets
r.sadd("tags", "db")
  • Sorted Sets

Used for leaderboards.


4. Persistence

Two methods:

  • RDB snapshots
  • AOF (Append Only File)

5. Expiration (TTL)

r.set("temp", "value", ex=10)

6. Pub/Sub

Messaging system.

Publish:

r.publish("channel", "hello")

Subscribe via listeners.


7. Transactions

pipe = r.pipeline()
pipe.set("a", 1)
pipe.set("b", 2)
pipe.execute()

8. Caching Patterns

  • Cache-aside
  • Write-through
  • Write-behind

9. Use Cases

  • Session storage
  • Caching queries
  • Real-time analytics
  • Leaderboards
  • Queues

10. Advantages

  • Ultra fast
  • Lightweight
  • Rich data structures

11. Limitations

  • RAM dependent
  • Limited complex queries