Passed
Pull Request — main (#126)
by Yume
01:19
created

internal/card/redisRepository.go   A

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A card.withID 0 2 1
A card.RedisRepository.GetByID 0 2 1
A card.getBaseKey 0 2 1
A card.NewRedisRepository 0 2 1
1
package card
2
3
import (
4
	"context"
5
6
	"github.com/memnix/memnix-rest/pkg/utils"
7
	"github.com/redis/go-redis/v9"
8
)
9
10
func getBaseKey() string {
11
	return "card:id:"
12
}
13
14
func withID(getter func() string, id uint) string {
15
	return getter() + utils.ConvertUIntToStr(id)
16
}
17
18
type RedisRepository struct {
19
	RedisConn *redis.Client // RedisConn is the redis connection.
20
}
21
22
func NewRedisRepository(redisConn *redis.Client) IRedisRepository {
23
	return &RedisRepository{RedisConn: redisConn}
24
}
25
26
func (r RedisRepository) GetByID(ctx context.Context, id uint) (string, error) {
27
	return r.RedisConn.Get(ctx, withID(getBaseKey, id)).Result()
28
}
29