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