Redis Tutorial 0/42 lessons ~6 min read Lesson 6

    Redis CLI

    redis-cli is the first tool on every production incident.

    Course progress0%
    Focus
    10 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    redis-cli is the first tool on every production incident. Before Grafana loads, you will run SLOWLOG GET, INFO memory, and LATENCY DOCTOR to narrow the blast radius.

    It speaks RESP over TCP (or Unix socket), supports interactive mode, one-shot commands, and cluster-aware routing with --cluster options.

    Master these diagnostics and you can distinguish a hot key from a memory fragmentation crisis in under two minutes.

    Understanding the topic

    Key concepts

    • Interactive mode: redis-cli with no args opens a REPL.
    • One-shot: redis-cli GET key for scripts and CI checks.
    • MONITOR streams every command — dev only, crushes prod.
    • SLOWLOG captures commands exceeding slowlog-log-slower-than.
    • LATENCY DOCTOR summarizes recent latency spikes.
    • --bigkeys and --hotkeys scan keyspace for outliers (use off-peak).
    text
    flowchart TB
    CLI[redis-cli] --> Data[GET HGET ZRANGE]
    CLI --> Server[INFO CONFIG]
    CLI --> Debug[SLOWLOG LATENCY MONITOR]
    CLI --> Cluster[CLUSTER NODES]

    Step-by-step explanation

    1. redis-cli connects to host:port (default 127.0.0.1:6379).
    2. -a or --user for ACL authentication.
    3. Commands sent as RESP; replies rendered as text or raw.
    4. Cluster mode follows MOVED/ASK redirects with -c flag.
    5. Pipe mode (--pipe) bulk-loads data for migrations.

    Syntax reference

    Common commands

    • TTL/TYPE — first step on any mystery key.
    • SLOWLOG — find commands blocking the event loop.
    • LATENCY DOCTOR — human-readable latency report.
    bash
    redis-cli -h prod.redis.internal -a '$PASS' --no-auth-warning
    TTL session:abc
    TYPE session:abc
    SLOWLOG GET 10
    LATENCY DOCTOR
    MEMORY DOCTOR

    Informative example

    Investigate a slow API — check slowlog and memory in one session:

    bash
    redis-cli SLOWLOG GET 5
    # 1) 1) (integer) 1234567
    # 2) (integer) 8500 ← microseconds
    # 3) (integer) 10
    # 4) 1) "KEYS" 2) "*"
    redis-cli INFO memory | grep used_memory_human
    redis-cli --hotkeys -i 0.1

    KEYS in slowlog is a smoking gun. Replace with SCAN in application code and flush the offender deploy.

    Real-world use

    Real-world use cases

    • On-call: confirm connectivity and auth after network change.
    • Find slow commands blocking the event loop.
    • Inspect TTL and type before deleting mystery keys.
    • Cluster slot migration with CLUSTER MEET / ADDSLOTS.
    • Bulk import via cat data.txt | redis-cli --pipe.

    Best practices

    • Use --no-auth-warning in scripts; prefer REDISCLI_AUTH env var.
    • Never MONITOR in production under load.
    • Run --bigkeys during maintenance windows only.
    • Wrap repeated checks in shell aliases for on-call runbooks.
    • Use -c for cluster; without it MOVED errors confuse juniors.
    • Prefer read-only ACL user for diagnostic scripts.

    Common mistakes

    • Running KEYS * on production to count keys.
    • Leaving MONITOR running over SSH disconnect.
    • Forgetting -c on cluster and misreading errors.
    • Pasting production passwords into Slack with redis-cli -a.

    Advanced interview questions

    Q1BeginnerHow do you connect to Redis from CLI?
    redis-cli -h host -p 6379; AUTH or --user for ACL.
    Q2BeginnerWhat does PING return?
    PONG — confirms server is reachable and responding.
    Q3IntermediateHow do you find slow commands?
    SLOWLOG GET or configure slowlog-log-slower-than lower threshold.
    Q4IntermediateWhy avoid MONITOR in production?
    It streams every command and adds overhead; can degrade a busy instance.
    Q5AdvancedDebug high latency without application access?
    SLOWLOG, LATENCY DOCTOR, INFO stats, --hotkeys, check recent deploys and memory pressure.

    Summary

    redis-cli is the primary production diagnostic tool.

    Ready to mark this lesson complete?Track your journey across the entire course.