英文:
Using AWS MemoryDB with Go Redis client
问题
我正在使用go-redis库将AWS MemoryDB集群用作数据库。
我能够通过VPN连接到集群,但是以下命令行命令可以连接到数据库:
redis-cli --tls -u redis://<memory-db-endpoint> -p 6379
但是以下Go代码无法工作,并出现i/o timeout
错误。
conf, err := redis.ParseURL("redis://$CLUSTER_ENDPOINT:6379")
if err != nil {
panic(err)
}
cl := redis.NewClient(conf)
res, err := cl.Ping(context.Background()).Result()
if err != nil {
panic(err)
}
如何建立与单节点AWS MemoryDB集群的连接?
英文:
I am using go-redis library to use AWS MemoryDB cluster as a database.
I am able to connect to cluster with VPN connection, however
the following cli command connects to database:
redis-cli --tls -u redis://<memory-db-endpoint> -p 6379
but the following Go code does not work and get i/o timeout
error.
conf, err := redis.ParseURL("redis://$CLUSTER_ENDPOINT:6379")
if err != nil {
panic(err)
}
cl := redis.NewClient(conf)
res, err := cl.Ping(context.Background()).Result()
if err != nil {
panic(err)
}
what is needed to establish a connection with a single node AWS MemoryDB cluster?
答案1
得分: 2
Redis URIs with TLS must begin with "rediss://", not "redis://"; see https://www.iana.org/assignments/uri-schemes/prov/rediss for more information.
This code works:
conf, err := redis.ParseURL("rediss://$CLUSTER_ENDPOINT:6379")
if err != nil {
panic(err)
}
cl := redis.NewClient(conf)
res, err := cl.Ping(context.Background()).Result()
if err != nil {
panic(err)
}
英文:
Redis URIs with TLS must begin with "rediss://", not "redis://"; see https://www.iana.org/assignments/uri-schemes/prov/rediss for more information.
This code works:
conf, err := redis.ParseURL("rediss://$CLUSTER_ENDPOINT:6379")
if err != nil {
panic(err)
}
cl := redis.NewClient(conf)
res, err := cl.Ping(context.Background()).Result()
if err != nil {
panic(err)
}
答案2
得分: 1
问题是go-redis
库不知道如何获取用于TLS连接的系统证书。
因此,以下是如何将系统证书池传递给连接配置的方法。
...
pool, err := x509.SystemCertPool()
if err != nil {
panic(err)
}
conf.TLSConfig = &tls.Config{
RootCAs: pool,
}
...
英文:
The problem is go-redis
library does not know how to get system certificates for TLS connections.
So, here is how to pass system certificate pool to connection config.
...
pool, err := x509.SystemCertPool()
if err != nil {
panic(err)
}
conf.TLSConfig = &tls.Config{
RootCAs: pool,
}
...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论