From 996961dd860060419d7c27654f05a81cd0073554 Mon Sep 17 00:00:00 2001 From: kataras Date: Sun, 20 Aug 2017 18:57:19 +0300 Subject: [PATCH] fix redis sessiondb expiration I don't know why I did add LifeTime.Second() back then, it was silly of me but didn't receive any reports except a commit comment 25 minutes ago, so we can assume that redis is almost "dead" nowdays. Thank you for the notice @sy264115809 Former-commit-id: 140caa2a42aa16b1e80905d24976c481eae24c69 --- sessions/sessiondb/redis/database.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sessions/sessiondb/redis/database.go b/sessions/sessiondb/redis/database.go index 8ee35587..d3015226 100644 --- a/sessions/sessiondb/redis/database.go +++ b/sessions/sessiondb/redis/database.go @@ -2,6 +2,7 @@ package redis import ( "runtime" + "time" "github.com/kataras/golog" "github.com/kataras/iris/sessions" @@ -84,7 +85,14 @@ func (db *Database) sync(p sessions.SyncPayload) { return } - db.redis.Set(p.SessionID, storeB, p.Store.Lifetime.Second()) + // not expire if zero + seconds := 0 + + if lifetime := p.Store.Lifetime; !lifetime.IsZero() { + seconds = int(lifetime.Sub(time.Now()).Seconds()) + } + + db.redis.Set(p.SessionID, storeB, seconds) } // Close shutdowns the redis connection.