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

services/auth/redisRepository.go   A

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 15
dl 0
loc 33
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A auth.NewRedisRepository 0 3 1
A auth.*RedisRepository.DeleteState 0 2 1
A auth.*RedisRepository.SetState 0 2 1
A auth.*RedisRepository.HasState 0 2 1
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