Redis is a popular in-memory data store that can be used as a database, message broker, or cache layer. When working with Redis, it’s common to have multiple instances running on your system, especially during development or testing phases. However, managing these instances can become cumbersome if you don’t know the proper commands and techniques.
In this tutorial, we’ll cover how to stop and manage Redis server instances, including using the redis-cli
command-line tool and system-specific methods for Ubuntu and macOS systems.
Using redis-cli to Stop Redis Server
The most straightforward way to stop a Redis server instance is by using the redis-cli
command. To do this:
- Open your terminal.
- Type
redis-cli shutdown
and press Enter.
This will send a shutdown signal to the Redis server, which will then save its data to disk and exit cleanly.
Using System-Specific Methods
Depending on your operating system, you may have additional methods for stopping and managing Redis server instances.
Ubuntu Systems
On Ubuntu systems, you can use the service
command to manage Redis. To stop a Redis server instance:
- Open your terminal.
- Type
sudo service redis-server stop
and press Enter.
To start or restart the Redis server, replace stop
with start
or restart
, respectively.
macOS Systems (with Homebrew)
If you’ve installed Redis using Homebrew on macOS, you can use the brew services
command to manage Redis. To stop a Redis server instance:
- Open your terminal.
- Type
brew services stop redis
and press Enter.
To start or restart the Redis server, replace stop
with start
or restart
, respectively.
Creating Aliases for Convenience
If you find yourself frequently starting and stopping Redis server instances, consider creating aliases to simplify the process. For example:
alias redstart='redis-server /usr/local/etc/redis/6379.conf'
alias redstop='redis-cli -h 127.0.0.1 -p 6379 shutdown'
These aliases will allow you to start and stop Redis server instances with a single command.
Conclusion
In this tutorial, we’ve covered how to stop and manage Redis server instances using the redis-cli
command-line tool and system-specific methods for Ubuntu and macOS systems. By mastering these techniques, you’ll be able to efficiently manage your Redis instances and focus on developing your applications.