Limited Time Offer: 40% off

Redis CLI

Connect to Redis, run commands, and debug issues with the redis-cli tool.

What is redis-cli?

redis-cli is the official command-line client for Redis. It ships with Redis and lets you connect to any Redis server, run commands interactively, pipe bulk data, and run diagnostic checks. It is the first tool most people reach for when debugging a Redis problem or exploring data.

Connecting to Redis

Running redis-cli with no arguments connects to 127.0.0.1 on port 6379, the default Redis address:

BASH
redis-cli
127.0.0.1:6379>

To connect to a different host or port, use -h and -p:

BASH
redis-cli -h 10.0.1.50 -p 6380

Connecting with a password

If your Redis server requires authentication, pass the password with -a:

BASH
redis-cli -h 10.0.1.50 -a mysecretpassword

Alternatively, connect first and then authenticate inside the session using the AUTH command:

127.0.0.1:6379> AUTH mysecretpassword
OK

The -a flag prints a warning to stderr by default. To suppress it, add --no-auth-warning.

Connecting with TLS

For Redis servers that require TLS (common with managed cloud providers), add the --tls flag:

BASH
redis-cli -h my-redis.example.com -p 6380 --tls

If your server uses a self-signed certificate, you can provide a CA certificate:

BASH
redis-cli -h my-redis.example.com --tls --cacert /path/to/ca.crt

Interactive mode vs. single-command mode

redis-cli works in two modes.

Interactive mode opens a prompt where you type commands one at a time:

BASH
redis-cli
127.0.0.1:6379> PING
PONG

Single-command mode runs one command and exits, which is useful in scripts:

BASH
redis-cli PING
# PONG

redis-cli GET session:user:1042
# "eyJhbGciOiJIUzI1NiJ9..."

You can also pass a series of commands non-interactively using -e to exit on errors, or pipe commands via stdin:

BASH
echo "SET counter 0" | redis-cli

Basic commands

These are the commands you will use most often:

127.0.0.1:6379> SET product:price:42 29.99
OK

127.0.0.1:6379> GET product:price:42
"29.99"

127.0.0.1:6379> EXISTS product:price:42
(integer) 1

127.0.0.1:6379> DEL product:price:42
(integer) 1

127.0.0.1:6379> SET session:token:abc123 "logged_in"
OK

127.0.0.1:6379> EXPIRE session:token:abc123 3600
(integer) 1

127.0.0.1:6379> TTL session:token:abc123
(integer) 3598

127.0.0.1:6379> TYPE session:token:abc123
string

TTL returns seconds remaining. It returns -1 if the key has no expiry and -2 if the key does not exist.

Working with data types

Redis supports several data structures beyond plain strings.

Lists

Lists are ordered sequences of strings. Use them for queues, feeds, or logs:

127.0.0.1:6379> LPUSH notifications:user:88 "Your order shipped" "Payment received"
(integer) 2

127.0.0.1:6379> LRANGE notifications:user:88 0 -1
1) "Payment received"
2) "Your order shipped"

LRANGE 0 -1 returns all elements. LPUSH inserts at the head, so the most recent item comes first.

Sets

Sets store unique, unordered values. Good for tags, memberships, and deduplication:

127.0.0.1:6379> SADD article:tags:301 "postgresql" "performance" "indexing"
(integer) 3

127.0.0.1:6379> SMEMBERS article:tags:301
1) "indexing"
2) "postgresql"
3) "performance"

Hashes

Hashes store field-value pairs under a single key. Useful for representing objects:

127.0.0.1:6379> HSET user:profile:55 name "Priya Sharma" email "priya@example.com" plan "pro"
(integer) 3

127.0.0.1:6379> HGETALL user:profile:55
1) "name"
2) "Priya Sharma"
3) "email"
4) "priya@example.com"
5) "plan"
6) "pro"

127.0.0.1:6379> HGET user:profile:55 email
"priya@example.com"

Sorted sets

Sorted sets associate a score with each member. Use them for leaderboards, rate limiting, and time-ordered data:

127.0.0.1:6379> ZADD leaderboard:week 9850 "alice" 12400 "bob" 7200 "carol"
(integer) 3

127.0.0.1:6379> ZRANGE leaderboard:week 0 -1 WITHSCORES REV
1) "bob"
2) "12400"
3) "alice"
4) "9850"
5) "carol"
6) "7200"

REV returns members from highest to lowest score (requires Redis 6.2+).

Scanning keys safely

Avoid KEYS * in production. It blocks the server while scanning the entire keyspace, which can cause latency spikes on large databases.

Use SCAN instead. It returns results in batches using a cursor and does not block:

127.0.0.1:6379> SCAN 0 MATCH "session:*" COUNT 100
1) "128"
2) 1) "session:token:abc123"
   2) "session:token:def456"

The first return value is the next cursor. Repeat the call with that cursor until it returns 0, which means the scan is complete.

For a full scan from the command line in one shot, use the --scan flag:

BASH
redis-cli --scan --pattern "session:*"

