Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package auth |
||
2 | |||
3 | import ( |
||
4 | "context" |
||
5 | |||
6 | "github.com/redis/go-redis/v9" |
||
7 | ) |
||
8 | |||
9 | // RedisRepository is the redis repository for the auth use case. |
||
10 | type RedisRepository struct { |
||
11 | RedisConn *redis.Client |
||
12 | } |
||
13 | |||
14 | // NewRedisRepository returns a new redis repository. |
||
15 | func NewRedisRepository(redisConn *redis.Client) IAuthRedisRepository { |
||
16 | return &RedisRepository{ |
||
17 | RedisConn: redisConn, |
||
18 | } |
||
19 | } |
||
20 | |||
21 | // HasState checks if the state exists in the redis database. |
||
22 | func (r *RedisRepository) HasState(ctx context.Context, state string) (bool, error) { |
||
23 | return r.RedisConn.SIsMember(ctx, "state", state).Result() |
||
24 | } |
||
25 | |||
26 | // SetState sets the state in the redis database. |
||
27 | func (r *RedisRepository) SetState(ctx context.Context, state string) error { |
||
28 | return r.RedisConn.SAdd(ctx, "state", state).Err() |
||
29 | } |
||
30 | |||
31 | // DeleteState deletes the state in the redis database. |
||
32 | func (r *RedisRepository) DeleteState(ctx context.Context, state string) error { |
||
33 | return r.RedisConn.SRem(ctx, "state", state).Err() |
||
34 | } |
||
35 |