Passed
Pull Request — main (#166)
by Yume
02:23
created

auth.NewRedisRepository   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 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