Mac下Golang连接Docker启动的redis conne
2022-09-14 本文已影响0人
crazy一笑
我的问题是一开始使用Docker中的映射端口6379
,所以才出现问题,不同容器应该使用宿主机的端口访问,查看端口:
$ docker ps
docker-ps.png
package main
import (
"fmt"
"github.com/garyburd/redigo/redis"
)
func main() {
//c, err := redis.Dial("tcp", "localhost: 6379")//错误写法
c, err := redis.Dial("tcp", "localhost:55001")
if err != nil {
fmt.Println("redis dial err: ", err)
return
}
fmt.Println("redis dial success: ", c)
}
zhouxianmingdeMacBook-Pro:redis zhouxianming$ go run main.go
redis dial success: &{{0 0} 0 <nil> 0x14000186000 0 0x14000182060 0 0x1400018a000 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]}