package
0.1.1
Repository: https://github.com/sigmavirus24/circuitry.git
Documentation: pkg.go.dev

# README

Redis Backend for Circuitry

This provides a StorageBackender implementation for circuitry that uses Redis as the backend.

Note: This requires github.com/redis/go-redis/v9

Usage

import (
    "fmt"
    "time"

    "github.com/bsm/redislock"
    "github.com/redis/go-redis/v9"
    "github.com/sigmavirus24/circuitry"
    redisbackend "github.com/sigmavirus24/circuitry/backends/redis"
)

func main() {
    settings, err := circuitry.NewFactorySettings(
        redisbackend.WithRedisBackend(
            &redis.Options{
                // See also https://pkg.go.dev/github.com/redis/go-redis/v9#readme-quickstart
                // and https://pkg.go.dev/github.com/redis/go-redis/v9#Options
                Addr: "localhost:6379",
                Password: "",
                DB: 0,
            },
            &redislock.Options{
                RetryStrategy: redislock.NoRetry(),
            },
            1 * time.Hour,
        ),
        circuitry.WithDefaultNameFunc(),
        circuitry.WithDefaultTripFunc(),
        circuitry.WithDefaultFallbackErrorMatcher(),
    )
    if err != nil {
        fmt.Printf("could not create settings: %v\n", err)
        return
    }
    factory := circuitry.NewCircuitBreakerFactory(settings)
    breaker := factory.BreakerFor("my-name", map[string]any{})
    ctx := context.Background()
    err = breaker.Start(ctx)
    if err != nil {
        fmt.Printf("could not start circuit breaker: %v\n", err)
    }
    defer breaker.End(ctx, nil)
}

# Functions

New builds a new StorageBackender for circuitry.
WithRedisBackend provides a way to configure the StorageBackend for a Circuit Breaker Factory's esttings.

# Structs

Backend implements the StorageBackender interface for Redis using redis/go-redis/v9 and bsm/redislock.

# Interfaces

Client describes the interface expected for this backend to function appropriately.
Locker describes the interface expected for this backend to function appropriately.