Applying cache

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

$ go get github.com/garyburd/redigo/redis

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 ( 
      "log" 
      "time" 
 
      redigo "github.com/garyburd/redigo/redis" 
    ) 

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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.