{"id":"52928ffe039e9ed0","repo":"go-redis/redis","slug":"to-route-commands-randomly-use-newfailovercluster","errorCode":null,"errorMessage":"to route commands randomly, use NewFailoverClusterClient","messagePattern":"to route commands randomly, use NewFailoverClusterClient","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sentinel.go","lineNumber":543,"sourceCode":"\t}\n\n\treturn o, nil\n}\n\n// NewFailoverClient returns a Redis client that uses Redis Sentinel\n// for automatic failover. It's safe for concurrent use by multiple\n// goroutines.\n// Passing nil FailoverOptions will cause a panic.\nfunc NewFailoverClient(failoverOpt *FailoverOptions) *Client {\n\tif failoverOpt == nil {\n\t\tpanic(\"redis: NewFailoverClient nil options\")\n\t}\n\n\tif failoverOpt.RouteByLatency {\n\t\tpanic(\"to route commands by latency, use NewFailoverClusterClient\")\n\t}\n\tif failoverOpt.RouteRandomly {\n\t\tpanic(\"to route commands randomly, use NewFailoverClusterClient\")\n\t}\n\n\tsentinelAddrs := make([]string, len(failoverOpt.SentinelAddrs))\n\tcopy(sentinelAddrs, failoverOpt.SentinelAddrs)\n\n\trand.Shuffle(len(sentinelAddrs), func(i, j int) {\n\t\tsentinelAddrs[i], sentinelAddrs[j] = sentinelAddrs[j], sentinelAddrs[i]\n\t})\n\n\tfailover := &sentinelFailover{\n\t\topt:           failoverOpt,\n\t\tsentinelAddrs: sentinelAddrs,\n\t}\n\n\topt := failoverOpt.clientOptions()\n\topt.Dialer = masterReplicaDialer(failover)\n\topt.init()\n","sourceCodeStart":525,"sourceCodeEnd":561,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/sentinel.go#L525-L561","documentation":"Error \"to route commands randomly, use NewFailoverClusterClient\" thrown in go-redis/redis.","triggerScenarios":"Thrown at sentinel.go:543 when the library encounters an invalid state.","commonSituations":"Validate routing flags against the chosen client type.","solutions":["Use NewFailoverClusterClient for RouteRandomly routing","Disable RouteRandomly for the simple failover client"],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}