Introduction
Redis is an in-memory data structure used as a database, cache, message broker, and streaming engine. It is open-source (BSD license). Redis allows data structures like strings, hashes, lists, sets, sorted sets with range searches, bitmaps, hyperloglogs, geographic indexes, and streams.
Redis offers built-in replication, Lua scripting, LRU eviction, transactions, several levels of on-disk persistence, Redis Sentinel for high availability, and Redis Cluster for automatic partitioning. You can use Redis from most programming languages.
A TCP socket and a Redis-specific protocol are used by external programs to communicate with Redis. The Redis client libraries for many programming languages implement this protocol. On the other hand, Redis provides a command-line utility that can be used to send commands to the database. This program is known as Redis-CLI.
The Redis command-line interface (Redis-CLI) is a terminal tool that allows you to send instructions to the Redis server and get responses from it.
It has two modes: an interactive REPL (Read Eval Print Loop) mode in which the user enters Redis commands and receives responses.
The other is a command mode in which Redis-CLI is run with additional arguments the response is sent to standard output.
Redis uses an in-memory dataset to attain high performance. Redis may save your data in one of two ways, depending on your needs: periodically dumping the dataset to disk or adding the commands to a disk-based log. But if you only need a feature-rich, networked, in-memory cache, you can turn off persistence.
Command-line usage
Redis-CLI includes basic line editing capabilities in interactive mode, giving you a typing-like experience.
You have several options for starting the software in unique modes. You can, among other things, simulate a replica and print the replication stream it receives from the main, examine a Redis server's latency and show statistics, or request an ASCII-art spectrogram of latency samples and frequencies.
Include this command to execute as separate arguments of redis-cli to run a Redis command and receive its response as standard output to the terminal:
$ redis-cli INCR mycounter
(integer) 7
The command's response is "7." Because Redis responses are typed (strings, arrays, integers, nil, errors, and so on), the type of the response is displayed within parenthesis.
When redis-cli detects that the standard output is a tty or terminal, it only displays additional information for human readability. It will automatically enable the raw output mode for all other outputs, as shown:
$ redis-cli INCR mycounter > /tmp/output.txt
$ cat /tmp/output.txt
8
Because redis-cli identified that the output was no longer written to the terminal, (integer) was excluded from the output. With the —raw option, you can force raw output even on the terminal:
$ redis-cli --raw INCR mycounter
9
When writing to a file or via a pipe to other commands, use —no-raw to force human-readable output.
Host, port, password, and database
Redis-cli, by default, connects to the server at 127.0.0.1 on port 6379. Several command line parameters can be used to adjust this. Use the -h option to specify a different hostname or IP address. Use -p to specify a different port.
If your instance is password-protected, the -a <password> option will perform authentication, avoiding the need to use the AUTH command explicitly:
$ redis-cli -a myUnguessedPassword PING
PONG
It is recommended that the password be sent to redis-cli automatically via the REDISCLI AUTH environment variable for security reasons.
SSL/TLS
By default, redis-cli connects to Redis via a standard TCP connection. The —tls option, coupled with —cacert or —cacertdir to configure a trusted root certificate bundle or directory, can be used to enable SSL/TLS.
If the target server requires client-side certificate authentication, use —cert and —key to specify a certificate and accompanying private key.