登录
首页 >  Golang >  Go问答

无法从 Go Fiber 会话存储中检索会话值

来源:stackoverflow

时间:2024-03-29 13:09:21 367浏览 收藏

最近发现不少小伙伴都对Golang很感兴趣,所以今天继续给大家介绍Golang相关的知识,本文《无法从 Go Fiber 会话存储中检索会话值》主要内容涉及到等等知识点,希望能帮到你!当然如果阅读本文时存在不同想法,可以在评论中表达,但是请勿使用过激的措辞~

问题内容

我正在使用 fiber 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
    
})

以上就是《无法从 Go Fiber 会话存储中检索会话值》的详细内容,更多关于的资料请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>