RedisCounterStore
The CounterStore on Redis: one INCR per hit, the TTL armed atomically by the first.
Implements
Section titled “Implements”CounterStore
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new RedisCounterStore(
redis,options?):RedisCounterStore
Parameters
Section titled “Parameters”Redis
options?
Section titled “options?”RedisStoreOptions = {}
Returns
Section titled “Returns”RedisCounterStore
Methods
Section titled “Methods”decrement()
Section titled “decrement()”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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”CounterStore.decrement
get(
key):Promise<CounterWindow|null>
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<CounterWindow | null>
Implementation of
Section titled “Implementation of”CounterStore.get
increment()
Section titled “increment()”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.
Parameters
Section titled “Parameters”string
windowMs
Section titled “windowMs”number
Returns
Section titled “Returns”Promise<CounterWindow>
Implementation of
Section titled “Implementation of”CounterStore.increment
reset()
Section titled “reset()”reset(
key):Promise<void>
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”CounterStore.reset
set(
key,count,windowMs):Promise<void>
Overwrites the counter with count and a fresh TTL of windowMs.
Parameters
Section titled “Parameters”string
number
windowMs
Section titled “windowMs”number
Returns
Section titled “Returns”Promise<void>
Implementation of
Section titled “Implementation of”CounterStore.set