Getting Started with Redis: Installation Guide


This guide provides the step-by-step commands to install Redis on your computer for development purposes. It’s the official companion to our tutorial video.



Installing Redis on Windows

For Windows, you have a couple of excellent options. The method we use in the video is WSL, but the native Memurai installer is also a great choice. You can use Docker instead of WSL, you just need to set up a linux environment in the docker then the process is the same as the linux process.



Method 1: WSL (Recommended for this Tutorial Series)

The Windows Subsystem for Linux (WSL) lets you run a real Linux environment directly on Windows. This is the method recommended by the official Redis documentation because you get to run the actual Linux version of Redis, which is what you’ll almost always use on a real server.

Step 1: Install WSL

  1. Right click on the Start icon.
  2. Select Terminal (Admin).
  3. Select yes when prompted.
  4. In the PowerShell window that appears, type the following command and press Enter:

    wsl --install
    
  5. This will automatically download and install WSL along with the default Ubuntu distribution. Once it’s finished, restart your computer.

Step 2: Set Up Linux

  1. After restarting, find “Ubuntu” in your Start Menu and open it.
    or
  2. Run a terminal and type wsl into it
  3. The first time it runs, it will ask you to create a username and a password. This is only for your new Linux environment. Complete this setup.

Step 3: Install Redis in Ubuntu

  1. Now that you have a Linux terminal running, copy and paste the following commands as they are and press Enter.

    curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
    
    echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
    
    sudo apt-get update
    sudo apt-get install redis
    

    (Note: We use the sudo command because installing software and managing services requires administrator privileges in Linux.)

Step 4: Start the Redis Server

  1. To start the Redis service, use the following command:

    sudo service redis-server start
    
  2. Incase you need to stop Redis, use the command:

     sudo service redis-server stop
    

    You’re all set! Skip to the “Verifying Your Installation” section.



Method 2: Memurai (Native Windows Alternative)

Memurai is the official Redis partner for providing a native Windows version. It’s an excellent choice if you prefer a simple .msi installer and don’t want to set up WSL.

  1. Download: Go to the Memurai Download Page.
  2. Select Edition: Download the Memurai Developer Edition, which is free.
  3. Install: Run the installer just like any other Windows application. It will set up Redis to run automatically as a Windows service.



Installing Redis on macOS

For macOS, the easiest way to install Redis is with a package manager called Homebrew.

Step 1: Install Homebrew (if you don’t have it)

  1. Open your Terminal application.
  2. Paste the following command and press Enter:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    

Step 2: Install Redis

  1. In the same terminal, run:

    brew install redis
    

Step 3: Start the Redis Server

  1. To have Redis start automatically every time you log in, run:

    brew services start redis
    
  2. To stop Redis, use the command:

    brew services stop redis
    



Verifying Your Installation

This process is the same for all operating systems.

  1. Open your command line tool (Terminal, or your Ubuntu WSL terminal).
  2. Type the following command to connect to your running Redis server:

    redis-cli
    
  3. You should see your prompt change to 127.0.0.1:6379>.

  4. To test the connection, type PING and press Enter. You should see a PONG response.

    127.0.0.1:6379> PING
    PONG
    

    Congratulations, Redis is working!



A Few Fun Commands to Try

# Set a key named "message" with the value "hello redis"
127.0.0.1:6379> SET message "hello redis"
OK

# Get the value of the key "message"
127.0.0.1:6379> GET message
"hello redis"

# Check if a key named "message" exists (1 means yes, 0 means no)
127.0.0.1:6379> EXISTS message
(integer) 1

# Delete the key
127.0.0.1:6379> DEL message
(integer) 1

# Check again if it exists
127.0.0.1:6379> EXISTS message
(integer) 0
Enter fullscreen mode

Exit fullscreen mode

To exit the Redis CLI, type exit or press Ctrl+C.



What’s Next?

Now that you have Redis installed, you’re ready to dive into the core of its power: data types! In our next video/article, we’ll cover the fundamental data types in Redis.

For more in-depth information, you can always refer to the Official Redis Documentation.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *