Persisting client sessions with Redis

The sessions we created until now are stored in the program memory. It means if the program crashes or restarts, all the logged sessions will be lost. It needs the client to re-authenticate once again to get a new session cookie. It can be an annoying thing sometimes. In order to save sessions in some place, we chose Redis. Redis is a key-value storage that is very fast because it lives in primary memory.

The Redis server stores any key-value pairs we supply. It provides basic data types such as strings, lists, hashes, sets, and so on. For more details, visit https://redis.io/topics/data-types. We can install Redis with the following command on Ubuntu 16.04:

sudo apt-get install redis-server

On macOS ...

Get Building RESTful Web services with Go 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.