The redis-cli command-line utility lets you interact with a Redis database. With redis-cli, you can run Redis commands directly from the command-line terminal or with interactive mode.

If you want to run Redis commands without redis-cli, you can connect to a database with RedisInsight and use the built-in CLI prompt instead.

Install redis-cli

When you install Redis Enterprise Software or open source Redis, it also installs the redis-cli command-line utility.

To learn how to install Redis and redis-cli, see the following installation guides:

Connect to a database

To run Redis commands with redis-cli, you need to connect to your Redis database.

Connect from a node

If you have SSH access to a node in a Redis cluster, you can run redis-cli directly from the node:

  1. Use SSH to sign in to a node in the Redis Enterprise cluster.

  2. Connect to the database with redis-cli:

    $ redis-cli -p <port>

Connect remotely

If you have redis-cli installed on your local machine, you can use it to connect to a remote Redis database. You will need to provide the database’s connection details, such as the hostname or IP address, port, and password.

$ redis-cli -h <endpoint> -p <port> -a <password>

You can also provide the password with the REDISCLI_AUTH environment variable instead of the -a option:

$ export REDISCLI_AUTH=<password>
$ redis-cli -h <endpoint> -p <port>

Connect with Docker

If your Redis database runs in a Docker container, you can use docker exec to run redis-cli commands:

$ docker exec -it <Redis container name> redis-cli -p <port>

Basic use

You can run redis-cli commands directly from the command-line terminal:

$ redis-cli -p <port> <Redis command>

For example, you can use redis-cli to test your database connection and store a new Redis string in the database:

$ redis-cli -p 12000 PING
$ redis-cli -p 12000 SET mykey "Hello world"
$ redis-cli -p 12000 GET mykey              
"Hello world"

For more information, see Command line usage.

Interactive mode

In redis-cli interactive mode, you can:

  • Run any redis-cli command without prefacing it with redis-cli.
  • Enter ? for more information about how to use the HELP command and set redis-cli preferences.
  • Enter HELP followed by the name of a command for more information about the command and its options.
  • Press the Tab key for command completion.
  • Enter exit or quit or press Control+D to exit interactive mode and return to the terminal prompt.

This example shows how to start interactive mode and run Redis commands:

$ redis-cli -p 12000> PING
PONG> SET mykey "Hello world"
OK> GET mykey
"Hello world"

More info