Code Reference

Getting Started with Redis

Redis · Reference cheat sheet

Getting Started with Redis

Redis · Reference cheat sheet


📋 Overview

Redis is an in-memory data structure server used for caching, sessions, queues, rate limits, and pub/sub. Data structures are first-class (strings, hashes, lists, sets, sorted sets).

🔧 Core concepts

IdeaMeaning
KeyString name for a value
TTLOptional expiry on keys
Single-threaded command executionCommands are atomic per command
PersistenceOptional RDB/AOF durability
DB indexLogical keyspaces 0–15 (default config)
CommandPurpose
redis-cliInteractive client
PINGHealth check → PONG
INFOServer stats
SELECT nSwitch DB index

💡 Examples

Run Redis (Docker):

docker run --rm -p 6379:6379 redis:7-alpine

First commands:

redis-cli
> PING
PONG
> SET greeting "hello"
OK
> GET greeting
"hello"

From Node sketch:

import { createClient } from "redis";
const client = createClient({ url: "redis://127.0.0.1:6379" });
await client.connect();
await client.set("greeting", "hello");

⚠️ Pitfalls

  • Memory is finite — without eviction policy + TTLs, Redis can OOM.
  • Treating Redis as the only source of truth without persistence/HA is risky.
  • Key naming collisions across features — use prefixes (app:session:).

On this page