Use redis to store the sessions

This commit is contained in:
2024-07-29 21:54:37 +02:00
parent 52c3679158
commit 5d225f0186
5 changed files with 30 additions and 7 deletions

View File

@ -15,7 +15,9 @@ import (
"os"
"time"
"github.com/alexedwards/scs/redisstore"
"github.com/alexedwards/scs/v2"
"github.com/gomodule/redigo/redis"
)
const portNumber = ":8080"
@ -80,7 +82,16 @@ func run() (*driver.DB, error) {
// change this to true when in production
app.InProduction = *inProduction
// Establish connection pool to Redis.
pool := &redis.Pool{
MaxIdle: 10,
Dial: func() (redis.Conn, error) {
return redis.Dial("tcp", "localhost:6379")
},
}
session = scs.New()
session.Store = redisstore.New(pool)
session.Lifetime = 24 * time.Hour
session.Cookie.Persist = true
session.Cookie.SameSite = http.SameSiteLaxMode