What is Redis?
Redis is an in-memory data store. It keeps all its data in RAM, so reads and writes take well under a millisecond. Apps use it next to their main database for the jobs that need to be fast:
| Use case | Example |
|---|---|
| Caching | Store an expensive query result for 60 seconds |
| Sessions | Who's logged in, with automatic expiry |
| Rate limiting | Max 100 API requests per minute per user |
| Queues | Background jobs: send emails, resize images |
| Leaderboards | Top 10 players, updated in real time |
| Real-time messaging | Chat, notifications, live dashboards |
| Counters | Page views, likes, stock levels |
Redis was created by Salvatore Sanfilippo in 2009, and its name stands for REmote DIctionary Server. It's a key-value store, but the values have types: strings, lists, hashes, sets, sorted sets, streams and more. Each type has its own commands, and they all run atomically.
ℹ️ Licences: in 2024 Redis changed from the BSD licence to source-available licences, and the Linux Foundation started an open source fork called Valkey. Redis 8 (2025) added the open source AGPL licence as an option. Valkey and Redis share the same commands, so everything in this track works on both.
Why is it so fast?
- Data lives in memory, not on disk.
- Commands run one at a time on a single main thread, so there's no locking overhead, and every command is atomic.
- Data structures are carefully optimised (small lists and hashes use compact encodings).
The trade-off: RAM is limited and more expensive than disk, so Redis usually holds hot data, not everything. It can save data to disk (lesson 9), but most teams treat it as a fast layer next to a primary database such as PostgreSQL or MongoDB.
The redis-cli simulator
You talk to Redis by sending commands. The editors in this track are a simulated redis-cli: type commands, one per line, and press ▶ Run. Lines starting with # are comments.
What the replies mean:
| Reply | Meaning |
|---|---|
PONG, OK |
Simple status replies |
"Hello, Redis!" |
A string value |
(nil) |
Nothing there |
(integer) 5 |
A number |
1) "a" 2) "b" |
A list of values |
(error) … |
Something went wrong |
After a run, you can keep typing commands in the prompt underneath, as in a real terminal (↑ recalls previous commands). Type HELP to see every command the simulator supports.
Keys
Every value lives under a key. Keys are strings, and the convention is to namespace them with colons:
Good key names are readable and predictable: object-type:id:field, such as session:8f2c… or cache:products:page:2.
Installing Redis for real
Docker:
docker run -d --name redis -p 6379:6379 redis:8
docker exec -it redis redis-climacOS: brew install redis && brew services start redis
Linux: sudo apt install redis-server
Windows: use Docker or WSL.
Cloud: Redis Cloud, AWS ElastiCache, Upstash, Google Memorystore and Azure Cache all offer managed Redis (or Valkey).
Redis listens on port 6379. Connect with redis-cli, or a URL in your app: redis://localhost:6379. Graphical tools: Redis Insight (official) and others.
Using Redis from code
// Node.js: npm install redis
import { createClient } from 'redis';
const redis = await createClient({ url: process.env.REDIS_URL }).connect();
await redis.set('greeting', 'Hello!');
const value = await redis.get('greeting'); // 'Hello!'
await redis.incr('page:home:views');# Python: pip install redis
import redis
r = redis.Redis.from_url(os.environ["REDIS_URL"], decode_responses=True)
r.set("greeting", "Hello!")
print(r.get("greeting"))The commands map one to one: if you know them in redis-cli, you know them in every language.
Practice
- Store your name under
me:nameand your city underme:city, then read them back. - List all keys starting with
me:. - Delete one and check that
EXISTSreturns 0.
1.Why is Redis so fast?
2.Which is a typical use of Redis?
3.What does (nil) mean in a reply?