{"id":222,"date":"2026-08-01T09:52:47","date_gmt":"2026-08-01T01:52:47","guid":{"rendered":"https:\/\/yykcj.com\/?p=222"},"modified":"2026-08-01T09:52:47","modified_gmt":"2026-08-01T01:52:47","slug":"%e6%b7%b1%e5%85%a5%e6%b5%85%e5%87%ba-rate-limiting%ef%bc%9a%e4%bb%8e%e5%9b%ba%e5%ae%9a%e7%aa%97%e5%8f%a3%e5%88%b0%e4%bb%a4%e7%89%8c%e6%a1%b6%e7%9a%84%e5%ae%9e%e6%88%98%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/yykcj.com\/?p=222","title":{"rendered":"\u6df1\u5165\u6d45\u51fa Rate Limiting\uff1a\u4ece\u56fa\u5b9a\u7a97\u53e3\u5230\u4ee4\u724c\u6876\u7684\u5b9e\u6218\u6307\u5357"},"content":{"rendered":"<h2>\u4e3a\u4ec0\u4e48\u4f60\u9700\u8981\u9650\u6d41\uff1f<\/h2>\n<p>\u5728\u5fae\u670d\u52a1\u67b6\u6784\u548c API \u8bbe\u8ba1\u4e2d\uff0c\u9650\u6d41\uff08Rate Limiting\uff09\u662f\u4fdd\u969c\u7cfb\u7edf\u7a33\u5b9a\u6027\u7684\u5173\u952e\u6280\u672f\u3002\u60f3\u8c61\u4e00\u4e0b\uff0c\u4f60\u7684\u670d\u52a1\u7a81\u7136\u88ab\u6076\u610f\u8bf7\u6c42\u6216\u5f02\u5e38\u6d41\u91cf\u51b2\u51fb\uff0c\u5982\u679c\u6ca1\u6709\u9650\u6d41\uff0c\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u53ef\u80fd\u88ab\u8017\u5c3d\uff0cCPU \u98d9\u5347\uff0c\u6700\u7ec8\u5bfc\u81f4\u6574\u4e2a\u670d\u52a1\u4e0d\u53ef\u7528\u3002\u9650\u6d41\u5c31\u50cf\u4ea4\u901a\u7ba1\u5236\uff0c\u5b83\u63a7\u5236\u8bf7\u6c42\u7684\u901f\u7387\uff0c\u786e\u4fdd\u7cfb\u7edf\u8d1f\u8f7d\u5728\u53ef\u627f\u53d7\u8303\u56f4\u5185\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u9650\u6d41\u573a\u666f\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u4fdd\u62a4\u540e\u7aef\u670d\u52a1\u514d\u53d7\u7a81\u53d1\u6d41\u91cf\u51b2\u51fb<\/li>\n<li>\u9632\u6b62 API \u88ab\u6ee5\u7528\uff08\u5982\u722c\u866b\u3001\u66b4\u529b\u7834\u89e3\uff09<\/li>\n<li>\u4fdd\u969c\u591a\u79df\u6237\u7cfb\u7edf\u4e2d\u6bcf\u4e2a\u79df\u6237\u7684\u516c\u5e73\u4f7f\u7528<\/li>\n<li>\u5e73\u6ed1\u6d41\u91cf\uff0c\u907f\u514d\u9ad8\u5cf0\u65f6\u6bb5\u8fc7\u8f7d<\/li>\n<\/ul>\n<p>\u672c\u6587\u5c06\u5e26\u4f60\u6df1\u5165\u7406\u89e3\u56db\u79cd\u7ecf\u5178\u9650\u6d41\u7b97\u6cd5\u7684\u539f\u7406\u4e0e\u5b9e\u73b0\uff0c\u5e76\u7ed9\u51fa\u57fa\u4e8e Node.js \u548c Redis \u7684\u5b9e\u6218\u4ee3\u7801\uff0c\u5e2e\u52a9\u4f60\u6784\u5efa\u9ad8\u53ef\u7528\u7684\u9650\u6d41\u6a21\u5757\u3002<\/p>\n<h2>\u9650\u6d41\u7b97\u6cd5\u6982\u89c8<\/h2>\n<p>\u9650\u6d41\u7b97\u6cd5\u672c\u8d28\u4e0a\u662f\u5bf9\u8bf7\u6c42\u901f\u7387\u7684\u63a7\u5236\uff0c\u5e38\u89c1\u7684\u6709\u56db\u79cd\uff1a<\/p>\n<ol>\n<li><strong>\u56fa\u5b9a\u7a97\u53e3\uff08Fixed Window\uff09<\/strong>\uff1a\u7b80\u5355\uff0c\u4f46\u5b58\u5728\u4e34\u754c\u95ee\u9898\u3002<\/li>\n<li><strong>\u6ed1\u52a8\u7a97\u53e3\uff08Sliding Window\uff09<\/strong>\uff1a\u89e3\u51b3\u56fa\u5b9a\u7a97\u53e3\u7684\u4e34\u754c\u95ee\u9898\uff0c\u4f46\u5b9e\u73b0\u7a0d\u590d\u6742\u3002<\/li>\n<li><strong>\u6f0f\u6876\uff08Leaky Bucket\uff09<\/strong>\uff1a\u6052\u5b9a\u901f\u7387\u5904\u7406\u8bf7\u6c42\uff0c\u9002\u5408\u5e73\u6ed1\u6d41\u91cf\u3002<\/li>\n<li><strong>\u4ee4\u724c\u6876\uff08Token Bucket\uff09<\/strong>\uff1a\u5141\u8bb8\u4e00\u5b9a\u7a0b\u5ea6\u7684\u7a81\u53d1\u6d41\u91cf\uff0c\u662f\u6700\u5e38\u7528\u7684\u7b97\u6cd5\u3002<\/li>\n<\/ol>\n<p>\u4e0b\u9762\u6211\u4eec\u9010\u4e00\u6df1\u5165\u3002<\/p>\n<h2>1. \u56fa\u5b9a\u7a97\u53e3\u7b97\u6cd5<\/h2>\n<h3>\u539f\u7406<\/h3>\n<p>\u56fa\u5b9a\u7a97\u53e3\u5c06\u65f6\u95f4\u5212\u5206\u4e3a\u56fa\u5b9a\u5927\u5c0f\u7684\u7a97\u53e3\uff08\u5982 1 \u79d2\uff09\uff0c\u6bcf\u4e2a\u7a97\u53e3\u5185\u5141\u8bb8\u4e00\u5b9a\u6570\u91cf\u7684\u8bf7\u6c42\u3002\u7a97\u53e3\u8fb9\u754c\u662f\u56fa\u5b9a\u7684\uff08\u5982\u4ece 0 \u79d2\u5230 1 \u79d2\uff0c1 \u79d2\u5230 2 \u79d2\uff09\u3002<\/p>\n<h3>\u5b9e\u73b0<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684 Node.js \u5b9e\u73b0\uff1a<\/p>\n<pre><code class=\"language-javascript\">\nclass FixedWindowLimiter {\n    constructor(windowSizeMs, maxRequests) {\n        this.windowSizeMs = windowSizeMs;\n        this.maxRequests = maxRequests;\n        this.windowStart = Date.now();\n        this.count = 0;\n    }\n\n    allow() {\n        const now = Date.now();\n        \/\/ \u5982\u679c\u5f53\u524d\u65f6\u95f4\u8d85\u8fc7\u7a97\u53e3\u8fb9\u754c\uff0c\u91cd\u7f6e\u7a97\u53e3\n        if (now - this.windowStart &gt;= this.windowSizeMs) {\n            this.windowStart = now;\n            this.count = 0;\n        }\n        if (this.count &lt; this.maxRequests) {\n            this.count++;\n            return true;\n        }\n        return false;\n    }\n}\n<\/code><\/pre>\n<h3>\u4e34\u754c\u95ee\u9898<\/h3>\n<p>\u56fa\u5b9a\u7a97\u53e3\u7684\u7f3a\u9677\u5728\u4e8e\u4e34\u754c\u95ee\u9898\u3002\u5047\u8bbe\u7a97\u53e3\u5927\u5c0f\u4e3a 1 \u79d2\uff0c\u6700\u5927\u8bf7\u6c42\u6570\u4e3a 5\u3002\u5728 0.9 \u79d2\u65f6\u6765\u4e86 5 \u4e2a\u8bf7\u6c42\uff0c\u7a97\u53e3\u91cd\u7f6e\u540e\uff0c1.1 \u79d2\u53c8\u6765\u4e86 5 \u4e2a\u8bf7\u6c42\uff0c\u90a3\u4e48 0.9 \u5230 1.1 \u79d2\u4e4b\u95f4\u5b9e\u9645\u4e0a\u5904\u7406\u4e86 10 \u4e2a\u8bf7\u6c42\uff0c\u8d85\u51fa\u4e86\u9650\u5236\u3002<\/p>\n<h2>2. \u6ed1\u52a8\u7a97\u53e3\u7b97\u6cd5<\/h2>\n<h3>\u539f\u7406<\/h3>\n<p>\u6ed1\u52a8\u7a97\u53e3\u5c06\u65f6\u95f4\u5212\u5206\u4e3a\u66f4\u5c0f\u7684\u7c92\u5ea6\uff08\u5982\u79d2\uff09\uff0c\u5e76\u8bb0\u5f55\u6bcf\u4e2a\u5c0f\u7a97\u53e3\u7684\u8bf7\u6c42\u6570\u3002\u7a97\u53e3\u968f\u65f6\u95f4\u6ed1\u52a8\uff0c\u8ba1\u7b97\u5f53\u524d\u7a97\u53e3\u603b\u548c\u3002<\/p>\n<h3>\u5b9e\u73b0<\/h3>\n<p>\u4f7f\u7528\u4e00\u4e2a\u6570\u7ec4\u8bb0\u5f55\u6bcf\u4e2a\u5c0f\u7a97\u53e3\u7684\u8ba1\u6570\uff1a<\/p>\n<pre><code class=\"language-javascript\">\nclass SlidingWindowLimiter {\n    constructor(windowSizeMs, maxRequests, precisionMs = 1000) {\n        this.windowSizeMs = windowSizeMs;\n        this.maxRequests = maxRequests;\n        this.precisionMs = precisionMs;\n        this.window = []; \/\/ \u5b58\u50a8 [timestamp, count]\n    }\n\n    allow() {\n        const now = Date.now();\n        \/\/ \u6e05\u7406\u8fc7\u671f\u6570\u636e\n        while (this.window.length &gt; 0 &amp;&amp; now - this.window[0][0] &gt; this.windowSizeMs) {\n            this.window.shift();\n        }\n        \/\/ \u8ba1\u7b97\u5f53\u524d\u7a97\u53e3\u603b\u8bf7\u6c42\u6570\n        let total = 0;\n        for (const [ts, count] of this.window) {\n            total += count;\n        }\n        if (total &lt; this.maxRequests) {\n            \/\/ \u6dfb\u52a0\u5f53\u524d\u8bf7\u6c42\u5230\u7a97\u53e3\n            const lastIndex = this.window.length - 1;\n            if (lastIndex &gt;= 0 &amp;&amp; now - this.window[lastIndex][0] &lt; this.precisionMs) {\n                this.window[lastIndex][1]++;\n            } else {\n                this.window.push([now, 1]);\n            }\n            return true;\n        }\n        return false;\n    }\n}\n<\/code><\/pre>\n<p>\u6ed1\u52a8\u7a97\u53e3\u7684\u7cbe\u5ea6\u53d6\u51b3\u4e8e\u5c0f\u7a97\u53e3\u7684\u7c92\u5ea6\u3002\u7c92\u5ea6\u8d8a\u5c0f\uff0c\u7cbe\u5ea6\u8d8a\u9ad8\uff0c\u4f46\u5185\u5b58\u5360\u7528\u4e5f\u8d8a\u5927\u3002<\/p>\n<h2>3. \u6f0f\u6876\u7b97\u6cd5<\/h2>\n<h3>\u539f\u7406<\/h3>\n<p>\u6f0f\u6876\u7b97\u6cd5\u5c06\u8bf7\u6c42\u89c6\u4e3a\u6c34\u6ef4\uff0c\u6876\u7684\u5bb9\u91cf\u6709\u9650\uff0c\u6c34\u6ef4\u4ee5\u56fa\u5b9a\u901f\u7387\u4ece\u6876\u5e95\u6f0f\u51fa\uff08\u5373\u5904\u7406\u8bf7\u6c42\uff09\u3002\u5982\u679c\u6876\u6ee1\u4e86\uff0c\u65b0\u7684\u6c34\u6ef4\u4f1a\u88ab\u4e22\u5f03\u3002<\/p>\n<h3>\u5b9e\u73b0<\/h3>\n<pre><code class=\"language-javascript\">\nclass LeakyBucketLimiter {\n    constructor(capacity, leakRatePerSec) {\n        this.capacity = capacity;\n        this.leakRatePerSec = leakRatePerSec;\n        this.water = 0;\n        this.lastTime = Date.now();\n    }\n\n    allow() {\n        const now = Date.now();\n        \/\/ \u8ba1\u7b97\u6f0f\u6389\u7684\u6c34\u91cf\n        const leaked = ((now - this.lastTime) \/ 1000) * this.leakRatePerSec;\n        this.water = Math.max(0, this.water - leaked);\n        this.lastTime = now;\n        if (this.water &lt; this.capacity) {\n            this.water++;\n            return true;\n        }\n        return false;\n    }\n}\n<\/code><\/pre>\n<p>\u6f0f\u6876\u7b97\u6cd5\u5f3a\u5236\u5e73\u6ed1\u6d41\u91cf\uff0c\u4f46\u65e0\u6cd5\u5e94\u5bf9\u7a81\u53d1\u6d41\u91cf\uff0c\u56e0\u4e3a\u5373\u4f7f\u6876\u672a\u6ee1\uff0c\u5904\u7406\u901f\u7387\u4e5f\u662f\u6052\u5b9a\u7684\u3002<\/p>\n<h2>4. \u4ee4\u724c\u6876\u7b97\u6cd5<\/h2>\n<h3>\u539f\u7406<\/h3>\n<p>\u4ee4\u724c\u6876\u4ee5\u56fa\u5b9a\u901f\u7387\u5411\u6876\u4e2d\u6dfb\u52a0\u4ee4\u724c\uff0c\u6bcf\u4e2a\u8bf7\u6c42\u9700\u8981\u6d88\u8017\u4e00\u4e2a\u4ee4\u724c\u3002\u6876\u7684\u5bb9\u91cf\u6709\u9650\uff0c\u5982\u679c\u6876\u6ee1\u5219\u4ee4\u724c\u88ab\u4e22\u5f03\u3002\u4e0e\u6f0f\u6876\u4e0d\u540c\uff0c\u4ee4\u724c\u6876\u5141\u8bb8\u4e00\u5b9a\u7a0b\u5ea6\u7684\u7a81\u53d1\u6d41\u91cf\uff08\u56e0\u4e3a\u6876\u5185\u53ef\u4ee5\u7d2f\u79ef\u4ee4\u724c\uff09\u3002<\/p>\n<h3>\u5b9e\u73b0<\/h3>\n<pre><code class=\"language-javascript\">\nclass TokenBucketLimiter {\n    constructor(capacity, refillRatePerSec) {\n        this.capacity = capacity;\n        this.tokens = capacity; \/\/ \u521d\u59cb\u88c5\u6ee1\u4ee4\u724c\n        this.refillRatePerSec = refillRatePerSec;\n        this.lastRefill = Date.now();\n    }\n\n    allow() {\n        this.refill();\n        if (this.tokens &gt;= 1) {\n            this.tokens--;\n            return true;\n        }\n        return false;\n    }\n\n    refill() {\n        const now = Date.now();\n        const elapsedSec = (now - this.lastRefill) \/ 1000;\n        this.tokens = Math.min(this.capacity, this.tokens + elapsedSec * this.refillRatePerSec);\n        this.lastRefill = now;\n    }\n}\n<\/code><\/pre>\n<p>\u4ee4\u724c\u6876\u7b97\u6cd5\u662f\u4e1a\u754c\u6700\u5e38\u7528\u7684\u7b97\u6cd5\uff0c\u4f8b\u5982 Guava \u7684 RateLimiter \u5c31\u662f\u57fa\u4e8e\u4ee4\u724c\u6876\u7684\u53d8\u4f53\u3002<\/p>\n<h2>\u5b9e\u6218\uff1a\u57fa\u4e8e Redis \u7684\u5206\u5e03\u5f0f\u9650\u6d41<\/h2>\n<p>\u5355\u673a\u9650\u6d41\u65e0\u6cd5\u5e94\u5bf9\u591a\u5b9e\u4f8b\u90e8\u7f72\u7684\u573a\u666f\uff0c\u56e0\u6b64\u6211\u4eec\u9700\u8981\u5206\u5e03\u5f0f\u9650\u6d41\u3002Redis \u7684 <code>INCR<\/code> \u548c <code>EXPIRE<\/code> \u547d\u4ee4\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u56fa\u5b9a\u7a97\u53e3\u9650\u6d41\u3002<\/p>\n<h3>\u56fa\u5b9a\u7a97\u53e3\u7684 Redis \u5b9e\u73b0<\/h3>\n<pre><code class=\"language-javascript\">\nconst redis = require(&#x27;redis&#x27;);\nconst client = redis.createClient();\n\nasync function fixedWindowLimit(key, maxRequests, windowSec) {\n    const current = await client.incr(key);\n    if (current === 1) {\n        await client.expire(key, windowSec);\n    }\n    return current &lt;= maxRequests;\n}\n<\/code><\/pre>\n<p>\u4f46\u8fd9\u79cd\u65b9\u5f0f\u4ecd\u6709\u4e34\u754c\u95ee\u9898\u3002\u66f4\u4f18\u96c5\u7684\u65b9\u6848\u662f\u4f7f\u7528 Redis \u7684 <code>ZSET<\/code> \u5b9e\u73b0\u6ed1\u52a8\u7a97\u53e3\u3002<\/p>\n<h3>\u6ed1\u52a8\u7a97\u53e3\u7684 Redis \u5b9e\u73b0<\/h3>\n<pre><code class=\"language-javascript\">\nasync function slidingWindowLimit(userId, maxRequests, windowSec) {\n    const key = `rate:${userId}`;\n    const now = Date.now();\n    const oldest = now - windowSec * 1000;\n    const pipeline = client.multi();\n    pipeline.zremrangebyscore(key, 0, oldest); \/\/ \u79fb\u9664\u8fc7\u671f\u8bb0\u5f55\n    pipeline.zadd(key, now, now); \/\/ \u6dfb\u52a0\u5f53\u524d\u8bf7\u6c42\n    pipeline.zcard(key); \/\/ \u7edf\u8ba1\u7a97\u53e3\u5185\u8bf7\u6c42\u6570\n    pipeline.expire(key, windowSec); \/\/ \u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\n    const results = await pipeline.exec();\n    const count = results[2];\n    return count &lt;= maxRequests;\n}\n<\/code><\/pre>\n<h3>\u4ee4\u724c\u6876\u7684 Redis \u5b9e\u73b0\uff08Lua \u811a\u672c\uff09<\/h3>\n<p>\u4e3a\u4e86\u539f\u5b50\u6027\uff0c\u6211\u4eec\u4f7f\u7528 Lua \u811a\u672c\uff1a<\/p>\n<pre><code class=\"language-lua\">\n-- KEYS[1]: \u4ee4\u724c\u6876 key\n-- ARGV[1]: \u5bb9\u91cf\n-- ARGV[2]: \u6bcf\u79d2\u8865\u5145\u901f\u7387\n-- ARGV[3]: \u5f53\u524d\u65f6\u95f4\u6233\uff08\u79d2\uff09\n-- ARGV[4]: \u8bf7\u6c42\u7684\u4ee4\u724c\u6570\uff08\u901a\u5e38\u4e3a1\uff09\n\nlocal bucket = KEYS[1]\nlocal capacity = tonumber(ARGV[1])\nlocal refillRate = tonumber(ARGV[2])\nlocal now = tonumber(ARGV[3])\nlocal requested = tonumber(ARGV[4])\n\nlocal lastRefill = tonumber(redis.call(&#x27;hget&#x27;, bucket, &#x27;lastRefill&#x27;) or now)\nlocal tokens = tonumber(redis.call(&#x27;hget&#x27;, bucket, &#x27;tokens&#x27;) or capacity)\n\n-- \u8ba1\u7b97\u8865\u5145\u7684\u4ee4\u724c\nlocal elapsed = math.max(0, now - lastRefill)\ntokens = math.min(capacity, tokens + elapsed * refillRate)\n\nif tokens &gt;= requested then\n    tokens = tokens - requested\n    redis.call(&#x27;hset&#x27;, bucket, &#x27;tokens&#x27;, tokens)\n    redis.call(&#x27;hset&#x27;, bucket, &#x27;lastRefill&#x27;, now)\n    return 1\nelse\n    return 0\nend\n<\/code><\/pre>\n<p>\u5728 Node.js \u4e2d\u8c03\u7528\uff1a<\/p>\n<pre><code class=\"language-javascript\">\nconst script = `...`; \/\/ \u4e0a\u9762\u7684 Lua \u811a\u672c\nconst result = await client.eval(script, 1, &#x27;user:123&#x27;, capacity, refillRate, Math.floor(Date.now()\/1000), 1);\n<\/code><\/pre>\n<h2>\u6700\u4f73\u5b9e\u8df5\u4e0e\u907f\u5751\u6307\u5357<\/h2>\n<h3>\u9009\u62e9\u5408\u9002\u7684\u7b97\u6cd5<\/h3>\n<ul>\n<li>\u5982\u679c\u7cfb\u7edf\u9700\u8981\u5e73\u6ed1\u6d41\u91cf\uff0c\u9009\u62e9\u6f0f\u6876\u3002<\/li>\n<li>\u5982\u679c\u5e0c\u671b\u5141\u8bb8\u7a81\u53d1\u6d41\u91cf\uff0c\u9009\u62e9\u4ee4\u724c\u6876\u3002<\/li>\n<li>\u5982\u679c\u662f\u7b80\u5355\u7684 API \u9650\u6d41\uff0c\u56fa\u5b9a\u7a97\u53e3\u6216\u6ed1\u52a8\u7a97\u53e3\u5df2\u8db3\u591f\u3002<\/li>\n<\/ul>\n<h3>\u6ce8\u610f\u65f6\u949f\u540c\u6b65<\/h3>\n<p>\u5728\u5206\u5e03\u5f0f\u73af\u5883\u4e2d\uff0c\u65f6\u95f4\u6233\u4f9d\u8d56\u53ef\u80fd\u5bfc\u81f4\u95ee\u9898\u3002\u5982\u679c\u4f7f\u7528 Redis\uff0c\u786e\u4fdd\u670d\u52a1\u5668\u65f6\u95f4\u540c\u6b65\uff08NTP\uff09\u3002<\/p>\n<h3>\u8bbe\u7f6e\u5408\u7406\u7684\u8d85\u65f6\u548c\u8fc7\u671f\u65f6\u95f4<\/h3>\n<p>Redis \u7684 key \u4e00\u5b9a\u8981\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\uff0c\u9632\u6b62\u5185\u5b58\u6cc4\u6f0f\u3002<\/p>\n<h3>\u4f7f\u7528\u539f\u5b50\u64cd\u4f5c<\/h3>\n<p>\u907f\u514d\u7ade\u6001\u6761\u4ef6\uff0c\u4f7f\u7528 Lua \u811a\u672c\u6216\u4e8b\u52a1\u3002<\/p>\n<h3>\u964d\u7ea7\u7b56\u7565<\/h3>\n<p>\u5f53\u9650\u6d41\u89e6\u53d1\u65f6\uff0c\u53ef\u4ee5\u8fd4\u56de 429 \u72b6\u6001\u7801\uff0c\u5e76\u63d0\u4f9b Retry-After \u5934\u3002<\/p>\n<h3>\u76d1\u63a7\u4e0e\u544a\u8b66<\/h3>\n<p>\u8bb0\u5f55\u9650\u6d41\u4e8b\u4ef6\uff0c\u76d1\u63a7\u6307\u6807\uff0c\u53ca\u65f6\u53d1\u73b0\u5f02\u5e38\u3002<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u9650\u6d41\u662f\u7cfb\u7edf\u9632\u62a4\u7684\u91cd\u8981\u9632\u7ebf\uff0c\u672c\u6587\u4ecb\u7ecd\u4e86\u56db\u79cd\u7b97\u6cd5\u7684\u539f\u7406\u4e0e\u5b9e\u73b0\uff0c\u5e76\u7ed9\u51fa\u4e86\u5206\u5e03\u5f0f\u9650\u6d41\u7684\u5b9e\u6218\u65b9\u6848\u3002\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\uff0c\u5efa\u8bae\u7ed3\u5408\u5177\u4f53\u573a\u666f\u9009\u62e9\u5408\u9002\u7684\u7b97\u6cd5\uff0c\u5e76\u6ce8\u610f\u539f\u5b50\u6027\u548c\u6027\u80fd\u3002\u4e0b\u4e00\u6b65\uff0c\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u5c06\u9650\u6d41\u96c6\u6210\u5230 API \u7f51\u5173\u4e2d\uff0c\u6216\u8005\u4f7f\u7528\u73b0\u6210\u7684\u4e2d\u95f4\u4ef6\uff08\u5982 Express-rate-limit\uff09\u3002<\/p>\n<p>\u5e0c\u671b\u672c\u6587\u80fd\u5e2e\u52a9\u4f60\u6784\u5efa\u7a33\u5b9a\u53ef\u9760\u7684\u7cfb\u7edf\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9650\u6d41\u662f\u4fdd\u969c\u7cfb\u7edf\u7a33\u5b9a\u6027\u7684\u5173\u952e\u624b\u6bb5\uff0c\u672c\u6587\u4ece\u57fa\u7840\u6982\u5ff5\u51fa\u53d1\uff0c\u9010\u6b65\u8bb2\u89e3\u56fa\u5b9a\u7a97\u53e3\u3001\u6ed1\u52a8\u7a97\u53e3\u3001\u6f0f\u6876\u548c\u4ee4\u724c\u6876\u56db\u79cd\u9650\u6d41\u7b97\u6cd5\u7684\u539f\u7406\u4e0e\u5b9e\u73b0\uff0c\u5e76\u7ed9\u51fa Node.js \u548c Redis \u7684\u5b9e\u6218\u793a\u4f8b\uff0c\u52a9\u4f60\u8f7b\u677e\u5e94\u5bf9\u9ad8\u5e76\u53d1\u573a\u666f\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[5,168,65,66,169],"class_list":["post-222","post","type-post","status-publish","format-standard","hentry","category-3","category-4","tag-node-js","tag-rate-limiting","tag-redis","tag-66","tag-169"],"_links":{"self":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts\/222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=222"}],"version-history":[{"count":0,"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts\/222\/revisions"}],"wp:attachment":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}