RATELIMIT.CHECK
RATELIMIT.CHECK name key [COST n]
- Group
- Rate limiting
- Complexity
- O(1)
- Arity
- -3 (at least 3 words, counting the command name)
- Flags
- write, fast
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- Performance and Scale
- On-Premise
- requires the rate-limiting license feature
Named rate limiters apply one policy (a limit, a window and an algorithm) separately to every key you check against them, such as a user id, an API key or an IP address. RATELIMIT.CHECK asks whether a request costing COST units
(default 1) fits within the limit for key. If it does, the units are
consumed. A refused request consumes nothing.
Options
Section titled “Options”| Option | Effect |
|---|---|
COST n |
Units this request uses, a positive integer. Default 1. |
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Always | Array of five integers (below) | Same |
| Position | Type | Meaning |
|---|---|---|
| 1 | Integer | 1 if allowed, 0 if not. |
| 2 | Integer | Units still available after this request (0 when not allowed). |
| 3 | Integer | When not allowed, milliseconds until the request would fit; otherwise 0. |
| 4 | Integer | The limiter’s limit. |
| 5 | Integer | Units in use before this request. |
For a limiter that does not exist, every element is 0.
Errors:
ERR invalid COSTifCOSTis not a positive integer.ERR wrong number of arguments for 'ratelimit.check' commandif the argument count is wrong.NOLICENSE rate-limiting requires a HotKV license. Contact sales@hotkv.comif your license does not include therate-limitingfeature.
Examples
Section titled “Examples”127.0.0.1:6379> RATELIMIT.CREATE api 100 60000OK127.0.0.1:6379> RATELIMIT.CHECK api user:11) (integer) 12) (integer) 993) (integer) 04) (integer) 1005) (integer) 0127.0.0.1:6379> RATELIMIT.CHECK api user:1 COST 991) (integer) 12) (integer) 03) (integer) 04) (integer) 1005) (integer) 1127.0.0.1:6379> RATELIMIT.CHECK api user:11) (integer) 02) (integer) 03) (integer) 6004) (integer) 1005) (integer) 100Compatibility
Section titled “Compatibility”HotKV-only command. Redis and Valkey have no equivalent.
See also
Section titled “See also”RATELIMIT.CREATE, RATELIMIT.PEEK, RATELIMIT.RESET, RATELIMIT.STATS, RATELIMIT.DROP, RATELIMIT.LIST, AI features guide
Was this page helpful?
Thanks for the feedback.