gin-gonic / contrib

Collection of middlewares created by the community

Home Page:https://gin-gonic.github.io/gin/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Redis session store ,Options not working

opened this issue · comments

    `s := gin.New()
s.Use(gin.Recovery())
s.Use(gin.Logger())
store, _ := sessions.NewRedisStore(10, "tcp", "192.168.99.100:32775", "", []byte("secret"))
store.Options(sessions.Options{
    MaxAge: 3600,
    Path: "/",
    Secure: true,
    HttpOnly: true,
})
s.Use(sessions.Sessions("session", store))
s.GET("/home",controllers.Home)

`
controllers.Home

`
func Home(c *gin.Context) {

s := sessions.Default(c)
var count int
v := s.Get("count")
if v == nil {
    count = 0
} else {
    count = v.(int)
    count += 1
}
s.Set("count", count)
s.Save()

c.JSON(200, gin.H{"count": count})

}`


/home return {"count":0} with no cookie

yes it is not working