I have a general question about sessions. I am not very seasoned when it comes to this subject. I've tried with:
NewRediStore (gopkg.in/boj/redistore.v1)
NewCookieStore
NewFileSystemStore
I was under the impression that sessions could last between server restarts, hence the need for a 'store'. While my golang backend is running, I am able to set new sessions and retrieve them for multiple users/browsers. No problems there. When I restart my server, I notice that all session access results in session.IsNew == true
.
In Redis, I can see all the session keys after the restart, and even verified that .Get
ting the session results in the right ID retrieved, but IsNew
is still set.
I guess intuitively, this makes sense because there must be some map in memory that leads to the setting of IsNew
but I would think that if there was any hit to the store, IsNew should not be set. Am I going crazy? Is there something easy that I am doing wrong? Is this a fundamental misunderstanding of how to use sessions?
Please let me know if I need to include code or additional details.
评论:
droneprime:
gohacker:Answered this myself in case any one stumbles across it. https://stackoverflow.com/questions/45196950/gorilla-sessions-persistent-between-server-restarts/45197671#45197671
Use
gob
when you put the data in and when you try to take it out.
func NewCookieStore(keyPairs ...[]byte) *CookieStore
keyPairs ...[]byte
changing key pairs = invalidating the sessions
