From d9183aa80ae17d36b79dda48c6b1d7fa22a80ee3 Mon Sep 17 00:00:00 2001
From: xiejun <xiejun@vci-tech.com>
Date: 星期三, 22 一月 2025 11:20:41 +0800
Subject: [PATCH] 现场型号代号/人员/组织接口调试

---
 Source/BladeX-Tool/blade-starter-redis/src/main/resources/META-INF/scripts/blade_rate_limiter.lua |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/Source/BladeX-Tool/blade-starter-redis/src/main/resources/META-INF/scripts/blade_rate_limiter.lua b/Source/BladeX-Tool/blade-starter-redis/src/main/resources/META-INF/scripts/blade_rate_limiter.lua
new file mode 100644
index 0000000..26be751
--- /dev/null
+++ b/Source/BladeX-Tool/blade-starter-redis/src/main/resources/META-INF/scripts/blade_rate_limiter.lua
@@ -0,0 +1,28 @@
+-- lua 涓嬫爣浠� 1 寮�濮�
+-- 闄愭祦 key
+local key = KEYS[1]
+-- 闄愭祦澶у皬
+local max = tonumber(ARGV[1])
+-- 瓒呮椂鏃堕棿
+local ttl = tonumber(ARGV[2])
+-- 鑰冭檻涓讳粠绛栫暐鍜岃剼鏈洖鏀炬満鍒讹紝杩欎釜time鐢卞鎴风鑾峰彇浼犲叆
+local now = tonumber(ARGV[3])
+-- 宸茬粡杩囨湡鐨勬椂闂寸偣
+local expired = now - (ttl * 1000)
+
+-- 娓呴櫎杩囨湡鐨勬暟鎹�,绉婚櫎鎸囧畾鍒嗘暟锛坰core锛夊尯闂村唴鐨勬墍鏈夋垚鍛�
+redis.call('zremrangebyscore', key, 0, expired)
+-- 鑾峰彇褰撳墠娴侀噺澶у皬
+local currentLimit = tonumber(redis.call('zcard', key))
+
+local nextLimit = currentLimit + 1
+if nextLimit > max then
+    -- 杈惧埌闄愭祦澶у皬 杩斿洖 0
+    return 0;
+else
+    -- 娌℃湁杈惧埌闃堝�� value + 1
+    redis.call("zadd", key, now, now)
+    -- 绉掍负鍗曚綅璁剧疆 key 鐨勭敓瀛樻椂闂�
+    redis.call("pexpire", key, ttl)
+    return nextLimit
+end

--
Gitblit v1.9.3