Passed
Pull Request — main (#166)
by Yume
02:36
created

user.*RedisRepository.Set   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 3
dl 0
loc 2
rs 10
c 0
b 0
f 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