我在尝试使用redis-golang驱动程序连接到Redis时遇到问题。 这是我的
docker-compose.yml
文件 :
version: "3"
services:
driver:
build: ./API-Golang
command: go run app.go
volumes:
- ./API-Golang:/app
ports:
- "8080:8080"
depends_on:
- db
- redis
links :
- redis
- db
redis:
image: redis
container_name: redis
ports: ["6379:6379"]
db:
image: mongo:3.4.2
container_name: mongodb
ports : ["27017:27017"]
这是我试图连接到redis (API-Golang/数据库/allSystem.go)的代码:
redisConn := RedisHost{
Address: "localhost:6379",
Password: "",
DB: 0,
}
redisConnection, err := redisConn.Connect()
if err != nil {
panic(err)
}
我试图改变 localhost
为 redis
但它还是不管用。错误如下:
driver_1 | panic: dial tcp [::1]:6379: getsockopt: connection refused
driver_1 |
driver_1 | goroutine 1 [running]:
driver_1 | github.com/Gujarats/API-Golang/database.SystemConnection(0x48)
driver_1 | /go/src/github.com/Gujarats/API-Golang/database/allSystem.go:32 +0x3d3
driver_1 | main.main()
driver_1 | /go/src/github.com/Gujarats/API-Golang/app.go:24 +0x34
driver_1 | exit status 2
你知道哪里出错了吗?