I cannot connect to my local redis through my go project.
I am starting redis using docker compose like so:
redis:
image: redis:6.2.3-alpine
platform: linux/x86_64
ports:
- 6379:6379
I’m trying to connect to this in my go project like this:
func connect()*RedisConnection {
opts := &redis.Options{
Addr: "localhost:6379",
Password: "",
DB: 0,
}
opts.TLSConfig = &tls.Config{
InsecureSkipVerify: true,
}
client := redis.NewClient(opts)
opts.OnConnect = func(ctx context.Context, cn *redis.Conn) error {
log.Info().Msgf("connected to redis..")
return nil
}
if err := client.Ping(ctx).Err(); err != nil {
log.Info().Msgf(err.Error())
}
return &RedisConnection{
redisClient: client,
}
However this constantly fails and I get a “context deadline exceeded error”.
I’m not sure what I’m doing wrong?