如何解决wsarecv连接错误?Golang / Heroku redis

huangapple go评论92阅读模式
英文:

How to solve the wsarecv connection error? Golang / Heroku redis

问题

我正在尝试将我的Go应用程序连接到Heroku Redis数据库。使用以下代码:

(使用"github.com/go-redis/redis/v8")

opt, err := redis.ParseURL("redis://:PASSWORD@AWS-HOST:15670/0")
if err != nil {
    panic(err)
}
rdb := redis.NewClient(opt)
usu := rdb.Get(ctx, userID)

但是我遇到了以下错误:

get 61d4bb472db95c17de8c: wsarecv: 远程主机强制关闭了一个现有的连接。

HEROKU凭据

感谢任何帮助!

英文:

I'm trying to connect my go app to a heroku redis db. With this code:

(using "github.com/go-redis/redis/v8")

opt, err := redis.ParseURL("redis://:PASSWORD@AWS-HOST:15670/0")
	if err != nil {
		panic(err)
	}
	rdb := redis.NewClient(opt)
	usu := rdb.Get(ctx, userID)

But i'm getting this error:

> get 61d4bb472db95c17de8c: wsarecv: An existing connection was
> forcibly closed by the remote host.

HEROKU CREDENTIALS

I appreciate any help !

答案1

得分: 0

尝试关闭RDB持久化功能。如果仍然出现相同的错误,这意味着Heroku存在问题。

为了将数据持久化到磁盘上,RDB需要经常进行fork()操作,使用子进程进行持久化。如果数据集很大,fork()可能会耗时,并且可能导致Redis在一些毫秒甚至一秒钟内停止为客户端提供服务,尤其是在数据集非常大且CPU性能不佳的情况下。

为了更好地理解,请参考以下链接:https://redis.io/topics/persistence

确保您创建一个连接实例,并在各个地方都使用它,这样是线程安全的。

还要确保:

启用TCP keepalive -> 这将防止意外的连接关闭事件。

您可以参考以下链接:https://redis.io/topics/clients

增加opt.MaxRetries的值。

英文:

Try by doing RDB persistence off. If you still get the same error it means there is issue with Heroku.

RDB needs to fork() often in order to persist on disk using a child process.
Fork() can be time consuming if the dataset is big, and may result in Redis
to stop serving clients for some millisecond or even for one second if the
dataset is very big and the CPU performance not great.

For better understanding refer this link : https://redis.io/topics/persistence

Make sure, you create one instance for connection and use it everywhere, it is thread safe.

Also make sure :

TCP keepalive is enable -> It will prevent unexpected connection closed events.

You can refer this link : https://redis.io/topics/clients

Increase the opt.MaxRetries.

huangapple
  • 本文由 发表于 2022年1月10日 14:39:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/70648654.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定