Skip to content

Commit

Permalink
Merge pull request #47 from agungwk/master
Browse files Browse the repository at this point in the history
Add redis session timeout
  • Loading branch information
kirsle authored Jun 23, 2023
2 parents e56ad19 + 1553313 commit e38f316
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sessions/redis/extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (s *Session) putRedisFrozen(username string, data *sessions.UserData, froze
return err
}

err = s.client.Set(key, string(encoded), 0).Err()
err = s.client.Set(key, string(encoded), s.sessionTimeout).Err()
if err != nil {
return err
}
Expand Down
18 changes: 12 additions & 6 deletions sessions/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package redis
import (
"fmt"
"strings"
"time"

"github.com/aichaos/rivescript-go/sessions"
redis "gopkg.in/redis.v5"
Expand All @@ -25,13 +26,17 @@ type Config struct {

// Settings for the Redis client.
Redis *redis.Options

// Session timeout using time.duration
SessionTimeout time.Duration
}

// Session wraps a Redis client connection.
type Session struct {
prefix string
frozenPrefix string
client *redis.Client
prefix string
frozenPrefix string
client *redis.Client
sessionTimeout time.Duration
}

// New creates a new Redis session instance.
Expand All @@ -58,9 +63,10 @@ func New(options *Config) *Session {
}

return &Session{
prefix: options.Prefix,
frozenPrefix: options.FrozenPrefix,
client: redis.NewClient(options.Redis),
prefix: options.Prefix,
frozenPrefix: options.FrozenPrefix,
client: redis.NewClient(options.Redis),
sessionTimeout: options.SessionTimeout,
}
}

Expand Down

0 comments on commit e38f316

Please sign in to comment.