Applying cache

The first step is to download dependency with Redis as the connection driver:

$ go get

The Redigo is our communication interface with Redis. We will use Redis as a cache tool of our microservice.

Now, we will create the cache.go file. This file is responsible for delivering us a configured instance of the cache. Similar to the other files we've ever created, let's declare the package where we are working and the dependencies, as follows:

    package main 
    import ( 
      redigo "" 

Then, we create an interface to create a pool of connections to the Redis and a struct with all the settings of the connection. Note that the instance of our pool will also be in ...

Get Microservice Patterns and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.