Skip to content

RedisCounterStore

The CounterStore on Redis: one INCR per hit, the TTL armed atomically by the first.

  • CounterStore

new RedisCounterStore(redis, options?): RedisCounterStore

Redis

RedisStoreOptions = {}

RedisCounterStore

decrement(key): Promise<void>

Takes one back: atomically lowers the counter by 1, never below 0, keeping its TTL. A missing key stays missing. Used to refund a reserved attempt.

string

Promise<void>

CounterStore.decrement


get(key): Promise<CounterWindow | null>

string

Promise<CounterWindow | null>

CounterStore.get


increment(key, windowMs): Promise<CounterWindow>

Increments the counter. The first hit arms a TTL of windowMs; later hits never extend it. Every key has a TTL, always. Of N concurrent callers each sees a distinct count.

string

number

Promise<CounterWindow>

CounterStore.increment


reset(key): Promise<void>

string

Promise<void>

CounterStore.reset


set(key, count, windowMs): Promise<void>

Overwrites the counter with count and a fresh TTL of windowMs.

string

number

number

Promise<void>

CounterStore.set