Skip to content

DEV: (cmds) add GCRA command page and general info.#2943

Open
dwdougherty wants to merge 2 commits intoDOC-6334from
DOC-6405
Open

DEV: (cmds) add GCRA command page and general info.#2943
dwdougherty wants to merge 2 commits intoDOC-6334from
DOC-6405

Conversation

@dwdougherty
Copy link
Copy Markdown
Collaborator

@dwdougherty dwdougherty commented Mar 26, 2026

Redis 8.8 feature

@LiorKogan: I'm anticipating lots of "red ink" on this one! 🫠


Note

Low Risk
Low risk since this PR only adds documentation and an SVG diagram, with no runtime or API behavior changes. Primary risk is doc correctness/consistency (e.g., argument names/return description) affecting user understanding.

Overview
Adds new documentation for the Redis 8.8 GCRA rate-limiting command, including full command reference metadata (arguments, ACL/categories, reply schema), usage explanation, and examples.

Introduces a new Rate limiting guide under develop/using-commands that explains GCRA concepts, common patterns, and client-side handling, and adds the gcra railroad diagram SVG for syntax visualization.

Written by Cursor Bugbot for commit 8afb220. This will update automatically on new commits. Configure here.

@dwdougherty dwdougherty requested review from a team and LiorKogan March 26, 2026 18:06
@dwdougherty dwdougherty self-assigned this Mar 26, 2026
@dwdougherty dwdougherty added dev cmds oss Redis Open Source labels Mar 26, 2026
@github-actions
Copy link
Copy Markdown
Contributor

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 26, 2026

DOC-6405

@jit-ci
Copy link
Copy Markdown

jit-ci bot commented Mar 26, 2026

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

Copy link
Copy Markdown
Collaborator

@mich-elle-luna mich-elle-luna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one change from me, thank you!

Co-authored-by: mich-elle-luna <153109578+mich-elle-luna@users.noreply.github.com>
@dwdougherty
Copy link
Copy Markdown
Collaborator Author

Thank you for the review and comment, @mich-elle-luna!


Performs rate limiting using the [Generic Cell Rate Algorithm (GCRA)](https://en.wikipedia.org/wiki/Generic_cell_rate_algorithm).

GCRA is a popular rate limiting algorithm known for its simplicity and speed. It allows a sustained rate of `requests_per_period` requests per `period` seconds, with a minimum spacing (emission interval) of `period / requests_per_period` seconds between each request. The `max_burst` parameter allows for occasional spikes by granting up to `max_burst` additional requests to be consumed at once beyond the sustained rate.
Copy link
Copy Markdown
Member

@LiorKogan LiorKogan Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While everything is correct, I suggest using the 'tokens' terminology.

Each request is associated with a given number of tokens (default = 1).

requests_per_period should be renamed to tokens_per_period
(max_burst is already in tokens)


## Optional arguments

<details open><summary><code>NUM_REQUESTS count</code></summary>
Copy link
Copy Markdown
Member

@LiorKogan LiorKogan Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest renaming NUM_REQUESTS to NUM_TOKENS or simply TOKENS.


<details open><summary><code>NUM_REQUESTS count</code></summary>

is the cost (or weight) of this rate-limiting request. A higher cost drains the allowance faster. This is useful when different operations have different costs. Default value: `1`.
Copy link
Copy Markdown
Member

@LiorKogan LiorKogan Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to use cost and weight, just Number of tokens. For a single request, we can use requested
tokens.

weight: 40
---

Rate limiting controls how often a user or client can perform an action within
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some use cases you can add:

  • Preventing DDoS attacks
  • Preventing brute force attacks
  • Preventing API abuse
  • Preventing web scraping
  • Limiting resource consumption based on subscription type

Some examples you can add:

  • Credit card processing: limit the number of each user’s attempted transactions per minute
  • Dating site: per user - limit profiles view per hour
  • Download site: limit the number of files each free-tier user can download per day


## Examples

Rate limit an API endpoint to 10 requests per 60 seconds with a burst of 5:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 tokens per 60 seconds with a burst of 5 tokens:

Performs rate limiting using the [Generic Cell Rate Algorithm (GCRA)](https://en.wikipedia.org/wiki/Generic_cell_rate_algorithm).

GCRA is a popular rate limiting algorithm known for its simplicity and speed. It allows a sustained rate of `requests_per_period` requests per `period` seconds, with a minimum spacing (emission interval) of `period / requests_per_period` seconds between each request. The `max_burst` parameter allows for occasional spikes by granting up to `max_burst` additional requests to be consumed at once beyond the sustained rate.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One important note about this command:

It is used to either establish a new rate limiter (if the key doesn't exist) or use an existing one (if the key exists). That's why all the parameters need to be repeated on each call (clients don't need to validate that the key exists before using an existing rate limiter).

Under normal usage, max-burst, tokens-per-period, and period should not change between calls, though this command supports such changes as well.


## Comparison with other approaches

Before the `GCRA` command, common approaches for rate limiting in Redis
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest removing this because in future versions we plan https://redislabs.atlassian.net/browse/RED-191300

- **External modules** like redis-cell: effective but require installing and
maintaining a separate module.

The built-in `GCRA` command provides the same functionality with better
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not the same functionality. The rate-limiting algorithm is different.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants