Skip to content
GitHub

ShardedCooldownStore

class in meocord/common Since 4.1.0

class ShardedCooldownStore extends CooldownStore

A CooldownStore for process sharding that needs no database.

Use it so 'user' and 'global' cooldowns are exact across the shards on one host: each shard asks the shard manager, which counts every shard's calls in its memory. For counts that outlive a restart, or bots on several hosts, use RedisCooldownStore.

Examples

TypeScript
@MeoCord({
  controllers: [],
  clientOptions: { intents: [GatewayIntentBits.Guilds] },
  cooldownStore: ShardedCooldownStore,
})
export default class App {}

Members

constructor

new ShardedCooldownStore()

consume

consume(key: string, limit: CooldownLimit): Promise<CooldownVerdict>

Records a call for key if the limit allows it: in the manager with process sharding, here otherwise.

Parameters

NameTypeDescription
keystring

Identifies the handler, the cooldown and the caller, user or place it counts per.

limitCooldownLimit

The calls allowed, and the window they are counted over.

Returns

Promise<CooldownVerdict>

Whether this call was recorded, and if not, how long until one can be.

consumeMany

consumeMany(entries: readonly CooldownEntry[]): Promise<CooldownBatchVerdict>

Records a call against every entry if all allow it, in one message to the manager.

Parameters

NameTypeDescription
entriesreadonly CooldownEntry[]

The keys and limits the call counts against.

Returns

Promise<CooldownBatchVerdict>

Whether the call was recorded, and if not, how long until it can be and which entry refused it.

Throws

  • When the manager cannot be reached, its store fails, or it does not answer at all.

peekMany

peekMany(entries: readonly CooldownEntry[]): Promise<CooldownBatchVerdict>

Checks every entry as consumeMany would, recording nothing, in one message to the manager.

Parameters

NameTypeDescription
entriesreadonly CooldownEntry[]

The keys and limits to check.

Returns

Promise<CooldownBatchVerdict>

Whether every entry allows a call now, and if not, how long until it would and which refused.

Throws

  • When the manager cannot be reached, its store fails, or it does not answer at all.