Redis

How to Use the Redis PING Command

Redis is a free and open-source NoSQL database that stores data in memory in the form of key-value pairs. It is mainly used as a caching mechanism for other databases as it has low latency. Redis can store data structures, such as strings, hashes, lists, HyperLogs, and geospatial indexes.

Redis uses a set of commands for managing and working with the databases. One useful command is the PING command. Let us illustrate how we can use the Redis PING command.

Install Redis on Linux

Before working with the Redis command, you must ensure a Redis server is installed on your system.

Open the terminal and update the system as indicated below:

$ sudo apt-get update

$ sudo apt-get upgrade

Next, enter the commands below to download and install the Redis server:

$ wget http://download.redis.io/redis-stable.tar.gz
$ tar xvzf redis-stable.tar.gz
$ cd redis-stable
$ make

Before running the previous command, ensure you have the GCC compiler and libc installed.

Once Redis server is installed, open the terminal and run the following command to start the server:

$ redis-server

The command indicated above should start the Redis server with the output as shown below:

Test If Redis Is Running

Before running any commands or connecting any clients to the Redis server, you must ensure that Redis is running. Luckily, the PING command allows us to test if the server is running.

The PING command returns PONG if the server is up and running. An example of using the PING command in Redis is provided below:

$ redis-cli ping

PONG

Running the redis-cli command followed by a command will execute the specified command to the Redis server. By default, the redis-cli command will attempt to connect to the Redis server on port 6379.

You can also open the redis-cli interface and run the following PING command as shown:

$ redis-cli

127.0.0.1:6379> ping

PONG

Note: the PING command also supports string arguments. An example is as shown below:

127.0.0.1:6379> ping "Hi"

"Hi"

Conclusion

This short article provides the importance of Redis commands to work and manage databases. It also guides you on testing and verifying if the Redis server is running using the PING command. We hope you found this article helpful. Check out other Linux Hint articles for more tips and information.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list