在 Golang 中使用 Redis 配置杜松子酒会话



我在 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 中的存储时间?

谢谢。

虽然自述文件很少,但 GoDoc 文档对此更清楚一些。

请注意,gin-gonic 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))

最新更新