有奖捉虫:云通信与企业服务文档专题,速来> HOT

运行前必备

下载客户端 Go-redis

示例代码

package main

import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
"log"
"time"
)
func main() {
const host = "127.0.0.1"
const port = 6379
const 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())
}