Redis is an in-memory data store used as a database, cache, or message broker. Go-redis/redis is a type-safe, Redis client library for Go with support for features like Pub/Sub, sentinel, and pipelining.

NOTE: We will be referring to the client library as “go-redis” to help differentiate it from Redis itself.

In this article, we will explore go-redis and use its pipeline feature to build a leaderboard API. The API will use Gin and Redis’ sorted sets under the hood. It will expose the following endpoints:

  • GET /points/:username — to get a user’s score and their rank in the overall leaderboard
  • POST /points — to add or update a user and their score. This endpoint will also return the new rank of the user
  • GET /leaderboard — returns the current leaderboard, with users sorted in ascending order of their ranks

#redis #database #web-development #programming #developer

How to Use Redis as a Database with go-redis
2.90 GEEK