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 without arguments:
After running this command, you will be greeted with an interactive prompt for typing Redis commands:
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
127.0.0.1:6379> set key1 hello
Type "exit" to leave the Redis prompt:
A cool feature of the `redis-cli is that in provides hints in light gray as you type commands:
This is a pretty amazing command-line interface feature!
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!
To connect to a remote server running Redis (a server named
raspi in this case), issue the following command:
$ redis-cli -h raspi
See the redis-cli reference for a list of other
redis-cli command line arguments.