How to Access Sentinel Instance
This guide demonstrates how to establish connections to Redis Sentinel 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 Sentinel 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.
Parameter | Description |
---|
Connection Address | Kubernetes service name and port combinations for Redis Sentinel. |
For 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.
Parameter | Description |
---|
Sentinel Node Access Address | External IP addresses and ports for pods of sentinel in Redis Sentinel, enabling connectivity from outside the Kubernetes network. |
Interactive Debugging
On the instance details page, click the Terminal Console in the upper right corner, and use the redis-cli
command to connect to each Redis node.
redis-cli -h <internal-routing-ip> -p 6379
A debugging example is shown below.
Example debugging session demonstrating set/get:
192.168.0.10:6379> set a 1
OK
192.168.0.10:6379> get a
"1"
192.168.0.10:6379>
Client Integration Examples
The following examples demonstrate best practices for connecting to Redis Sentinel instances with various client libraries.
Note: The master-slave cluster name registered in Sentinel mode is fixed to mymaster
.
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.NewFailoverClient(&redis.FailoverOptions{
SentinelAddrs: []string{"<address>"},
MasterName: "mymaster",
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 identification and tracking
ClientName: "go-demo",
// Using Context for timeout control
ContextTimeoutEnabled: true,
// Maximum number of retries
MaxRetries: 3,
// Minimum backoff time for retries
MinRetryBackoff: 20 * time.Millisecond,
// Maximum backoff time for retries
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 idle connections for each node
MinIdleConns: 5,
// Maximum idle connections for each node
MaxIdleConns: 10,
// Maximum 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 the community documentation.