Command Palette

Search for a command to run...

Hectal
PHASE 0Beginner ~14 min· topic 3 of 5

Topic 0.3

Your Redis Lab: Docker, redis-cli, Insight, and Valkey

In one line

Set up a local lab you'll reuse all course: Redis and Valkey in Docker, redis-cli fluency, RedisInsight for browsing, and the handful of commands that tell you what a server is and how it's configured.

0/5 · 0%

Think of it like this

A flight simulator. Pilots rehearse engine failures on the ground where mistakes are free. Your lab is where you'll run DEBUG SLEEP, kill primaries and fill memory on purpose, so production never sees those experiments first.

Key ideas

  1. 01

    Run Redis with Docker: docker run -d --name redis -p 6379:6379 redis:8 gives you Redis Open Source 8 with JSON, search, time series and probabilistic structures built in. valkey/valkey:8 gives you Valkey. Both speak the same protocol, so redis-cli works with either.

  2. 02

    redis-cli is the tool you'll use most: interactive mode (redis-cli), one-shot commands (redis-cli GET key), --scan --pattern 'user:*' for safe key iteration, --bigkeys and --memkeys for size analysis, --latency for latency, --stat for a live dashboard, and -c for cluster mode (follows MOVED redirects).

  3. 03

    Know your server before debugging it: INFO server (version, mode, uptime), INFO memory, CONFIG GET maxmemory*, DBSIZE, CLIENT LIST, COMMAND DOCS SET (built-in docs, Redis 7+). MONITOR streams every command, which is great in the lab and dangerous in production (it roughly halves throughput).

  4. 04

    RedisInsight is a free GUI for browsing keys, profiling commands, and viewing memory analysis. It works with Valkey for the core data types. Use it to see structures, but learn the CLI first: incidents happen on servers with only a terminal.

  5. 05

    Pin versions in your lab to match production. Many commands in this course carry a version: SET ... GET (6.2), LMPOP (7.0), Functions (7.0), HEXPIRE (7.4), built-in JSON/search (Redis 8). Valkey tracks Redis 7.2 semantics plus its own additions, and Redis Stack modules are separate on Valkey (valkey-json, valkey-bloom, valkey-search).

Code & diagrams

lab.shbash

One Redis 8, one Valkey 8, both on your laptop.

docker network create redislab

docker run -d --name redis  --network redislab -p 6379:6379 redis:8
docker run -d --name valkey --network redislab -p 6380:6379 valkey/valkey:8

redis-cli -p 6379 PING      # PONG
redis-cli -p 6380 PING      # PONG

redis-cli -p 6379 INFO server | grep -E "redis_version|redis_mode|process_id"
redis_version:8.2.1
redis_mode:standalone
process_id:1

redis-cli -p 6380 INFO server | grep -E "server_name|valkey_version"
server_name:valkey
valkey_version:8.1.1
docker-compose.ymlyaml

A reusable lab with persistence turned on and a config file you can edit.

services:
  redis:
    image: redis:8
    command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
    ports: ["6379:6379"]
    volumes:
      - ./redis.conf:/usr/local/etc/redis/redis.conf:ro
      - redis-data:/data
  insight:
    image: redis/redisinsight:latest
    ports: ["5540:5540"]

volumes:
  redis-data:

# redis.conf (minimal)
# appendonly yes
# appendfsync everysec
# maxmemory 256mb
# maxmemory-policy allkeys-lru
cli-essentials.redisredis
127.0.0.1:6379> COMMAND DOCS GETEX
... summary: Returns the string value of a key after setting its expiration time.
... since: 6.2.0
127.0.0.1:6379> CONFIG GET maxmemory-policy
1) "maxmemory-policy"
2) "noeviction"
127.0.0.1:6379> DBSIZE
(integer) 5
127.0.0.1:6379> OBJECT ENCODING user:42
"listpack"
127.0.0.1:6379> MEMORY USAGE user:42
(integer) 88

When it breaks

A lab habit reaches production: MONITOR left running during an incident

What you see

Every command is copied to the monitoring client. Throughput drops sharply and the monitor's output buffer grows until Redis disconnects it.

Fix & prevent

Use MONITOR for seconds, never minutes, and never on a busy primary. Prefer SLOWLOG, LATENCY, INFO commandstats, and client-side tracing.

Code tested on Redis 8 fails on the production Valkey or older Redis

What you see

ERR unknown command 'HEXPIRE' or JSON.SET in production, after it all worked locally.

Fix & prevent

Run the same engine and version locally and in CI (Testcontainers with a pinned image). Record the minimum server version your code needs.

Explain it without notes

01

Why should your local Redis version match production?

02

Name four redis-cli modes besides the interactive shell and what each is for.

Practice

01

Bring up the lab. Write 1,000 keys with a loop, then find them with redis-cli --scan --pattern 'lab:*' | wc -l.

02

Use COMMAND DOCS to find which version added the GET option to SET.

Trade-offs

  • ↔

    Redis Open Source 8 (built-in JSON, search, time series; RSAL/SSPL/AGPL licences) vs Valkey (BSD, modules installed separately, backed by major clouds): pick based on the features you need and your organisation's licence policy.

  • ↔

    GUI tools speed up exploration; the CLI is what you'll have during an incident. Learn both, rely on the CLI.

Done when you can

  • I have Redis and Valkey running locally in Docker.

  • I can find the server version, mode, memory and eviction policy in under a minute.

  • I can iterate keys with --scan, find big keys, and measure latency from the CLI.