我在Go中使用gin-gonic并使用github.com/gin-gonic/contrib/sessions
包中提供的Redis会话功能
store, _ := sessions.NewRedisStore(10, "tcp", "localhost:6379", "", []byte("secret"))
router.Use(sessions.Sessions("workino_session", store))
如何控制这些会话在Redis中的存储时间?
谢谢。
答案 0 :(得分:1)
尽管自述文件对文档有帮助,但GoDoc docs对此更为明确。
请注意,gin-gonic会话包使用下面的gorilla/sessions并共享相同的选项API。
// We check for errors.
store, err := sessions.NewRedisStore(10, "tcp", "localhost:6379", "", []byte("secret"))
if err != nil {
// Handle the error. Probably bail out if we can't connect.
}
// Ref: https://godoc.org/github.com/gin-gonic/contrib/sessions#Options
store.Options = &sessions.Options{
MaxAge: 86400,
Path: "/",
Secure: true,
HttpOnly: true,
}
// Use the store once configured.
router.Use(sessions.Sessions("workino_session", store))