What is GCRA?
GCRA (Generic Cell Rate Algorithm) is a rate limiting mechanism built into Redis (available since Redis 8.8). It implements a leaky-bucket-style algorithm that allows applications to enforce request rate limits with burst tolerance — all in a single atomic command, without Lua scripts or external libraries.
Why?
Rate limiting is one of the most common Redis use cases. Until now, users had to implement it themselves using combinations of INCR, EXPIRE, and Lua scripts. The GCRA command provides a first-class, production-ready solution with:
- Atomic rate decisions — no race conditions
- Burst support — allows short traffic spikes within configurable limits
- Weighted requests — a single request can consume multiple tokens (e.g., expensive API calls)
- Actionable response — tells the caller exactly when to retry and when the bucket fully refills
Usage Example
// Allow 10 requests per 60 seconds, with a burst tolerance of 5 extra requests
GCRAParams params = GCRAParams.gcraParams(5, 10, 60);
GCRAResponse response = jedis.gcra("api:user:123", params);
if (response.isLimited()) {
// Reject — tell caller to retry after this many seconds
long retryAfterSec = response.getRetryAfter();
} else {
// Allow — this many requests still available in the current window
long remaining = response.getAvailableRequests();
}
Scope
- Full API coverage: sync, async, reactive, and Kotlin coroutines
- Tested across standalone, cluster, RESP2, RESP3, reactive, and transactional modes
What is GCRA?
GCRA (Generic Cell Rate Algorithm) is a rate limiting mechanism built into Redis (available since Redis 8.8). It implements a leaky-bucket-style algorithm that allows applications to enforce request rate limits with burst tolerance — all in a single atomic command, without Lua scripts or external libraries.
Why?
Rate limiting is one of the most common Redis use cases. Until now, users had to implement it themselves using combinations of
INCR,EXPIRE, and Lua scripts. TheGCRAcommand provides a first-class, production-ready solution with:Usage Example
Scope