$linuxjunkies
>

redis-cli(1)

Command-line interface for interacting with Redis servers and executing Redis commands.

UbuntuDebianFedoraArch

Synopsis

redis-cli [OPTIONS] [COMMAND] [ARG] [ARG] ...

Description

redis-cli is the official command-line client for Redis, allowing you to send commands to a Redis server and read responses. It supports interactive mode for an interactive shell, or single-command mode for executing one command and exiting. It can connect to local or remote Redis instances and supports authentication, pipelining, and scripting.

Common use cases include data inspection, database administration, performance monitoring, and testing Redis functionality. redis-cli also provides helpful features like command history, auto-completion, and special commands for cluster management and debugging.

Common options

FlagWhat it does
-h <hostname>Server hostname or IP address (default: 127.0.0.1)
-p <port>Server port number (default: 6379)
-a <password>Password to authenticate with the Redis server
-u <uri>Redis URI (e.g., redis://user:password@host:port/db)
-n <db>Select database number (default: 0)
-i <interval>Execute command every N seconds (continuous monitoring mode)
--rawOutput raw replies without formatting or colors
--csvOutput results in CSV format
-xRead the last argument from standard input
--pipeTransfer raw Redis protocol data from stdin; mass insert mode
--scanScan keys matching a pattern (iterates through keys efficiently)
--eval <script>Execute a Lua script with optional arguments

Examples

Test connectivity to the default Redis server (localhost:6379)

redis-cli ping

Connect to a remote Redis server with authentication and retrieve a key value

redis-cli -h redis.example.com -p 6380 -a mypassword GET mykey

Select database 1 and set a key-value pair

redis-cli -n 1 SET counter 100

Delete all keys in the current database (interactive confirmation mode)

redis-cli FLUSHDB

Scan for all keys matching the pattern 'user:*' and show first 20 results

redis-cli --scan --pattern 'user:*' | head -20

Monitor server statistics, refreshing every second

redis-cli -i 1 INFO stats

Bulk insert Redis commands from a file using pipeline mode

cat commands.txt | redis-cli --pipe

Execute a Lua script that returns a key and an argument

redis-cli EVAL "return {KEYS[1],ARGV[1]}" 1 mykey myarg

Related commands