Skip to content

Using redis-cli

redis-cli is the command-line interface bundled with every Redis installation (and available inside the official Docker image). It supports two modes: interactive (a live REPL prompt) and inline (a single command passed directly from your shell).

The most common flags:

FlagDefaultPurpose
-h host127.0.0.1Redis server hostname or IP
-p port6379Redis server port
-n db-number0Select a database number (0–15) on connect
Terminal window
# Connect to the default host and port
redis-cli
# Connect explicitly — useful when targeting a remote server
redis-cli -h 127.0.0.1 -p 6379
# Connect and immediately switch to database 1
redis-cli -n 1

In inline mode you pass a single command as arguments to redis-cli and the result is printed to stdout — handy for scripts:

Terminal window
redis-cli PING

In interactive mode you run redis-cli with no command arguments and get the 127.0.0.1:6379> prompt where you can type commands one by one.

PING is the lightest possible check that the server is reachable:

127.0.0.1:6379> PING
PONG

Pass an optional message and Redis echoes it back — useful for testing round-trip latency in scripts:

127.0.0.1:6379> PING "hello world"
"hello world"

ECHO returns the argument unchanged. It is mainly useful for testing that the client encodes strings correctly:

127.0.0.1:6379> ECHO "Hello"
"Hello"

Redis provides 16 logical databases numbered 0 to 15. They share the same server process and memory but have completely separate keyspaces. The default is database 0.

127.0.0.1:6379> SELECT 1
OK
127.0.0.1:6379[1]> SET greeting "hi from db1"
OK
127.0.0.1:6379[1]> SELECT 0
OK
127.0.0.1:6379> GET greeting
(nil)

Notice the prompt changes to 127.0.0.1:6379[1] when you are on a database other than 0.

DBSIZE returns the number of keys in the currently selected database:

127.0.0.1:6379> DBSIZE
(integer) 5

FLUSHDB deletes every key in the current database. This is irreversible — use it only in development or test environments:

127.0.0.1:6379> FLUSHDB
OK
127.0.0.1:6379> DBSIZE
(integer) 0

redis-cli ships with inline documentation. Use HELP followed by a command name or a category tag:

127.0.0.1:6379> HELP SET
127.0.0.1:6379> HELP @string

HELP @string lists every command in the string group — a fast way to discover commands without leaving the terminal.

PING
ECHO "Hello"
SELECT 1
DBSIZE
SELECT 0
Which flag selects a specific Redis database when connecting with redis-cli?
What does PING return when the server is reachable?
What does FLUSHDB do?
How do you list all commands in the string group from within redis-cli?