Prerequisites

Install and Resolve Dependencies to Work With Redis.

  • Ensure you have an up-to-date Go toolchain on your system.
  • Install Redis. This tutorial assumes that you do so on your local machine. If you want to use a remote Redis instance for this tutorial, make sure to adjust the connection details accordingly. Note: Do not set a password for the database.
  • Verify your Redis installation:
    • Start redis-cli in a terminal. It should automatically connect to the local Redis instance.
    • Then, type ping at the prompt and hit Enter. If the Redis instance is available, it will reply with PONG.
  • Download and install the GoLand IDE. There is a free trial available; if you are new to GoLand, don't miss the chance to test it out!
  • Fork or clone the code repository for this tutorial. For brevity, this tutorial shows only parts of the code, so be sure to have the repository available to follow along.

All items checked off? Then let's begin!

Choosing a Redis Package

This tutorial uses the redis/go-redis package. This package is officially supported by the Redis team. However, it's not the only Redis package available. The second-most popular package is gomodule/redigo. Either of the packages is a good choice when working with Redis, but this tutorial uses go-redis for a few reasons:

The go-redis package provides a rich set of functions and types, so you'll want to keep the package reference open while moving through the tutorial.