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.once.Do(func() { 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 { if v := rss.client.Exists(key).Val(); v != 1 { return false } return true } // DeleteJwtToken delete jwt token func (rss *RedisSessionStore) DeleteJwtToken(key string) bool { if v := rss.client.Del(key).Val(); v != 1 { return false } return true }