redis-cli

Computer Terminal

Connecting to a Local Redis Server

The redis-cli provides a command-line interface to the Redis server. To connect to the local Redis server (i.e. the Redis server running on the same machine as the redis-cli), invoke redis-cli without arguments:

$ redis-cli

After running this command, you will be greeted with an interactive prompt for typing Redis commands:

127.0.0.1:6379>

The prompt indicates that we have connected to a Redis server running on the localhost (127.0.0.1) which is running on the default Redis TCP port (port 6379).

From here, you can enter various commands such as the set command:

127.0.0.1:6379> set key1 hello

Type "exit" to leave the Redis prompt:

127.0.0.1:6379> exit

A cool feature of the `redis-cli is that in provides hints in light gray as you type commands:

Redis

This is a pretty amazing command-line interface feature!

Running a Redis Command Non-interactively

You can run Redis commands non-interactively without the Redis prompt as follows:

$ redis-cli set key1 hello

You can also get values back and use them in other bash scripts:

$ result=$(redis-cli get key1)
$ echo $result
hello

I love the simplicity and beauty of this command-line tool!

Connecting to a Remote Redis Server

To connect to a remote server running Redis (a server named raspi in this case), issue the following command:

$ redis-cli -h raspi

More Information

See the redis-cli reference for a list of other redis-cli command line arguments.

results matching ""

    No results matching ""