Drivers & Interfaces API Reference
Package distlimit defines storage contracts and driver constructors.
Driver Interface
Section titled “Driver Interface”The Driver interface abstracts key storage and evaluation persistence engines.
type Driver interface { Allow(ctx context.Context, key string, limit int64, window time.Duration, algo algorithm.Algorithm) (Result, error) Reset(ctx context.Context, key string) error Close(ctx context.Context) error Name() string}Memory Driver (driver/memory)
Section titled “Memory Driver (driver/memory)”import "github.com/balramadan/distlimit/driver/memory"Creates a 64-sharded in-memory storage driver with automatic background TTL key purge routines.
func New(cleanupInterval time.Duration) *DriverRedis Driver (driver/redis)
Section titled “Redis Driver (driver/redis)”import "github.com/balramadan/distlimit/driver/redis"Creates a distributed Redis storage driver utilizing atomic Lua scripts and hash tags {}.
func New(client redis.UniversalClient) *DriverHybrid Driver (driver/hybrid)
Section titled “Hybrid Driver (driver/hybrid)”import "github.com/balramadan/distlimit/driver/hybrid"Creates a dual-tier resilient driver layering a Primary Redis Driver over an In-Memory Fallback Driver with Half-Open Circuit Breaker failover.
func New(primary distlimit.Driver, fallback distlimit.Driver, opts ...Option) *DriverOptions
Section titled “Options”WithCoolOffDuration(duration): Sets duration to remain in fallback mode after Redis failure (Default:5s).WithOnError(fn): Registers an error callback when Redis failover triggers.