Skip to content

Drivers & Interfaces API Reference

Package distlimit defines storage contracts and driver constructors.


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
}

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) *Driver

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) *Driver

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) *Driver
  • WithCoolOffDuration(duration): Sets duration to remain in fallback mode after Redis failure (Default: 5s).
  • WithOnError(fn): Registers an error callback when Redis failover triggers.