No history yet

Setting Up Redis

Getting Redis Running

Before you can use Redis in your applications, you need to install it and get its server running on your machine. Redis is a fast, in-memory key-value store. Think of it as a super-efficient dictionary for your server, often used for caching data to speed things up. Let's get it set up.

Installation

The installation process depends on your operating system. We'll cover the most common setups.

For macOS, the easiest way is with Homebrew, a popular package manager.

# First, update Homebrew
brew update

# Then, install Redis
brew install redis

On Linux distributions like Ubuntu or Debian, you can use the apt package manager.

# Update your package list
sudo apt update

# Install Redis
sudo apt install redis-server

Redis doesn't officially support Windows directly. The recommended approach is to use the Windows Subsystem for Linux (WSL). Once you have WSL set up with a Linux distribution like Ubuntu, you can just follow the Linux installation instructions inside your WSL terminal.

Running the Server

Once installed, you need to start the Redis server. This is the background process that will store your data. If you installed with Homebrew on macOS, you can start it as a service that runs automatically when you log in.

# Start Redis now and on login
brew services start redis

Alternatively, you can start it manually in your terminal. The server will run in the foreground, meaning it will occupy that terminal session.

redis-server

On Linux, the server often starts automatically after installation. You can check its status with this command.

sudo systemctl status redis

To stop a manually started server, you can press Ctrl+C in the terminal where it's running. For a more graceful shutdown, open a new terminal window and use the Redis command-line interface (CLI).

redis-cli shutdown

Verifying It Works

With the server running, you can test the connection. The redis-cli tool is your gateway to interacting with Redis. To check if the server is responsive, you can send it a ping command.

redis-cli ping

If everything is set up correctly, the server will reply with PONG. This simple exchange confirms your Redis instance is up and ready to receive commands.

Quiz Questions 1/5

What is the recommended method for installing Redis on a Windows machine?

Quiz Questions 2/5

After starting the Redis server, which redis-cli command is used to verify that the server is responsive?

Now that you have Redis installed and running, you're ready to start using it.