| Total Lines | 30 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package user |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "context" |
||
| 5 | |||
| 6 | "github.com/memnix/memnix-rest/config" |
||
| 7 | "github.com/memnix/memnix-rest/pkg/utils" |
||
| 8 | "github.com/redis/go-redis/v9" |
||
| 9 | ) |
||
| 10 | |||
| 11 | // RedisRepository is the interface for the redis repository. |
||
| 12 | type RedisRepository struct { |
||
| 13 | RedisConn *redis.Client // RedisConn is the redis connection. |
||
| 14 | } |
||
| 15 | |||
| 16 | // NewRedisRepository returns a new redis repository. |
||
| 17 | func NewRedisRepository(redisConn *redis.Client) IRedisRepository { |
||
| 18 | return &RedisRepository{ |
||
| 19 | RedisConn: redisConn, |
||
| 20 | } |
||
| 21 | } |
||
| 22 | |||
| 23 | // Get gets the user by id. |
||
| 24 | func (r *RedisRepository) Get(ctx context.Context, id uint) (string, error) { |
||
| 25 | return r.RedisConn.Get(ctx, keyPrefix+utils.ConvertUIntToStr(id)).Result() |
||
| 26 | } |
||
| 27 | |||
| 28 | // Set sets the user by id. |
||
| 29 | func (r *RedisRepository) Set(ctx context.Context, id uint, value string) error { |
||
| 30 | return r.RedisConn.Set(ctx, keyPrefix+utils.ConvertUIntToStr(id), value, config.RedisDefaultExpireTime).Err() |
||
| 31 | } |
||
| 32 |