RedisClient 连接 Redis
(pwd string)
| 18 | |
| 19 | // RedisClient 连接 Redis |
| 20 | func RedisClient(pwd string) (err error) { |
| 21 | |
| 22 | Rdb = redis.NewClient(&redis.Options{ |
| 23 | Addr: fmt.Sprintf("%s:%s", Rhost, Rport), |
| 24 | Password: pwd, // 密码认证 |
| 25 | }) |
| 26 | |
| 27 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 28 | |
| 29 | defer cancel() |
| 30 | |
| 31 | pong, err := Rdb.Ping(ctx).Result() |
| 32 | if err != nil { |
| 33 | return err |
| 34 | } |
| 35 | if strings.Contains(pong, "PONG") { |
| 36 | redisVersion() |
| 37 | } |
| 38 | return nil |
| 39 | } |
| 40 | |
| 41 | var wg sync.WaitGroup |
| 42 |
no test coverage detected