Help with gorilla/sessions?

xuanbao · · 516 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I have a general question about sessions. I am not very seasoned when it comes to this subject. I&#39;ve tried with: </p> <pre><code>NewRediStore (gopkg.in/boj/redistore.v1) NewCookieStore NewFileSystemStore </code></pre> <p>I was under the impression that sessions could last between server restarts, hence the need for a &#39;store&#39;. 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 <code>session.IsNew == true</code>. </p> <p>In Redis, I can see all the session keys after the restart, and even verified that <code>.Get</code>ting the session results in the right ID retrieved, but <code>IsNew</code> is still set. </p> <p>I guess intuitively, this makes sense because there must be some map in memory that leads to the setting of <code>IsNew</code> 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?</p> <p>Please let me know if I need to include code or additional details.</p> <hr/>**评论:**<br/><br/>droneprime: <pre><p>Answered this myself in case any one stumbles across it. <a href="https://stackoverflow.com/questions/45196950/gorilla-sessions-persistent-between-server-restarts/45197671#45197671" rel="nofollow">https://stackoverflow.com/questions/45196950/gorilla-sessions-persistent-between-server-restarts/45197671#45197671</a></p> <p>Use <code>gob</code> when you put the data in <strong>and</strong> when you try to take it out.</p></pre>gohacker: <pre><p><code>func NewCookieStore(keyPairs ...[]byte) *CookieStore</code></p> <p><code>keyPairs ...[]byte</code></p> <p>changing key pairs = invalidating the sessions</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

516 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传