LinuxCommandLibrary

redis-cli

Interact with Redis server

TLDR

Connect to the local server

$ redis-cli
copy

Connect to a remote server on the default port (6379)
$ redis-cli -h [host]
copy

Connect to a remote server specifying a port number
$ redis-cli -h [host] -p [port]
copy

Connect to a remote server specifying a URI
$ redis-cli -u [uri]
copy

Specify a password
$ redis-cli -a [password]
copy

Execute Redis command
$ redis-cli [redis_command]
copy

Connect to the local cluster
$ redis-cli -c
copy

SYNOPSIS

redis-cli [options] [command [arg ...]]

PARAMETERS

-h
    Connect to the specified Redis server hostname (default: 127.0.0.1).

-p
    Connect to the specified Redis server port (default: 6379).

-a
    Authenticate to the Redis server using the provided password.

-s
    Connect to the Redis server using the specified Unix domain socket path.

-n
    Select the specified Redis database number (default: 0).

--raw
    Output raw Redis replies, useful for scripting as it avoids pretty-printing.

--no-raw
    Output formatted and pretty-printed replies (default behavior).

-r
    Repeat the specified command times.

-i
    When repeating commands, wait seconds between executions. Useful with -r.

--latency
    Run a latency test, continuously pinging the server and showing statistics.

--stat
    Print Redis server statistics continuously in an ASCII art style.

--bigkeys
    Scan the database for keys that are very large (in terms of elements or bytes).

--hotkeys
    Discover keys that are frequently accessed by the server.

--memkeys
    Analyze memory usage per key pattern (requires Redis 4.0+).

--pipe
    Read Redis commands from standard input and send them to the server in a pipelined fashion for efficiency.

--scan
    Scan the database for keys matching a given pattern, similar to the SCAN command.

DESCRIPTION

The `redis-cli` command is a powerful and versatile command-line utility for Redis, the open-source, in-memory data structure store. It allows users to interact directly with a Redis server by sending Redis commands and receiving replies. This tool is essential for administering Redis instances, debugging applications, monitoring performance, and executing ad-hoc data operations. It supports various connection methods, including TCP/IP and Unix domain sockets, and offers a range of specialized modes like latency monitoring, statistical reporting, and key analysis (`--bigkeys`, `--hotkeys`, `--memkeys`). `redis-cli` can operate in interactive mode, where users type commands one by one, or non-interactive mode, where commands are passed as arguments or piped from standard input, making it suitable for scripting and automation.

CAVEATS

Connecting to a remote Redis server without TLS encryption can expose sensitive data and credentials to network eavesdropping. Always use strong passwords and consider IP whitelisting or TLS for production environments. Some `redis-cli` features, like `--hotkeys` or `--memkeys`, require specific Redis server versions (e.g., 4.0+). Extensive use of `--bigkeys` or `--scan` on large databases can be resource-intensive on both the client and server.

INTERACTIVE VS. NON-INTERACTIVE MODE

When `redis-cli` is invoked without a command argument, it enters an interactive mode, prompting the user to type Redis commands. This is ideal for exploratory work or debugging. When a command and its arguments are provided directly on the command line (e.g., `redis-cli GET mykey`), it operates in a non-interactive mode, executing the command and exiting. This mode is suitable for scripting.

SPECIAL MODES AND TOOLS

Beyond basic command execution, `redis-cli` offers several specialized modes. The latency mode helps diagnose network or server processing delays. Stat mode provides a live dashboard of server metrics. Tools like bigkeys, hotkeys, and memkeys are invaluable for database analysis and optimization, helping administrators identify and address performance bottlenecks related to data structure size or access patterns.

TLS/SSL SUPPORT

For secure connections, `redis-cli` supports TLS/SSL. Options like --tls, --cacert, --cert, and --key allow it to connect to Redis servers configured with TLS encryption, ensuring data privacy and integrity over the network.

HISTORY

`redis-cli` has been an integral part of the Redis distribution since its early days. It evolved alongside Redis itself, gaining new features to support Redis's growing capabilities, such as Redis Cluster commands, TLS support, and various analytical tools (`--bigkeys`, `--hotkeys`, `--memkeys`). Its development reflects the pragmatic and performance-oriented philosophy of the Redis project, providing a robust and efficient way to interact with the database.

SEE ALSO

redis-server(1), ss(8), netstat(8)

Copied to clipboard