How to Access Cluster Instance

This guide demonstrates how to establish connections to Redis Cluster instances using industry-standard client libraries. The examples cover configuration details for go-redis, Jedis, Lettuce, and Redisson. For additional client options, refer to Connect with Redis client API libraries.

TOC

Authentication Requirements

Redis Cluster instances implement the following authentication options:

  • Password Authentication: When configured with a password, all client connections must provide valid credentials
  • Password-less Access: If the Set Password option is disabled during instance creation, clients can connect without authentication
Security Best Practice

For production environments, implementing password authentication is strongly recommended to protect your data. Refer to User Management for detailed instructions on configuring and maintaining secure credentials.

Connection Endpoint Reference

Internal Cluster Access

For applications deployed within the same Kubernetes cluster, internal access endpoints are available through the Access Method tab under the Access within the Cluster section.

ParameterDescription
Connection AddressKubernetes service name and port combinations for each shard in the Redis Cluster

External Cluster Access

For applications connecting from outside the Kubernetes environment, external access endpoints are available when configured during instance creation. These endpoints can be found in the Access Method tab under the Access from outside the Cluster section.

Endpoint TypeDescription
Shard AddressExternal IP addresses and ports for pods of shard in the Redis Cluster, enabling connectivity from outside the Kubernetes network

Interactive Debugging

For administrative operations and troubleshooting, the Redis CLI provides direct access to cluster nodes:

  1. Access the Terminal Console from the instance details page
  2. Connect to any node using the cluster-aware client mode:
redis-cli -c -h <internal-routing-ip> -p 6379

Example debugging session demonstrating slot-based redirection:

192.168.0.10:6379> set a 1
-> Redirected to slot [15495] located at 192.168.0.10:6379
OK
192.168.0.10:6379> get a
"1"
192.168.0.10:6379>

The -c flag enables automatic following of MOVED and ASK redirections, which is essential when working with Redis Cluster.

Client Integration Examples

The following examples demonstrate best practices for connecting to Redis Cluster instances with various client libraries.

go-redis
Jedis
Lettuce
Redisson
package main

import (
    "context"
    "fmt"
    "time"
    // It is recommended to periodically upgrade to the latest version of the client for the latest bug fixes.
    "github.com/redis/go-redis/v9"
)

func main() {
    client := redis.NewClusterClient(&redis.ClusterOptions{
        Addrs:    []string{"<address>"},
        Password: "<password>",
        OnConnect: func(ctx context.Context, conn *redis.Conn) error {
            ctx, cancel := context.WithTimeout(ctx, 500*time.Millisecond)
            defer cancel()
            return conn.Ping(ctx).Err()
        },
        // Client name for tracking purposes
        ClientName: "go-demo",
        // Use Context for timeout control
        ContextTimeoutEnabled: true,
        // Maximum number of redirects in case of MOVED or ASK
        MaxRedirects: 3,
        // Maximum number of retries
        MaxRetries: 3,
        // Minimum retry backoff
        MinRetryBackoff: 20 * time.Millisecond,
        // Maximum retry backoff
        MaxRetryBackoff: 200 * time.Millisecond,
        // Connection timeout
        DialTimeout: 3 * time.Second,
        // Read timeout
        ReadTimeout: 5 * time.Second,
        // Write timeout
        WriteTimeout: 10 * time.Second,
        // Connection pool size for each node
        PoolSize: 100,
        // Maximum wait time for available connections in the pool
        PoolTimeout: time.Second,
        // Minimum number of idle connections for each node
        MinIdleConns: 5,
        // Maximum number of idle connections for each node
        MaxIdleConns: 10,
        // Maximum number of active connections for each node
        MaxActiveConns: 100,
        // Maximum idle time for connections
        ConnMaxIdleTime: time.Minute * 5,
    })
    defer client.Close()

    if val, err := client.Get(context.TODO(), "test").Result(); err != nil {
        panic(err)
    } else {
        fmt.Println(val)
    }
}

For more detailed configuration, please refer to Community Documentation