Total Lines | 28 |
Duplicated Lines | 0 % |
Changes | 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 |