Skip to content

Add GCRA Rate Limiting Command Support for Redis OSS 8.8 #3695

@a-TODO-rov

Description

@a-TODO-rov

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
GCRAArgs args = GCRAArgs.Builder.rate(5, 10, 60);

GCRAResponse response = redis.gcra("api:user:123", args);

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions