https://github.com/go-redis/redis
package main import ( "context" "fmt" "time" "github.com/go-redis/redis/v8" ) var ( ctx context.Context rdb *redis.Client ) func init() { rdb = redis.NewClient(&redis.Options{ Network: "tcp", Addr: "192.168.8.21:6379", Username: "tenacity", Password: "tenacity", DB: 0, PoolSize: 10, }) // var cancelFunc context.CancelFunc ctx, _ = context.WithTimeout(context.Background(), 5*time.Second) // defer cancelFunc() result, err := rdb.Ping(ctx).Result() fmt.Println("result:", result) fmt.Println("err:", err) } func main() { err := rdb.Set(ctx, "name", "go", 0).Err() result, err := rdb.Ping(ctx).Result() fmt.Println(result, err) if err != nil { // panic(err) fmt.Println("err:", err) } }