使用Gorilla sessions自定义后端的优势是什么?

huangapple go评论84阅读模式
英文:

What is the advantage of using Gorilla sessions custom backend?

问题

我想要使用Redis进行会话管理。
但是我无法弄清楚使用Redis作为Gorilla sessions包的自定义后端相比直接使用Redis有什么优势?

Gorilla sessions包的链接:http://www.gorillatoolkit.org/pkg/sessions

英文:

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

答案1

得分: 11

Gorilla Sessions提供了一种连接存储系统以进行会话管理的方法,只要你遵循提供的接口。目前,它们为你提供了两种开箱即用的存储方式。一种是FilesystemStore,它遵循接口,简单地将会话数据存储和检索到服务器的文件系统中。另一种是CookieStore,它通过读写浏览器内置的Cookie系统来实现相同的功能。

Gorilla Sessions与Redis实际上没有直接关系,但是如果你了解这一点,只要你构建一个遵循Gorilla Sessions Store接口的RedisStore,你就可以很容易地使用自己的会话存储。这完全取决于你的能力和你在会话存储系统中寻找的功能。Gorilla Sessions基本上为你提供了两个开箱即用的选项,并提供了一个适合你的应用的自定义选项。

另外,如果你确实构建了一个可以与Gorilla Sessions配合使用的RedisStore,考虑将其开源,因为它将是Go社区的一个很好的补充。

你需要评估你的应用程序的需求和性能要求,以确定使用哪种存储系统。为什么Redis可能是合理的选择呢?如果你正在构建一个需要频繁写入/修改数据并且这些数据需要持久化的应用程序,只要你正确使用Redis,它就可以帮助你扩展应用程序。如果你知道你在做什么,基于Redis的会话存储性能非常好。

最后一点,如果你要使用Redis,请考虑使用这个很棒的Go包:Redigo作为你的Redis客户端库。

英文:

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.

huangapple
  • 本文由 发表于 2014年4月11日 05:14:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/22999148.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定