Passed
Push — main ( 0795ea...57a23e )
by Yume
02:19 queued 01:06
created

mcq.getBaseKey   A

Complexity

Conditions 1

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
package mcq
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 "mcq: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
// GetByID gets the mcq by id.
23
func (r RedisRepository) GetByID(ctx context.Context, id uint) (string, error) {
24
	return r.RedisConn.Get(ctx, withID(getBaseKey, id)).Result()
25
}
26
27
func NewRedisRepository(redisConn *redis.Client) IRedisRepository {
28
	return RedisRepository{RedisConn: redisConn}
29
}
30