运行前必备
示例代码
package mainimport ("context""fmt""github.com/redis/go-redis/v9""log""time")func main() {const host = "127.0.0.1"const port = 6379const pwd = "*******"newClient := redis.NewClient(&redis.Options{Addr: fmt.Sprintf("%s:%d", host, port),Password: pwd,})ctx, cancelFunc := context.WithTimeout(context.Background(), 10*time.Second)defer cancelFunc()statusCmd := newClient.Ping(ctx)log.Printf(" ping status: %s", statusCmd.Val())}