Documentation
¶
Overview ¶
Package redis provides intelligent auto-detection capabilities for Redis connections. This file implements auto-detection for GCP environment and Redis cluster topology.
Package redis provides Redis connection management and operations utilities. This file contains cluster-specific implementations for Redis cluster mode support.
Package redis provides Redis connection management and operations utilities. It includes connection pooling, health checks, and helper functions for interacting with Redis databases in a safe and efficient manner.
The SmartRedisConnection automatically detects cluster mode and GCP IAM authentication based on address format and environment variables, while maintaining 100% backward compatibility with existing RedisConnection usage patterns.
Example (BackwardCompatibility) ¶
Example_backwardCompatibility demonstrates that existing code patterns continue to work unchanged
// This exact pattern works as before - no code changes needed
rc := &RedisConnection{
Addr: "localhost:6379",
Password: "password",
DB: 0,
}
ctx := context.Background()
// Connect using the same API as before
err := rc.Connect(ctx)
if err != nil {
fmt.Printf("Connection failed (expected without Redis): %v\n", err)
// In real usage, this would succeed with a running Redis instance
}
// GetClient still returns *redis.Client as expected
client, err := rc.GetClient(ctx)
if err != nil {
fmt.Printf("GetClient failed (expected without Redis): %v\n", err)
// In real usage, this would return a working client
}
_ = client // Would be used for Redis operations
// All existing methods work unchanged
pingCmd := rc.Ping(ctx)
fmt.Printf("Ping command created: %T\n", pingCmd)
setCmd := rc.Set(ctx, "key", "value", time.Minute)
fmt.Printf("Set command created: %T\n", setCmd)
getCmd := rc.Get(ctx, "key")
fmt.Printf("Get command created: %T\n", getCmd)
delCmd := rc.Del(ctx, "key")
fmt.Printf("Del command created: %T\n", delCmd)
// Close works as before
err = rc.Close()
fmt.Printf("Close successful: %v\n", err == nil)
Output: Connection failed (expected without Redis): failed to ping Redis: dial tcp [::1]:6379: connect: connection refused GetClient failed (expected without Redis): failed to ping Redis: dial tcp [::1]:6379: connect: connection refused Ping command created: *redis.StatusCmd Set command created: *redis.StatusCmd Get command created: *redis.StringCmd Del command created: *redis.IntCmd Close successful: true
Example (DetectionCaching) ¶
Example_detectionCaching demonstrates performance optimization
rc := &RedisConnection{
Addr: "localhost:6379",
Logger: &nopLogger{},
}
ctx := context.Background()
// First connection performs detection
start := time.Now()
err1 := rc.Connect(ctx)
firstConnectTime := time.Since(start)
if err1 != nil {
fmt.Printf("First connection failed (expected): %v\n", err1 != nil)
}
// Close and reconnect - uses cached detection (faster)
_ = rc.Close()
start = time.Now()
err2 := rc.Connect(ctx)
secondConnectTime := time.Since(start)
if err2 != nil {
fmt.Printf("Second connection failed (expected): %v\n", err2 != nil)
}
fmt.Printf("First connect took: %v\n", firstConnectTime > 0)
fmt.Printf("Second connect took: %v\n", secondConnectTime >= 0)
fmt.Printf("Cache working: %v\n", true) // Detection cache reduces overhead
// Force refresh detection cache
err := rc.RefreshDetection(ctx)
fmt.Printf("Detection refresh completed: %v\n", err != nil)
Output: First connection failed (expected): true Second connection failed (expected): true First connect took: true Second connect took: true Cache working: true Detection refresh completed: true
Example (MultipleFeatures) ¶
Example_multipleFeatures demonstrates smart detection with multiple features
// Both cluster addresses AND GCP environment
_ = os.Setenv("GOOGLE_CLOUD_PROJECT", "my-project")
defer func() { _ = os.Unsetenv("GOOGLE_CLOUD_PROJECT") }()
rc := &RedisConnection{
Addr: "cluster-node1:7000,cluster-node2:7001",
Logger: &nopLogger{},
}
ctx := context.Background()
// Automatically detects both cluster topology and GCP environment
err := rc.Connect(ctx)
if err != nil {
fmt.Printf("Multi-feature connection failed (expected): %v\n", err)
}
// Inspection shows what was detected
detection := rc.GetDetectedConfig()
if detection != nil {
fmt.Printf("GCP detected: %v\n", detection.IsGCP)
fmt.Printf("Cluster detected: %v\n", detection.IsCluster)
fmt.Printf("Detection summary: %s\n", detection.DetectionSummary())
}
// API remains unchanged
client, err := rc.GetClient(ctx)
if err != nil {
fmt.Printf("GetClient failed (expected): %v\n", err)
}
_ = client
Output: Multi-feature connection failed (expected): failed to ping Redis: dial tcp: lookup cluster-node1: no such host GCP detected: true Cluster detected: false Detection summary: GCP(project=my-project), Single, Error=cluster detection failed: failed to connect to any of the provided addresses GetClient failed (expected): failed to ping Redis: dial tcp: lookup cluster-node1: no such host
Example (SmartClusterDetection) ¶
Example_smartClusterDetection demonstrates automatic cluster detection
// Multiple addresses automatically trigger cluster detection
rc := &RedisConnection{
Addr: "node1:7000,node2:7001,node3:7002",
Password: "cluster-password",
Logger: &nopLogger{},
}
ctx := context.Background()
// Connect automatically detects cluster mode
err := rc.Connect(ctx)
if err != nil {
fmt.Printf("Cluster connection failed (expected without Redis): %v\n", err)
}
// Check detection results
fmt.Printf("Is cluster connection: %v\n", rc.IsClusterConnection())
fmt.Printf("Connection type: %s\n", rc.getConnectionType())
// GetClient still returns *redis.Client for backward compatibility
// (creates a proxy client when in cluster mode)
client, err := rc.GetClient(ctx)
if err != nil {
fmt.Printf("GetClient failed (expected): %v\n", err)
}
_ = client
// Inspection methods provide insight into detection
detection := rc.GetDetectedConfig()
if detection != nil {
fmt.Printf("Detection completed at: %v\n", detection.DetectedAt.IsZero() == false)
}
Output: Cluster connection failed (expected without Redis): failed to ping Redis: dial tcp: lookup node1: no such host Is cluster connection: false Connection type: single GetClient failed (expected): failed to ping Redis: dial tcp: lookup node1: no such host Detection completed at: true
Index ¶
- Constants
- Variables
- type AuthError
- type AuthenticatedRedisConnection
- func (arc *AuthenticatedRedisConnection) Close() error
- func (arc *AuthenticatedRedisConnection) Connect(ctx context.Context) error
- func (arc *AuthenticatedRedisConnection) Del(ctx context.Context, keys ...string) *redis.IntCmd
- func (arc *AuthenticatedRedisConnection) Get(ctx context.Context, key string) *redis.StringCmd
- func (arc *AuthenticatedRedisConnection) GetAuthenticatedClient(ctx context.Context) (RedisClient, error)
- func (arc *AuthenticatedRedisConnection) Ping(ctx context.Context) *redis.StatusCmd
- func (arc *AuthenticatedRedisConnection) Set(ctx context.Context, key string, value any, expiration time.Duration) *redis.StatusCmd
- type AutoDetector
- type ClusterConfig
- type ConnectionType
- type DetectionCache
- type DetectionResult
- type EnvironmentDetector
- type GCPAuthConfig
- type GCPClusterConfig
- type GCPEnvironmentDetector
- type GCPTokenProvider
- func (gcp *GCPTokenProvider) GetToken(ctx context.Context) (string, error)
- func (gcp *GCPTokenProvider) GetTokenTTL() time.Duration
- func (gcp *GCPTokenProvider) IsTokenExpired() bool
- func (gcp *GCPTokenProvider) RefreshToken(_ context.Context) (string, error)
- func (gcp *GCPTokenProvider) StartAutoRefresh(ctx context.Context) error
- func (gcp *GCPTokenProvider) StopAutoRefresh() error
- type RedisClient
- type RedisClusterConnection
- func (rcc *RedisClusterConnection) Close() error
- func (rcc *RedisClusterConnection) ConnectCluster(ctx context.Context) error
- func (rcc *RedisClusterConnection) Del(ctx context.Context, keys ...string) *redis.IntCmd
- func (rcc *RedisClusterConnection) Get(ctx context.Context, key string) *redis.StringCmd
- func (rcc *RedisClusterConnection) GetClusterClient(ctx context.Context) (*redis.ClusterClient, error)
- func (rcc *RedisClusterConnection) GetClusterInfo(ctx context.Context) (result map[string]any, err error)
- func (rcc *RedisClusterConnection) HealthCheck(ctx context.Context) (err error)
- func (rcc *RedisClusterConnection) Ping(ctx context.Context) *redis.StatusCmd
- func (rcc *RedisClusterConnection) Set(ctx context.Context, key string, value any, expiration time.Duration) *redis.StatusCmd
- type RedisConnection
- func (rc *RedisConnection) Close() error
- func (rc *RedisConnection) Connect(ctx context.Context) error
- func (rc *RedisConnection) Del(ctx context.Context, keys ...string) *redis.IntCmd
- func (rc *RedisConnection) Get(ctx context.Context, key string) *redis.StringCmd
- func (rc *RedisConnection) GetActualClient() any
- func (rc *RedisConnection) GetClient(ctx context.Context) (*redis.Client, error)
- func (rc *RedisConnection) GetDetectedConfig() *DetectionResult
- func (rc *RedisConnection) IsClusterConnection() bool
- func (rc *RedisConnection) IsGCPAuthenticated() bool
- func (rc *RedisConnection) Ping(ctx context.Context) *redis.StatusCmd
- func (rc *RedisConnection) RefreshDetection(ctx context.Context) error
- func (rc *RedisConnection) Set(ctx context.Context, key string, value any, expiration time.Duration) *redis.StatusCmd
- type RedisConnectionBuilder
- type RedisConnectionFactory
- type RedisTopologyDetector
- type TokenProvider
- type TopologyDetector
Examples ¶
Constants ¶
const ( DefaultDetectionCacheTTL = 10 * time.Minute DefaultDetectionTimeout = 5 * time.Second DefaultMetadataTimeout = 2 * time.Second DefaultConnectionTimeout = 3 * time.Second DefaultPingTimeout = 1 * time.Second // GCP metadata server endpoint GCPMetadataServerURL = "http://metadata.google.internal/computeMetadata/v1/" GCPProjectEndpoint = GCPMetadataServerURL + "project/project-id" GCPMetadataHeader = "Metadata-Flavor" GCPMetadataValue = "Google" )
Detection configuration constants
const ( EnvGCPValkeyAuth = "GCP_VALKEY_AUTH" EnvGCPServiceAccount = "GCP_SERVICE_ACCOUNT_PATH" EnvGCPProjectID = "GCP_PROJECT_ID" // #nosec G101 -- This is an environment variable name, not hardcoded credentials EnvGCPTokenRefreshBuffer = "GCP_TOKEN_REFRESH_BUFFER" )
Environment variable constants for GCP authentication
const ( DefaultTokenRefreshBuffer = 5 * time.Minute // DefaultTokenScope is Google's public OAuth scope URL, not a secret credential // #nosec G101 -- This is Google's public OAuth scope URL, not hardcoded credentials DefaultTokenScope = "https://www.googleapis.com/auth/cloud-platform" )
Default configuration values
const RedisTTL = 300
RedisTTL defines the default time-to-live (TTL) for Redis cache entries in seconds.
Variables ¶
var ( ErrGCPAuthDisabled = fmt.Errorf("GCP authentication is disabled") ErrInvalidCredentials = fmt.Errorf("invalid GCP credentials") ErrTokenExpired = fmt.Errorf("GCP access token expired") ErrTokenRefreshFailed = fmt.Errorf("failed to refresh GCP token") ErrServiceAccountMissing = fmt.Errorf("GCP service account path not configured") ErrProjectIDMissing = fmt.Errorf("GCP project ID not configured") ErrInvalidServiceAccount = fmt.Errorf("invalid GCP service account file") )
GCP-specific errors
Functions ¶
This section is empty.
Types ¶
type AuthenticatedRedisConnection ¶ added in v1.12.1
type AuthenticatedRedisConnection struct {
BaseConnection RedisClient
TokenProvider TokenProvider
AuthConfig GCPAuthConfig
Connected bool
Logger log.Logger
}
AuthenticatedRedisConnection wraps Redis connections with authentication
func (*AuthenticatedRedisConnection) Close ¶ added in v1.12.1
func (arc *AuthenticatedRedisConnection) Close() error
Close implements RedisClient interface for AuthenticatedRedisConnection
func (*AuthenticatedRedisConnection) Connect ¶ added in v1.12.1
func (arc *AuthenticatedRedisConnection) Connect(ctx context.Context) error
Connect establishes an authenticated connection
func (*AuthenticatedRedisConnection) Del ¶ added in v1.12.1
func (arc *AuthenticatedRedisConnection) Del(ctx context.Context, keys ...string) *redis.IntCmd
Del implements RedisClient interface
func (*AuthenticatedRedisConnection) Get ¶ added in v1.12.1
func (arc *AuthenticatedRedisConnection) Get(ctx context.Context, key string) *redis.StringCmd
Get implements RedisClient interface
func (*AuthenticatedRedisConnection) GetAuthenticatedClient ¶ added in v1.12.1
func (arc *AuthenticatedRedisConnection) GetAuthenticatedClient(ctx context.Context) (RedisClient, error)
GetAuthenticatedClient returns the authenticated Redis client
func (*AuthenticatedRedisConnection) Ping ¶ added in v1.12.1
func (arc *AuthenticatedRedisConnection) Ping(ctx context.Context) *redis.StatusCmd
Ping implements RedisClient interface for AuthenticatedRedisConnection
type AutoDetector ¶ added in v1.12.1
type AutoDetector struct {
// contains filtered or unexported fields
}
AutoDetector provides intelligent auto-detection capabilities
func NewAutoDetector ¶ added in v1.12.1
func NewAutoDetector(logger log.Logger) *AutoDetector
NewAutoDetector creates a new auto-detector with default settings
func (*AutoDetector) ClearCache ¶ added in v1.12.1
func (ad *AutoDetector) ClearCache()
ClearCache clears the detection cache
func (*AutoDetector) Detect ¶ added in v1.12.1
func (ad *AutoDetector) Detect(ctx context.Context, addr string) (*DetectionResult, error)
Detect performs comprehensive auto-detection
func (*AutoDetector) SetCacheTTL ¶ added in v1.12.1
func (ad *AutoDetector) SetCacheTTL(ttl time.Duration)
SetCacheTTL sets the cache time-to-live
type ClusterConfig ¶ added in v1.12.1
type ClusterConfig struct {
Addrs []string `json:"addrs"`
Password string `json:"password,omitempty"`
Username string `json:"username,omitempty"`
MaxRetries int `json:"max_retries,omitempty"`
PoolSize int `json:"pool_size,omitempty"`
MinIdleConns int `json:"min_idle_conns,omitempty"`
MaxConnAge time.Duration `json:"max_conn_age,omitempty"`
PoolTimeout time.Duration `json:"pool_timeout,omitempty"`
IdleTimeout time.Duration `json:"idle_timeout,omitempty"`
ReadTimeout time.Duration `json:"read_timeout,omitempty"`
WriteTimeout time.Duration `json:"write_timeout,omitempty"`
RouteByLatency bool `json:"route_by_latency,omitempty"`
RouteRandomly bool `json:"route_randomly,omitempty"`
}
ClusterConfig represents Redis cluster configuration
func (*ClusterConfig) ToRedisOptions ¶ added in v1.12.1
func (cc *ClusterConfig) ToRedisOptions() *redis.ClusterOptions
ToRedisOptions converts ClusterConfig to redis.ClusterOptions
func (*ClusterConfig) Validate ¶ added in v1.12.1
func (cc *ClusterConfig) Validate() error
Validate validates the cluster configuration
type ConnectionType ¶ added in v1.12.1
type ConnectionType int
ConnectionType represents the type of Redis connection
const ( // SingleInstance represents a single Redis instance connection SingleInstance ConnectionType = iota // Cluster represents a Redis cluster connection Cluster // Sentinel represents a Redis Sentinel connection Sentinel )
func (ConnectionType) String ¶ added in v1.12.1
func (ct ConnectionType) String() string
String returns the string representation of ConnectionType
type DetectionCache ¶ added in v1.12.1
type DetectionCache struct {
// contains filtered or unexported fields
}
DetectionCache stores detection results to avoid repeated checks
type DetectionResult ¶ added in v1.12.1
type DetectionResult struct {
IsGCP bool
IsCluster bool
DetectedAt time.Time
GCPProjectID string
ClusterNodes []string
DetectionError error
}
DetectionResult represents the result of environment and topology detection
func (*DetectionResult) DetectionSummary ¶ added in v1.12.1
func (dr *DetectionResult) DetectionSummary() string
DetectionSummary provides a string summary of detection results
func (*DetectionResult) ToJSON ¶ added in v1.12.1
func (dr *DetectionResult) ToJSON() (string, error)
ToJSON converts detection result to JSON for logging/debugging
type EnvironmentDetector ¶ added in v1.12.1
type EnvironmentDetector interface {
IsGCP(ctx context.Context) (bool, string, error)
GetGCPProjectID(ctx context.Context) (string, error)
}
EnvironmentDetector interface for detecting the runtime environment
type GCPAuthConfig ¶ added in v1.12.1
type GCPAuthConfig struct {
Enabled bool `json:"enabled"`
ServiceAccountPath string `json:"service_account_path"`
ProjectID string `json:"project_id"`
TokenRefreshBuffer time.Duration `json:"token_refresh_buffer,omitempty"`
TokenScope []string `json:"token_scope,omitempty"`
}
GCPAuthConfig represents GCP-specific authentication configuration
func ConfigFromEnv ¶ added in v1.12.1
func ConfigFromEnv() (*GCPAuthConfig, error)
ConfigFromEnv loads GCP configuration from environment variables
func (*GCPAuthConfig) ValidateConfig ¶ added in v1.12.1
func (config *GCPAuthConfig) ValidateConfig() error
ValidateConfig ensures GCP configuration is complete and valid
type GCPClusterConfig ¶ added in v1.12.1
GCPClusterConfig represents cluster connection configuration for GCP auth
type GCPEnvironmentDetector ¶ added in v1.12.1
type GCPEnvironmentDetector struct {
// contains filtered or unexported fields
}
GCPEnvironmentDetector implements GCP environment detection
func NewGCPEnvironmentDetector ¶ added in v1.12.1
func NewGCPEnvironmentDetector() *GCPEnvironmentDetector
NewGCPEnvironmentDetector creates a new GCP environment detector
func (*GCPEnvironmentDetector) GetGCPProjectID ¶ added in v1.12.1
func (gcd *GCPEnvironmentDetector) GetGCPProjectID(ctx context.Context) (string, error)
GetGCPProjectID retrieves the GCP project ID
type GCPTokenProvider ¶ added in v1.12.1
type GCPTokenProvider struct {
ServiceAccountPath string
ProjectID string
TokenScope []string
Logger log.Logger
// contains filtered or unexported fields
}
GCPTokenProvider implements TokenProvider for GCP IAM
func NewGCPTokenProvider ¶ added in v1.12.1
func NewGCPTokenProvider(config *GCPAuthConfig, logger log.Logger) (*GCPTokenProvider, error)
NewGCPTokenProvider creates a new GCP token provider
func (*GCPTokenProvider) GetToken ¶ added in v1.12.1
func (gcp *GCPTokenProvider) GetToken(ctx context.Context) (string, error)
GetToken retrieves the current token, refreshing if necessary
func (*GCPTokenProvider) GetTokenTTL ¶ added in v1.12.1
func (gcp *GCPTokenProvider) GetTokenTTL() time.Duration
GetTokenTTL returns the time until token expiry
func (*GCPTokenProvider) IsTokenExpired ¶ added in v1.12.1
func (gcp *GCPTokenProvider) IsTokenExpired() bool
IsTokenExpired checks if the current token is expired or missing
func (*GCPTokenProvider) RefreshToken ¶ added in v1.12.1
func (gcp *GCPTokenProvider) RefreshToken(_ context.Context) (string, error)
RefreshToken fetches a new token from GCP
func (*GCPTokenProvider) StartAutoRefresh ¶ added in v1.12.1
func (gcp *GCPTokenProvider) StartAutoRefresh(ctx context.Context) error
StartAutoRefresh starts the automatic token refresh mechanism
func (*GCPTokenProvider) StopAutoRefresh ¶ added in v1.12.1
func (gcp *GCPTokenProvider) StopAutoRefresh() error
StopAutoRefresh stops the automatic token refresh mechanism
type RedisClient ¶ added in v1.12.1
type RedisClient interface {
Ping(ctx context.Context) *redis.StatusCmd
Set(ctx context.Context, key string, value any, expiration time.Duration) *redis.StatusCmd
Get(ctx context.Context, key string) *redis.StringCmd
Del(ctx context.Context, keys ...string) *redis.IntCmd
Close() error
}
RedisClient interface abstracts both single and cluster clients
type RedisClusterConnection ¶ added in v1.12.1
type RedisClusterConnection struct {
ClusterConfig ClusterConfig
ClusterClient *redis.ClusterClient
Connected bool
Logger log.Logger
}
RedisClusterConnection manages Redis cluster connections
func (*RedisClusterConnection) Close ¶ added in v1.12.1
func (rcc *RedisClusterConnection) Close() error
Close implements RedisClient interface
func (*RedisClusterConnection) ConnectCluster ¶ added in v1.12.1
func (rcc *RedisClusterConnection) ConnectCluster(ctx context.Context) error
ConnectCluster establishes cluster connection
func (*RedisClusterConnection) Del ¶ added in v1.12.1
func (rcc *RedisClusterConnection) Del(ctx context.Context, keys ...string) *redis.IntCmd
Del implements RedisClient interface
func (*RedisClusterConnection) Get ¶ added in v1.12.1
func (rcc *RedisClusterConnection) Get(ctx context.Context, key string) *redis.StringCmd
Get implements RedisClient interface
func (*RedisClusterConnection) GetClusterClient ¶ added in v1.12.1
func (rcc *RedisClusterConnection) GetClusterClient(ctx context.Context) (*redis.ClusterClient, error)
GetClusterClient returns cluster client with health check
func (*RedisClusterConnection) GetClusterInfo ¶ added in v1.12.1
func (rcc *RedisClusterConnection) GetClusterInfo(ctx context.Context) (result map[string]any, err error)
GetClusterInfo returns cluster topology information
func (*RedisClusterConnection) HealthCheck ¶ added in v1.12.1
func (rcc *RedisClusterConnection) HealthCheck(ctx context.Context) (err error)
HealthCheck performs cluster-wide health check
func (*RedisClusterConnection) Ping ¶ added in v1.12.1
func (rcc *RedisClusterConnection) Ping(ctx context.Context) *redis.StatusCmd
Ping implements RedisClient interface
type RedisConnection ¶
type RedisConnection struct {
Addr string
User string
Password string
DB int
Protocol int
Client *redis.Client // Keep original type for 100% backward compatibility
Connected bool
Logger log.Logger
// contains filtered or unexported fields
}
RedisConnection is a hub which deal with redis connections. The type name intentionally matches the package name for clarity in external usage. Now includes intelligent auto-detection for GCP IAM authentication and cluster topology.
func (*RedisConnection) Close ¶ added in v1.12.1
func (rc *RedisConnection) Close() error
Close implements RedisClient interface
func (*RedisConnection) Connect ¶
func (rc *RedisConnection) Connect(ctx context.Context) error
Connect keeps a singleton connection with redis using intelligent auto-detection. Automatically detects GCP environment and cluster topology for optimal connection.
func (*RedisConnection) Del ¶ added in v1.12.1
func (rc *RedisConnection) Del(ctx context.Context, keys ...string) *redis.IntCmd
Del implements RedisClient interface
func (*RedisConnection) Get ¶ added in v1.12.1
func (rc *RedisConnection) Get(ctx context.Context, key string) *redis.StringCmd
Get implements RedisClient interface
func (*RedisConnection) GetActualClient ¶ added in v1.12.1
func (rc *RedisConnection) GetActualClient() any
GetActualClient returns the actual underlying client (cluster or single)
func (*RedisConnection) GetClient ¶
func (rc *RedisConnection) GetClient(ctx context.Context) (*redis.Client, error)
GetClient returns a pointer to the redis connection, initializing it if necessary. This method maintains backward compatibility while leveraging auto-detection.
func (*RedisConnection) GetDetectedConfig ¶ added in v1.12.1
func (rc *RedisConnection) GetDetectedConfig() *DetectionResult
GetDetectedConfig returns the auto-detection results for inspection
func (*RedisConnection) IsClusterConnection ¶ added in v1.12.1
func (rc *RedisConnection) IsClusterConnection() bool
IsClusterConnection returns true if the connection is using cluster mode
func (*RedisConnection) IsGCPAuthenticated ¶ added in v1.12.1
func (rc *RedisConnection) IsGCPAuthenticated() bool
IsGCPAuthenticated returns true if the connection is using GCP IAM authentication
func (*RedisConnection) Ping ¶ added in v1.12.1
func (rc *RedisConnection) Ping(ctx context.Context) *redis.StatusCmd
Ping implements RedisClient interface
func (*RedisConnection) RefreshDetection ¶ added in v1.12.1
func (rc *RedisConnection) RefreshDetection(ctx context.Context) error
RefreshDetection clears the cache and re-runs auto-detection
type RedisConnectionBuilder ¶ added in v1.12.1
type RedisConnectionBuilder struct {
ConnectionType ConnectionType
SingleConfig *RedisConnection
ClusterConfig *GCPClusterConfig
GCPAuth *GCPAuthConfig
Logger log.Logger
}
RedisConnectionBuilder creates connections with optional GCP auth
func (*RedisConnectionBuilder) Build ¶ added in v1.12.1
func (builder *RedisConnectionBuilder) Build() (RedisClient, error)
Build creates the appropriate Redis connection with authentication
func (*RedisConnectionBuilder) WithCluster ¶ added in v1.12.1
func (builder *RedisConnectionBuilder) WithCluster(config *GCPClusterConfig) *RedisConnectionBuilder
WithCluster enables cluster mode
func (*RedisConnectionBuilder) WithGCPAuth ¶ added in v1.12.1
func (builder *RedisConnectionBuilder) WithGCPAuth(config *GCPAuthConfig) *RedisConnectionBuilder
WithGCPAuth enables GCP IAM authentication
type RedisConnectionFactory ¶ added in v1.12.1
RedisConnectionFactory creates appropriate Redis connections
func (*RedisConnectionFactory) CreateConnection ¶ added in v1.12.1
func (f *RedisConnectionFactory) CreateConnection(connType ConnectionType, config any) (RedisClient, error)
CreateConnection factory method for creating Redis connections
type RedisTopologyDetector ¶ added in v1.12.1
type RedisTopologyDetector struct {
// contains filtered or unexported fields
}
RedisTopologyDetector implements Redis cluster topology detection
func NewRedisTopologyDetector ¶ added in v1.12.1
func NewRedisTopologyDetector() *RedisTopologyDetector
NewRedisTopologyDetector creates a new Redis topology detector
func (*RedisTopologyDetector) DetectNodes ¶ added in v1.12.1
func (rtd *RedisTopologyDetector) DetectNodes(ctx context.Context, addrs []string) ([]string, error)
DetectNodes discovers all nodes in a Redis cluster
type TokenProvider ¶ added in v1.12.1
type TokenProvider interface {
GetToken(ctx context.Context) (string, error)
RefreshToken(ctx context.Context) (string, error)
IsTokenExpired() bool
GetTokenTTL() time.Duration
StartAutoRefresh(ctx context.Context) error
StopAutoRefresh() error
}
TokenProvider interface for GCP access token management