0

Golang and redis newbie. I have a redis cluster in amazon with 9 nodes. 3 master and for each master we have 2 slaves. Total nine nodes. Not using RetryConn returns a MOVED node error and using it returns a null. Is it important to give the IP address for all the nodes? IS it ok to give the host name that amz gives when we create the cluster.

cluster = redisc.Cluster{
         StartupNodes: []string{"*****"},
         DialOptions:  []redis.DialOption{redis.DialConnectTimeout(5 * 
time.Minute)},
         CreatePool: createPool,
         }
         if err := cluster.Refresh(); err != nil {
             log.Fatalf("Refresh failed: %v", err)
         }else{
             log.Println("Refresh worked")
         } 

func createPool(addr string, opts ...redis.DialOption) (*redis.Pool, 
error) {
return &redis.Pool{
    MaxIdle:     5,
    MaxActive:   10,
    IdleTimeout: time.Minute,
    Dial: func() (redis.Conn, error) {
        c, err := redis.Dial("tcp", "***", opts...)
        if err != nil {
            log.Panic(err)
        }        

}, nil

}

func RedisConnection() redis.Conn {  
// grab a connection from the pool
conn := cluster.Get()
if(conn != nil){
    rc, err := redisc.RetryConn(conn, 9, 1*time.Second)
    if(err ==nil){
        return rc
    }
    return nil
  }
}

What am I doing wrong? Also how do we binding the conn needed?Any insight would be very helpful

LearnGo
  • 105
  • 8
  • The logic around ` if(err !=nil){ return rc } ` seems odd. (returning value only on error?). Also, should that parameter to `redis.Dial()` not be `addr`? – Hein Oldewage Nov 30 '17 at 06:36
  • Typo while I was posting the question. func . What do mean the addr. Does it have to be the IP ? RedisConnection() redis.Conn { conn := cluster.Get() if(conn != nil){ rc, err := redisc.RetryConn(conn, 9, 1*time.Second) if(err == nil){ return rc }else{ spew.Dump(err) return nil } }else{ log.Println("Conn is nil") return nil } return nil } – LearnGo Nov 30 '17 at 17:42
  • When I use just addr in the redis.Dial("tcp",addr) I get the following error FAIL 0 ERR EXEC without MULTI – LearnGo Nov 30 '17 at 18:18

0 Answers0