Adapts an already-connected ioredis client into a fixed-window RateLimiter: INCR on
the windowed key, PEXPIRE arms the window on its first hit, and a denial reports the key's
remaining PTTL. The caller creates and owns the client, same as redisCache; the
returned close() releases the connection.
Each key gets limit calls per windowMs; because the counter lives in Redis, the limit holds
across every process sharing the instance. A denial whose key has lost its TTL reports a full
windowMs wait rather than a negative one. Keys live under the economy:ratelimit: prefix,
and a failed call throws a retryable STORE.FAILURE rather than silently allowing.
Adapts an already-connected ioredis client into a fixed-window RateLimiter:
INCRon the windowed key,PEXPIREarms the window on its first hit, and a denial reports the key's remainingPTTL. The caller creates and owns the client, same as redisCache; the returnedclose()releases the connection.Each key gets
limitcalls perwindowMs; because the counter lives in Redis, the limit holds across every process sharing the instance. A denial whose key has lost its TTL reports a fullwindowMswait rather than a negative one. Keys live under theeconomy:ratelimit:prefix, and a failed call throws a retryableSTORE.FAILURErather than silently allowing.