RedisGolang连接腾讯云数据库Redis

Golang连接

  • step1:下载golang的redis客户端

gogetgithub.com/garyburd/redigo/redis

  • step2:编写测试用例

packagemainimport("fmt""github.com/garyburd/redigo/redis")funcmain(){host:="jredis-cn-north-1-prod-redis-xxxxxxxxxx.jdcloud.com"//控制台显示的地址port:=6379c,err:=redis.Dial("tcp",fmt.Sprintf("%s:%d",host,port))iferr!=nil{fmt.Println("Connecttorediserror",err)return}deferc.Close()_,err:=c.Do("AUTH","")iferr!=nil{fmt.Println("redisauthfailed:",err)return}_,err:=c.Do("SET","key","jcloud-redis")iferr!=nil{fmt.Println("redissetfailed:",err)return}_,err:=c.Do("GET","key")iferr!=nil{fmt.Println("redisgetfailed:",err)return}//doothercommand...}