Passed
Push — main ( f6597a...58b626 )
by Yume
01:31 queued 12s
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 2
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
type RedisRepository struct {
12
	RedisConn *redis.Client
13
}
14
15
func NewRedisRepository(redisConn *redis.Client) IRedisRepository {
16
	return &RedisRepository{
17
		RedisConn: redisConn,
18
	}
19
}
20
21
func (r *RedisRepository) Get(id uint) (string, error) {
22
	return r.RedisConn.Get(context.Background(), "user:"+utils.ConvertUIntToStr(id)).Result()
23
}
24
25
func (r *RedisRepository) Set(id uint, value string) error {
26
	return r.RedisConn.Set(context.Background(), "user:"+utils.ConvertUIntToStr(id), value, config.RedisDefaultExpireTime).Err()
27
}
28