1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| package redisx
|
| import (
| "context"
| "fmt"
| "github.com/go-redis/redis/v8"
| )
|
| type Conf struct {
| Host string
| Port uint32
| Password string
| DB uint32
| }
|
| var client *redis.Client
|
| func GetRedisClient() *redis.Client {
| return client
| }
|
| func InitRedis(conf *Conf) error {
| client = redis.NewClient(&redis.Options{
| Addr: fmt.Sprintf("%s:%d", conf.Host, conf.Port),
| Password: conf.Password,
| DB: int(conf.DB),
| })
| _, err := client.Ping(context.TODO()).Result()
| if err != nil {
| return err
| }
| return nil
| }
|
|