29 lines
666 B
Go
29 lines
666 B
Go
package captcha
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
)
|
|
|
|
type redisStore struct {
|
|
client *redis.Client
|
|
}
|
|
|
|
func NewRedisStore(client *redis.Client) Store {
|
|
return &redisStore{client: client}
|
|
}
|
|
func (s *redisStore) Set(ctx context.Context, key string, value string, timeout time.Duration) error {
|
|
return s.client.Set(ctx, key, value, timeout).Err()
|
|
}
|
|
func (s *redisStore) Get(ctx context.Context, key string) (string, error) {
|
|
return s.client.Get(ctx, key).Result()
|
|
}
|
|
func (s *redisStore) Delete(ctx context.Context, key string) error {
|
|
return s.client.Del(ctx, key).Err()
|
|
}
|
|
func (s *redisStore) Close() error {
|
|
return s.client.Close()
|
|
}
|