What is the advantage of using Gorilla sessions custom backend?
Asked Answered
B

1

9

I want to use Redis for session management.
But I can't figure out what the advantage is of using Redis as a custom back-end for Gorilla sessions package over using it directly?

link to the Gorilla session package: http://www.gorillatoolkit.org/pkg/sessions

Bughouse answered 10/4, 2014 at 21:14 Comment(0)
P
11

Gorilla sessions provides a means to wire up a storage system for session management provided you adhere to the interface provided. Currently, they give you two stores out of the box. One is a FilesystemStore that adheres to the interface that simply stores and retrieves session based data on the server's filesystem. The CookieStore as another option, reads and writes to the browsers built-in cookie system to accomplish the same thing using another means.

Gorilla sessions really has nothing to do with Redis, but knowing this, you can easily use your own session storage with Gorilla provided you build a RedisStore that adheres to the Gorilla sessions Store interface. It really all depends on your capability and what you are looking for in a session store system. Gorilla basically gives you two options out of the box with an option for providing your own that suits your app.

Also, if you do get around to building a RedisStore that can work with Gorilla Sessions consider making it open-source since it would be a great addition to the Go community.

You have to evaluate the needs and performance requirements of your app to figure out which storage system to use. Why does Redis possibly make sense? Well if you are building an app that does heavy writes/modifications and this data needs to persist Redis is well known to help you scale your app so long as you utilize it properly. A Redis backed session will perform really well if you know what you are doing.

Last point, should you get Redis involved consider using this wonderful Go package: Redigo as your Redis client library.

Pameliapamelina answered 10/4, 2014 at 21:23 Comment(3)
there is one already, and i think it is good github.com/boj/redistore , just to make sure i got this right, the advantage of using gorilla sessions is the ability to use several ways together?Bughouse
The advantage to Gorilla Sessions is the core functionality of session management is nicely abstracted away in a library that has pluggable back-end storage solutions. As for Redis really, what it boils down to is Redis is known for speed. That coupled with it's pretty robust persistence model means it will handle a ton of concurrent read/write operations. But it does add complexity to your application because now you have an additional component that needs to be maintained, tuned, etc.Pameliapamelina
You can very well do that, but then you are also having to roll your own session and state management which includes figuring out how to deal with login/logout, matching sessions to users, and persisting sessions should a user return.Pameliapamelina

© 2022 - 2024 — McMap. All rights reserved.