goheroku-redis

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


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 !


Solution

  • 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.