redis-cli – Coding skill for AI agents
Redis command-line interface (redis-cli) reference and usage guide. Use this skill whenever the user mentions redis-cli, Redis CLI, or any task involving querying, inspecting, debugging, or managing Redis from the command line.
Install the redis-cli skill with one command
Pick the tool you use, copy the command and paste it in your terminal. The skill lands in that tool's skills folder and is ready in your next session.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/redis-cli-7ae02.tgz | tar xz -C ~/.claude/skills
Call it in Claude Code: /redis-cli – then describe the task you want done.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/redis-cli-7ae02.tgz | tar xz -C ~/.codex/skills
Call it in Codex: $redis-cli – then describe the task you want done.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/redis-cli-7ae02.tgz | tar xz -C ~/.hermes/skills
Call it in Hermes Agent: /redis-cli – then describe the task you want done.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/redis-cli-7ae02.tgz | tar xz -C ~/.deepcode/skills
Call it in DeepSeek: /redis-cli – then describe the task you want done.
SKILL.md content
redis-cli — Redis Command Line Interface
When to Use
Use this skill when you need redis command-line interface (redis-cli) reference and usage guide. Use this skill whenever the user mentions redis-cli, Redis CLI, or any task involving querying, inspecting, debugging, or managing Redis from the command line. Use it for scoped key/value operations, keyspace inspection and Redis administration.
redis-cli is the primary command-line tool for interacting with Redis. It supports two modes: command-line execution (run a command and exit) and interactive mode (a REPL with tab completion, history, and hints). It also provides special modes for monitoring, latency analysis, key space scanning, and data import/export.
Official resources: [Redis CLI Docs](https://redis.io/docs/latest/develop/tools/cli/) | [Commands](https://redis.io/commands/) | [Download](https://redis.io/downloads/)
Prerequisites
# Check if redis-cli is installed
redis-cli --version
# Install options:
# macOS (Homebrew)
brew install redis
# Ubuntu / Debian
sudo apt install redis-tools
# CentOS / RHEL
sudo yum install redis
# Alpine
apk add redis
# Build from source (binary only)
make redis-cli
# Binary at: src/redis-cli
# Docker (no installation needed)
docker run -it --rm redis redis-cli -h <host> -p <port> PINGSecurity Considerations
> IMPORTANT: Redis provides powerful operations that can irreversibly modify or delete data.
> Pay close attention to the following safety guidelines:
- Never pass passwords via
-ain production — visible in shell history and process listings. UseREDISCLI_AUTHenvironment variable instead. - **
KEYS *blocks the server** on large databases — always useSCANin production code. MONITORlogs all commands including sensitive data — use cautiously, and never for extended periods on production servers.FLUSHALL/FLUSHDBare irreversible — verify target database withCLIENT LISTorINFO keyspacefirst.--rdbproduces a point-in-time snapshot, not a continuous backup. Concurrent writes after the snapshot are absent; check exit status and test restore compatibility.
Quick Reference
Connection
# Basic connection (default: 127.0.0.1:6379)
redis-cli
redis-cli -h redis15.localnet.org -p 6390 PING
# With password (prefer REDISCLI_AUTH env var for security)
redis-cli --askpass PING
# URI connection
redis-cli --user username --askpass -h redis.example.com PING
# TLS
redis-cli --tls --cacert /path/to/ca.crt -h redis.example.com PING
# Specific database
redis-cli -n 2 DBSIZE
# IPv4/IPv6 preference
redis-cli -4 PING # prefer IPv4
redis-cli -6 PING # prefer IPv6Command-Line vs Interactive Mode
# Command-line mode: execute one command and exit
redis-cli INCR mycounter
redis-cli GET mykey
# Interactive mode: type commands at the prompt
redis-cli
127.0.0.1:6379> PING
PONG
127.0.0.1:6379> SELECT 2
OK
127.0.0.1:6379[2]> DBSIZE
(integer) 1The prompt shows host:port[db]. Use CONNECT <host> <port> to switch instances interactively.
Data Query Cheat Sheet
String operations (complexity depends on the command and bytes processed):
GET key # Get value
SET key value [NX|XX] [EX sec|PX ms|KEEPTTL] # Set with conditions/TTL
SET key value GET # Set new, return old value
GETSET key newvalue # [Use SET key value GET instead]
MGET key1 key2 ... # Get multiple values
INCR key # Increment integer (+1)
INCRBY key 10 # Increment by amount
STRLEN key # String length
GETRANGE key 0 50 # SubstringHash operations:
HGET key field # Get field value O(1)
HMGET key f1 f2 # Get multiple fields O(N)
HGETALL key # Get all fields/values O(N)
HKEYS key # Get all field names O(N)
HLEN key # Number of fields O(1)
HEXISTS key field # Check field exists O(1)
HSCAN key 0 [MATCH pat] # Iterate hash fields O(1) per callList operations:
LRANGE key 0 -1 # Get all elements O(N)
LLEN key # List length O(1)
LINDEX key 0 # Get by index O(N)
LPOS key value # Find element position O(N)Set operations:
SMEMBERS key # Get all members O(N)
SCARD key # Set cardinality O(1)
SISMEMBER key member # Check membership O(1)
SMISMEMBER key m1 m2 # Multi-membership check O(N)
SSCAN key 0 [MATCH pat] # Iterate set members O(1) per callSorted Set operations:
ZRANGE key 0 -1 [WITHSCORES] # By index O(log(N)+M)
ZRANGE key -inf +inf BYSCORE # By score range O(log(N)+M)
ZRANGE key [a [z BYLEX # By lexicographic O(log(N)+M)
ZCARD key # Member count O(1)
ZSCORE key member # Get score O(1)
ZRANK key member # Get rank O(log(N))
ZSCAN key 0 [MATCH pat] # Iterate members O(1) per callKey inspection:
EXISTS key [key ...] # Check existence (O(N) for multi) — returns count
TYPE key # Data type: string|list|set|zset|hash|stream O(1)
TTL key # Seconds until expiry (-1=none, -2=not exists) O(1)
PTTL key # Milliseconds until expiry O(1)
MEMORY USAGE key [SAMPLES n] # Memory consumption in bytes O(N)
OBJECT ENCODING key # Internal encoding (ziplist, hashtable, etc.) O(1)
OBJECT IDLETIME key # Seconds since last access O(1)
DBSIZE # Total keys in current database O(1)
RANDOMKEY # Return a random key O(1)Incremental Key Scanning
SCAN divides work into smaller calls but each call still uses server CPU; tune COUNT and throttle, unlike KEYS * which should be avoided in production.
# redis-cli built-in scan mode
redis-cli --scan # List all keys
redis-cli --scan --pattern 'user:*' # Filter by pattern
redis-cli --scan --pattern '*:12345*' # Glob patterns
redis-cli --scan --count 100 # Batch size hint
# Programmatic SCAN in interactive mode
SCAN 0 MATCH user:* COUNT 100
# Returns: 1) next_cursor 2) [keys...]
# Continue with: SCAN <next_cursor> MATCH user:* COUNT 100
# Iteration complete when cursor returns 0
# Count keys matching a pattern
redis-cli --scan --pattern 'session:*' | wc -lSCAN guarantees: a full iteration (cursor 0 → cursor 0) always returns all elements that existed for the entire duration. Elements may appear multiple times — handle duplicates in your application.
Server Inspection
# Real-time stats (updates every second, use -i to change interval)
redis-cli --stat
# Server information
redis-cli INFO server # Server details
redis-cli INFO memory # Memory usage
redis-cli INFO keyspace # Database key counts
redis-cli INFO replication # Replication status
redis-cli INFO all # Everything
# Key space analysis
redis-cli --bigkeys # Find largest keys by element count
redis-cli --memkeys # Find largest keys by memory usage
redis-cli --keystats # Combined bigkeys + memkeys with distribution
# Latency analysis
redis-cli --latency # Continuous latency sampling
redis-cli --latency-history # Latency over time (15s windows)
redis-cli --latency-dist # Latency spectrum visualization
redis-cli --intrinsic-latency 5 # System baseline latency (run on Redis host)Output Control
# Raw output (no type prefixes) — default when piping
redis-cli --raw GET mykey
redis-cli GET mykey > /tmp/output.txt # auto raw mode
# Human-readable (force) when piping
redis-cli --no-raw GET mykey | cat
# CSV output
redis-cli --csv LRANGE mylist 0 -1
# JSON output (RESP3, use -2 for RESP2)
redis-cli --json HGETALL user:1
# Read last argument from stdin
cat /etc/services | redis-cli -x SET net_services
# Pipe commands from file
cat /tmp/commands.txt | redis-cliRepeat Commands
# Run command N times
redis-cli -r 5 INCR counter
# Run with delay (seconds, supports decimals)
redis-cli -r -1 -i 1 INFO | grep rss_human # infinite, every 1s
# Interactive: prefix with count
5 INCR mycounter # runs 5 timesServer Administration
# ACL management
redis-cli ACL LIST # List all users… (full content is in the download package)
Related skills
- reference-builder – Creates exhaustive technical references and API documentation. Generates comprehensive…
- remotion-best-practices – Best practices for Remotion - Video creation in React
- repo-maintainer – Audit and repair repository hygiene across artifacts, dependencies, CI, docs, Git state…
- repo-native-refactor – Review diffs without editing, or perform evidence-based cleanup while preserving…
- requesting-code-review – Use when completing tasks, implementing major features, or before merging to verify work…
- resolving-merge-conflicts – Use when you need to resolve an in-progress git merge/rebase conflict.
- review-and-simplify-changes – Review a git diff or explicit file scope for reuse, code quality, efficiency, clarity…
- review-animations – Use when reviewing animation and motion code against a strict craft, performance…