composite

package
v0.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	// contains filtered or unexported fields
}

Backend provides automatic failover capability for rate limiting storage

func New

func New(config Config) (*Backend, error)

New creates a new composite backend

func (*Backend) CheckAndSet

func (c *Backend) CheckAndSet(ctx context.Context, key string, expected string, newValue string, expiration time.Duration) (bool, error)

CheckAndSet performs atomic compare-and-set with failover logic

func (*Backend) Close

func (c *Backend) Close() error

Close closes both backends and stops health monitoring

func (*Backend) Delete

func (c *Backend) Delete(ctx context.Context, key string) error

Delete removes key from backend with failover logic

func (*Backend) Get

func (c *Backend) Get(ctx context.Context, key string) (string, error)

Get retrieves value from backend with failover logic

func (*Backend) GetCircuitBreakerFailureCount

func (c *Backend) GetCircuitBreakerFailureCount() int32

GetCircuitBreakerFailureCount returns the internal failure count (for testing/debugging)

func (*Backend) GetCircuitBreakerState

func (c *Backend) GetCircuitBreakerState() breakerState

GetCircuitBreakerState returns current circuit breaker state (for monitoring)

func (*Backend) Set

func (c *Backend) Set(ctx context.Context, key string, value string, expiration time.Duration) error

Set stores value in backend with failover logic

type BreakerConfig

type BreakerConfig struct {
	FailureThreshold int32         // Number of failures before tripping
	RecoveryTimeout  time.Duration // Time to wait before trying primary again
}

BreakerConfig holds configuration for circuit breaker

type CheckerConfig

type CheckerConfig = healthchecker.Config

CheckerConfig is an alias for healthchecker.Config for backward compatibility

type Config

type Config struct {
	Primary        backends.Backend // Primary/preferred backend
	Secondary      backends.Backend // Secondary/fallback backend
	CircuitBreaker BreakerConfig    // Circuit breaker configuration
	HealthChecker  CheckerConfig    // Health check configuration (alias for backward compatibility)
}

Config holds configuration for the composite backend

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a configuration with sensible defaults

func (*Config) SetDefaults

func (c *Config) SetDefaults()

SetDefaults sets reasonable defaults for configuration values

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the composite backend configuration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL