modelRT/deploy/redis-test-data/util/redis.go

26 lines
403 B
Go

package util
import (
"context"
"time"
"github.com/redis/go-redis/v9"
)
func InitRedisClient(redisAddr string) *redis.Client {
rdb := redis.NewClient(&redis.Options{
Addr: redisAddr,
Password: "",
DB: 0,
})
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
_, err := rdb.Ping(ctx).Result()
if err != nil {
return nil
}
return rdb
}