management

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

pkg/management/bulk.go

pkg/management/key.go

pkg/management/redis.go

pkg/management/redis.go

pkg/management/redis.go

pkg/management/redis.go

Index

Constants

View Source
const (
	StateClosed   = iota // Normal operation
	StateOpen            // Not allowing operations
	StateHalfOpen        // Testing if service is healthy
)

Circuit breaker states

Variables

View Source
var (
	ErrCircuitOpen     = errors.New("circuit breaker is open")
	ErrTooManyRequests = errors.New("too many requests in half-open state")
)

Functions

This section is empty.

Types

type BulkOperation

type BulkOperation struct {
	Command   string
	Key       string
	Value     interface{}
	ExpiresAt time.Duration
	Result    chan error
}

BulkOperation represents a single operation in the bulk queue

type BulkProcessor

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

BulkProcessor handles bulk operations

func NewBulkProcessor

func NewBulkProcessor(service *RedisService) *BulkProcessor

NewBulkProcessor creates a new bulk processor

func (*BulkProcessor) Start

func (bp *BulkProcessor) Start(ctx context.Context)

Start begins processing bulk operations

type CircuitBreaker

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

func NewCircuitBreaker

func NewCircuitBreaker(threshold int64, resetAfter time.Duration, maxHalfOpen int32) *CircuitBreaker

NewCircuitBreaker creates a new circuit breaker

func (*CircuitBreaker) AllowRequest

func (cb *CircuitBreaker) AllowRequest() bool

AllowRequest checks if a request should be allowed

func (*CircuitBreaker) Execute

func (cb *CircuitBreaker) Execute(fn func() error) error

Execute runs the given function with circuit breaker protection

func (*CircuitBreaker) GetState

func (cb *CircuitBreaker) GetState() string

GetState returns the current state of the circuit breaker

func (*CircuitBreaker) RecordResult

func (cb *CircuitBreaker) RecordResult(err error)

RecordResult records the result of a request

type DBRange

type DBRange struct {
	Start int
	End   int
}

type KeyManager

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

func NewKeyManager

func NewKeyManager(cfg *config.Config) (*KeyManager, error)

func (*KeyManager) GetKey

func (km *KeyManager) GetKey(key string) string

func (*KeyManager) GetShardIndex

func (km *KeyManager) GetShardIndex(key string) (int, error)

type RedisService

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

func NewRedisService

func NewRedisService(cfg *config.Config) (*RedisService, error)

func (*RedisService) AddBulkOperation

func (rs *RedisService) AddBulkOperation(ctx context.Context, command string, key string, value interface{}, expires time.Duration) error

Add bulk operation methods

func (*RedisService) Close

func (rs *RedisService) Close() error

func (*RedisService) Delete

func (rs *RedisService) Delete(ctx context.Context, key string) error

Delete method with circuit breaker support

func (*RedisService) DeleteBatch

func (rs *RedisService) DeleteBatch(ctx context.Context, keys []string) error

DeleteBatch removes multiple keys in a single operation

func (*RedisService) Get

func (rs *RedisService) Get(ctx context.Context, key string) (string, error)

Modify Get method similarly

func (*RedisService) GetBatch

func (rs *RedisService) GetBatch(ctx context.Context, keys []string) (map[string]string, error)

GetBatch retrieves multiple values in a single operation

func (*RedisService) GetBatchTTL added in v1.2.0

func (rs *RedisService) GetBatchTTL(ctx context.Context, keys []string) (map[string]time.Duration, error)

func (*RedisService) GetPoolStats

func (rs *RedisService) GetPoolStats() *redis.PoolStats

GetPoolStats returns current pool statistics with additional safety checks

func (*RedisService) GetTTL added in v1.2.0

func (rs *RedisService) GetTTL(ctx context.Context, key string) (time.Duration, error)

func (*RedisService) Ping

func (rs *RedisService) Ping(ctx context.Context) error

Ping checks if Redis is responding

func (*RedisService) Set

func (rs *RedisService) Set(ctx context.Context, key string, value interface{}, expiration time.Duration) error

Modify Set method to use circuit breaker if enabled

func (*RedisService) SetBatch

func (rs *RedisService) SetBatch(ctx context.Context, items map[string]interface{}, expiration time.Duration) error

SetBatch stores multiple key-value pairs in a single operation

func (*RedisService) SetBatchTTL added in v1.2.0

func (rs *RedisService) SetBatchTTL(ctx context.Context, keys []string, ttl time.Duration) error

func (*RedisService) SetBatchWithDefaultTTL added in v1.1.0

func (rs *RedisService) SetBatchWithDefaultTTL(ctx context.Context, items map[string]interface{}) error

SetBatchWithDefaultTTL stores multiple values with configured default TTL

func (*RedisService) SetTTL added in v1.2.0

func (rs *RedisService) SetTTL(ctx context.Context, key string, ttl time.Duration) error

func (*RedisService) SetWithDefaultTTL added in v1.1.0

func (rs *RedisService) SetWithDefaultTTL(ctx context.Context, key string, value interface{}) error

SetWithDefaultTTL stores a value with configured default TTL

Jump to

Keyboard shortcuts

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