如何解决无法从Gofiber会话中的会话存储中获取价值
我正在使用光纤golang框架。我不明白为什么我不能从另一个请求或内部请求中获得存储(在此情况下为Redis)中设置的值。下面是代码:
sessionProvider := redis.New(redis.Config{
KeyPrefix: "session",Addr: "127.0.0.1:6379",PoolSize: 8,IdleTimeout: 30 * time.Second,})
sessions := session.New(session.Config{
Provider: sessionProvider,})
// sample routes for testing session
app.Get("/testing1",func(c *fiber.Ctx) {
store := sessions.Get(c)
// set value to the session store
store.Set("name","King Windrol")
store.Save()
})
app.Get("/testing2",func(c *fiber.Ctx) {
store := sessions.Get(c)
c.Send(store.Get("name"))
})
我尝试从同一请求中获取它,它似乎在调用store.Save()
之前就可以使用,但之后却无法使用!它只会返回nil
解决方法
app.Get("/testing1",func(c *fiber.Ctx) {
store := sessions.Get(c)
// set value to the session store
store.Set("name","King Windrol")
store.Save()
c.SendStatus(200) //add this
})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。