2

In Golang,Go redis has 2 clients, redis.NewClient and redis.NewClusterClient.

I am not sure which one to use for connecting to elasticcache for redis.

I want to use the client which will only connect to one endoint of cluster and that enpoint will make sure I get or set the keys for redis. As clusters in elasticcache are aware of eachother

Any help on this would be very much appreciated

1 Answers1

2

I would like to use NewClusterClient, for your question

I want to use the client which will only connect to one endoint of cluster and that enpoint will make sure I get or set the keys for redis

Please make sure all those parameters are false

        ReadOnly:       false,
        RouteRandomly:  false,
        RouteByLatency: false,

Sample codes

import (
  goredis "github.com/go-redis/redis/v8"
)

goredis.NewClusterClient(&goredis.ClusterOptions{
        Addrs:        []string{"cluster-configuration-endpoint:6379"},
        Password:     "password",
        PoolSize:     10, 
        MinIdleConns: 10,

        DialTimeout:  5 * time.Second,
        ReadTimeout:  3 * time.Second,
        WriteTimeout: 3 * time.Second,
        PoolTimeout:  4 * time.Second,

        IdleCheckFrequency: 60 * time.Second,
        IdleTimeout:        5 * time.Minute,
        MaxConnAge:         0 * time.Second,

        MaxRetries:      10,
        MinRetryBackoff: 8 * time.Millisecond,
        MaxRetryBackoff: 512 * time.Millisecond,

        TLSConfig: &tls.Config{
            InsecureSkipVerify: true,
        },

        ReadOnly:       false,
        RouteRandomly:  false,
        RouteByLatency: false,
    })
zangw
  • 43,869
  • 19
  • 177
  • 214
  • In rediscluster.Options there is one parameter to set NewClient. Do I need to set that as well or above configuration which you provided will work and I can get and set the keys using above code which you shared. I thought I have to only set that option (newclient in rediscluster.options), there also we can specify endpoint – Darshan Mestry Sep 30 '22 at 12:36
  • @DarshanMestry, I did not get a chance to test it. I think you could test it – zangw Sep 30 '22 at 12:43
  • I went ahead with your method of creating cluster client, It worked as expected. Thanks! - @zangw – Darshan Mestry Oct 07 '22 at 08:36