I was wondering if anyone has had any experience with using the github.com/go-redis/redis package to connect to a Digital Ocean managed Redis database?
I’ve tried the basic connection from the README file
client := redis.NewClient(&redis.Options{
Addr: "CONNECT_STRING : PORT",
Password: "PASSWORD", // password set
DB: 0, // use default DB
MaxRetries: 3, //added after a google suggestion
})
pong, err = client.Ping().Result()
if err != nil {
fmt.Printf("Cannot Ping: %v\n", err.Error())
} else {
fmt.Printf("Pong: %v\n", pong)
}
But when I come to test the connect, I don’t receive Pong as a reply, I get an error with the message
EOF
And when I come to check the logs in the control panel, I cannot see anything that looks like a connection attempt.
Any help would be greatly appreciated.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.
Hey! Just faced the same issue and find a working solution for using with
github.com/go-redis/redis/v8
(redis)you can enable TLS easily with providing empty struct
&tls.Config{}
toTLSConfig
in your connection config, so connecting to DO Managed Redis DB with connection string looks like:Have a good day!
It’s bad, that DO doesn’t have an option to disable tls for Redis. I recently migrated from dickerized Redis on droplet - to managed DO Redis and had to change all connection code to Redis…
I found 2 ways to do that in go:
Native go, I’m using
redigo
and there is TLS option.I haven’t tried it, but seems like it does tls. The problem with this approach for me was, that I’m using Iris framework, that doesn’t currently have an option to add this flag.Global way with stunnel. I followed this instruction and simply added it to my docker app.
apt-get install stunnel4 -y
wget http://ssl.rackspaceclouddb.com/rackspace-ca-2016.pem
my.conf
tunnel my.conf
Actually, maybe this will help you? I couldn’t figure it out either, and generally it seems like configuring tls for redis is a bit of a pain.
What I ended up doing, which works just fine for my purposes, was run redis as a docker container on the host. So I have a docker-compose setup that launches my app and redis as separate services, and the app depends on the redis service. Then I just set ‘redis’ (or whatever you decide to name the service) as my redis host.
I’m sure you could do this easily without a docker-compose setup, but this has been my local dev situation so it was easier to just translate that over for me.
Hope it helps