Skip to main content
Version: 1.x

FallbackRateLimitStorage

FallbackRateLimitStorage

Storage wrapper that falls back to a secondary implementation on failure.

Signature
class FallbackRateLimitStorage implements RateLimitStorage {
constructor(primary: RateLimitStorage, secondary: RateLimitStorage, options: FallbackRateLimitStorageOptions = {})
get(key: string) => Promise<T | null>;
set(key: string, value: T, ttlMs?: number) => Promise<void>;
delete(key: string) => Promise<void>;
incr(key: string, ttlMs: number) => ;
ttl(key: string) => ;
expire(key: string, ttlMs: number) => ;
zAdd(key: string, score: number, member: string) => ;
zRemRangeByScore(key: string, min: number, max: number) => ;
zCard(key: string) => ;
zRangeByScore(key: string, min: number, max: number) => ;
consumeFixedWindow(key: string, limit: number, windowMs: number, nowMs: number) => ;
consumeSlidingWindowLog(key: string, limit: number, windowMs: number, nowMs: number, member: string) => ;
deleteByPrefix(prefix: string) => ;
deleteByPattern(pattern: string) => ;
keysByPrefix(prefix: string) => ;
}

constructor

method
(primary: RateLimitStorage, secondary: RateLimitStorage, options: FallbackRateLimitStorageOptions = {}) => FallbackRateLimitStorage

Create a fallback wrapper with primary/secondary storages.

get

method
(key: string) => Promise<T | null>

Read a value using primary storage with fallback.

set

method
(key: string, value: T, ttlMs?: number) => Promise<void>

Store a value using primary storage with fallback.

delete

method
(key: string) => Promise<void>

Delete a key using primary storage with fallback.

incr

method
(key: string, ttlMs: number) =>

Increment a fixed-window counter using primary storage with fallback.

ttl

method
(key: string) =>

Read TTL using primary storage with fallback.

expire

method
(key: string, ttlMs: number) =>

Update TTL using primary storage with fallback.

zAdd

method
(key: string, score: number, member: string) =>

Add a member to a sorted set using primary storage with fallback.

zRemRangeByScore

method
(key: string, min: number, max: number) =>

Remove sorted-set members in a score range with fallback.

zCard

method
(key: string) =>

Count sorted-set members with fallback.

zRangeByScore

method
(key: string, min: number, max: number) =>

Read sorted-set members in a score range with fallback.

consumeFixedWindow

method
(key: string, limit: number, windowMs: number, nowMs: number) =>

Atomically consume a fixed-window counter with fallback.

consumeSlidingWindowLog

method
(key: string, limit: number, windowMs: number, nowMs: number, member: string) =>

Atomically consume a sliding-window log with fallback.

deleteByPrefix

method
(prefix: string) =>

Delete keys with a prefix using primary storage with fallback.

deleteByPattern

method
(pattern: string) =>

Delete keys matching a pattern using primary storage with fallback.

keysByPrefix

method
(prefix: string) =>

List keys matching a prefix using primary storage with fallback.