This handles the cursor iteration automatically.

The MONITOR command

MONITOR streams every command processed by the server in real time:

127.0.0.1:6379> MONITOR
OK
1714123456.789012 [0 127.0.0.1:52341] "SET" "cart:user:99" "item_id=7"
1714123457.001234 [0 127.0.0.1:52342] "GET" "product:price:7"

This is useful for debugging what an application sends to Redis. Be aware that MONITOR has a measurable performance impact. On a busy server, it can reduce throughput by 50% or more. Use it briefly on development or staging instances, not in production under load.

Press Ctrl+C to stop.

The INFO command

INFO returns a snapshot of server statistics:

BASH
redis-cli INFO

The output is split into sections. To retrieve a specific section:

BASH
redis-cli INFO memory
redis-cli INFO keyspace
redis-cli INFO replication

The keyspace section shows which databases have keys and their counts:

# Keyspace
db0:keys=14832,expires=9104,avg_ttl=87432

The memory section shows used_memory_human and maxmemory_human, which tells you how close you are to the memory limit.

Pipelining commands

The --pipe flag sends commands in bulk over a single connection without waiting for individual replies. This is significantly faster for loading large datasets:

BASH
cat commands.txt | redis-cli --pipe

Where commands.txt contains commands in Redis inline protocol format, one per line:

SET product:name:1 "Wireless Keyboard"
SET product:name:2 "USB-C Hub"
SET product:name:3 "Mechanical Keyboard"

After the operation completes, redis-cli prints a summary:

All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 3

Running Lua scripts with EVAL

Redis supports Lua scripts that run atomically on the server. EVAL executes a script inline:

BASH
redis-cli EVAL "return redis.call('SET', KEYS[1], ARGV[1])" 1 config:maintenance "true"

The arguments after the script are: the number of keys, the keys themselves, then any additional arguments.

For a more realistic use case, a script that increments a counter and returns the new value only if it is below a limit:

BASH
redis-cli EVAL "
  local current = tonumber(redis.call('GET', KEYS[1]) or 0)
  if current < tonumber(ARGV[1]) then
    return redis.call('INCR', KEYS[1])
  else
    return -1
  end
" 1 rate:user:88 100

For scripts you run repeatedly, load them with SCRIPT LOAD and call them with EVALSHA to avoid re-sending the script body each time.

Connecting to Redis Cluster

When connecting to a Redis Cluster, add the -c flag to enable cluster mode. This allows redis-cli to follow redirects when a key lives on a different node:

BASH
redis-cli -c -h 10.0.1.10 -p 7000

Without -c, the client will receive MOVED or ASK responses and fail to retrieve keys that are not on the node you connected to. With -c, it follows those redirects automatically.

Useful flags

FlagWhat it does
--no-auth-warningSuppresses the warning printed when using -a
--resp3Uses the RESP3 protocol (Redis 6+), which adds richer type information
--latencySamples latency between client and server continuously
--latency-historyShows latency samples over time in 15-second windows
--statPrints rolling server statistics (memory, keys, commands/sec) every second
--bigkeysScans the keyspace and reports the largest key per data type

The --stat flag is handy for a quick live view of server activity without parsing INFO output manually:

BASH
redis-cli --stat
------- data ------ --------------------- load -------------------- - child -
keys       mem      clients blocked requests            connections
14832      42.50M   18      0       1847302 (+0)        204
14832      42.50M   18      0       1847315 (+13)       204

Connecting to remote Redis

For managed Redis services like AWS ElastiCache or Upstash, the connection command follows the same pattern:

BASH
# Upstash
redis-cli -h your-instance.upstash.io -p 6379 -a your-password --tls

# ElastiCache (within the same VPC)
redis-cli -h my-cluster.abc123.0001.use1.cache.amazonaws.com -p 6379

ElastiCache does not allow connections from outside the VPC. To connect from your local machine, set up an SSH tunnel through a bastion host:

BASH
ssh -L 6379:my-cluster.abc123.0001.use1.cache.amazonaws.com:6379 user@bastion-host

Then connect locally:

BASH
redis-cli -h 127.0.0.1 -p 6379

Quick reference

Command / FlagDescription
redis-cliConnect to localhost:6379
redis-cli -h host -p portConnect to a specific host and port
redis-cli -a passwordConnect with a password
redis-cli --tlsConnect using TLS
redis-cli -cConnect in cluster mode
PINGTest the connection
SET key valueSet a string value
GET keyGet a string value
DEL keyDelete a key
EXISTS keyCheck if a key exists
EXPIRE key secondsSet a TTL on a key
TTL keyCheck remaining TTL
TYPE keyCheck the data type of a key
SCAN 0 MATCH pattern COUNT nSafely scan keys
redis-cli --scan --pattern "prefix:*"Scan keys from the shell
MONITORStream all commands in real time
INFO sectionServer statistics
redis-cli --pipeSend bulk commands via stdin
redis-cli --statRolling live stats
redis-cli --bigkeysFind the largest keys per type