perf(limit-count): use evalsha with NOSCRIPT fallback for Redis script execution#13363
Merged
Merged
Conversation
nic-6443
force-pushed
the
feat/limit-count-evalsha
branch
2 times, most recently
from
May 12, 2026 09:37
a0d683d to
542f505
Compare
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Optimizes the limit-count plugin’s Redis Lua execution by switching from EVAL to EVALSHA with a NOSCRIPT fallback, reducing per-request bandwidth and Redis script parsing overhead.
Changes:
- Use
evalshawithNOSCRIPTfallback in the standalone Redis backend. - Use
evalshawithNOSCRIPTfallback in the Redis Cluster backend. - Add a test that flushes Redis script cache and verifies fallback recovery.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
apisix/plugins/limit-count/limit-count-redis.lua |
Introduces script SHA computation and evalsha + NOSCRIPT fallback for standalone Redis. |
apisix/plugins/limit-count/limit-count-redis-cluster.lua |
Introduces script SHA computation and evalsha + NOSCRIPT fallback for Redis Cluster. |
t/plugin/limit-count-redis.t |
Adds coverage for NOSCRIPT fallback after flushing Redis script cache. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
nic-6443
force-pushed
the
feat/limit-count-evalsha
branch
from
May 12, 2026 09:41
542f505 to
0514f7b
Compare
…t execution Replace plain red:eval() with red:evalsha() + NOSCRIPT fallback in limit-count Redis and Redis Cluster backends. This reduces per-request network payload from ~200-500 bytes (full script text) to ~40 bytes (SHA1 digest + arguments) and eliminates Redis-side script parsing after the first call. The script SHA1 is computed client-side at module load time using ngx.sha1_bin(), which works correctly for both standalone Redis and Redis Cluster topologies. On NOSCRIPT (after Redis restart or when hitting a new cluster shard), the fallback to eval() implicitly caches the script for subsequent evalsha calls.
nic-6443
force-pushed
the
feat/limit-count-evalsha
branch
from
May 12, 2026 10:28
0514f7b to
faea574
Compare
AlinsRan
approved these changes
May 13, 2026
shreemaan-abhishek
approved these changes
May 13, 2026
membphis
approved these changes
May 14, 2026
wistefan
pushed a commit
to wistefan/apisix
that referenced
this pull request
Jun 16, 2026
Merged
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The limit-count plugin ships the full Lua script text on every Redis call via
red:eval(). At high RPS this wastes both network bandwidth (~200-500 bytes per call) and Redis CPU (script parsing on every call).This PR replaces
evalwithevalsha+ NOSCRIPT fallback in both the standalone Redis and Redis Cluster backends of the limit-count plugin. The script SHA1 is computed client-side at module load time, avoiding the need forSCRIPT LOAD(which doesn't route correctly in Redis Cluster). On NOSCRIPT (after Redis restart or hitting a new cluster shard), the code falls back toevalwhich implicitly caches the script for subsequent calls.This mirrors the pattern already used by the
limit-connplugin, but improves on it by supporting Redis Cluster mode (limit-conn currently disables evalsha for cluster).Changes:
apisix/plugins/limit-count/limit-count-redis.lua: evalsha + NOSCRIPT fallbackapisix/plugins/limit-count/limit-count-redis-cluster.lua: evalsha + NOSCRIPT fallbackt/plugin/limit-count-redis.t: add test for NOSCRIPT fallback recovery