云数据库 Tendis Go 连接示例

运行前必备:
下载客户端 Go-redis。示例代码:package mainimport( “fmt” “redis” “log”)func main() { const host=192.xx.xx.195 const port=6379 const instanceId=”84ffd722-b506-4934-9025-64xxx997b” const pass=”123d7sq” // 连接 T。

相关产品
云数据库 Tendis 产品页,含版本规格、价格与购买入口。

运行前必备:
下载客户端 Go-redis。示例代码:package mainimport( "fmt" "redis" "log")func main() { const host=192.xx.xx.195 const port=6379 const instanceId="84ffd722-b506-4934-9025-64xxx997b" const pass="123d7sq" // 连接 T。

运行前必备:
下载客户端 Go-redis。示例代码:package mainimport( "fmt" "redis" "log")func main() { const host=192.xx.xx.195 const port=6379 const instanceId="84ffd722-b506-4934-9025-64xxx997b" const pass="123d7sq" // 连接 Tendis 服务器 192.xx.xx.195:6379 并授权 instanceId 密码 spec := redis.DefaultSpec().Host(host).Port(port).Password(instanceId+":"+pass); client, err := redis.NewSynchClientWithSpec(spec) if err != nil { // 是否连接出错 log.Println("error on connect redis server") return } newvalue :=[]byte("QcloudV5!"); err=client.Set("name",newvalue); if err != nil { // 设置值出错 log.Println(err) return } value, err := client.Get("name") // 取值 if err != nil {  log.Println(err) return } fmt.Println("name value is:",fmt.Sprintf("%s", value)) //输出} 运行结果:


赞 (0)
上一篇 4天前
下一篇 4天前