123456789101112131415161718192021222324252627282930313233343536373839 |
- package auth
-
- import (
- "github.com/go-redis/redis"
- "sync"
- "time"
- )
-
- type RedisSessionStore struct {
- once *sync.Once
- client *redis.Client
- }
-
- func NewRedisSessionStore(address string, password string) *RedisSessionStore {
- session := &RedisSessionStore{once: &sync.Once{}}
- session.client = redis.NewClient(&redis.Options{
- Addr: address,
- Password: password,
- })
-
- if err := session.client.Ping().Err(); err != nil {
- panic(err)
- }
-
- return session
- }
-
- func (rss *RedisSessionStore) StoreJwtToken(key string, value string, timeout time.Duration) error {
- return rss.client.Set(key, value, timeout).Err()
- }
-
- func (rss *RedisSessionStore) IsExistsJwtToken(key string) bool {
- return rss.client.Exists(key).Val() == 1
- }
-
- func (rss *RedisSessionStore) DeleteJwtToken(key string) bool {
- return rss.client.Del(key).Val() == 1
- }
|