I have redis exposed via a container:
service_redis 0.0.0.0:6379->6379/tcp
And I can even connect to it via redis-cli
command with. But what I actually can't do, is to connect to via Go code (which also exists in a separate container, btw)
Here's how my client looks like:
opts := &redis.Options{
Addr: addr,
Password: pass,
DB: db,
}
cli := redis.NewClient(opts)
fmt.Println(master.Ping().Err())
fmt.Println(slave.Get("REAL_KEY").String())
I've tried to put in the addr
variable the following:
-
0.0.0.0:6379
AND127.0.0.1:6379
. The response was e.g.:
<nil>
get REAL KEY: dial tcp 0.0.0.0:6379: connect: connection refused
-
service_redis:6379
with the following response:
<nil>
get REAL KEY: dial tcp: lookup service_redis on 169.254.169.254:53: no such host
How can I solve the problem and what did I wrong?