{"id":111459,"date":"2026-10-01T08:57:09","date_gmt":"2026-10-01T00:57:09","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/111459.html"},"modified":"2026-10-01T08:57:09","modified_gmt":"2026-10-01T00:57:09","slug":"%e3%80%90%e5%9f%ba%e4%ba%8e-swoolehyperf-%e7%9a%84%e5%be%ae%e6%9c%8d%e5%8a%a1%e5%ae%9e%e6%88%98%e3%80%91%e7%ac%ac%e5%85%ab%e5%91%a8%c2%b7%e5%91%a8%e5%9b%9b%ef%bc%9a%e5%88%86%e5%b8%83%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/111459.html","title":{"rendered":"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011\u7b2c\u516b\u5468\u00b7\u5468\u56db\uff1a\u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236"},"content":{"rendered":"<h3>\u3010\u57fa\u4e8e Swoole&#043;Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011\u7b2c\u516b\u5468\u00b7\u5468\u56db&#xff1a;\u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236<\/h3>\n<hr \/>\n<p>\u4eca\u5929\u6211\u4eec\u8fdb\u5165\u7b2c\u516b\u5468\u5468\u56db&#xff0c;\u4e3b\u9898\u662f \u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236\u3002\u6628\u5929\u6211\u4eec\u7684 Saga \u534f\u8c03\u5668\u5df2\u7ecf\u80fd\u591f\u4fdd\u8bc1\u5206\u5e03\u5f0f\u4e8b\u52a1\u7684\u6700\u7ec8\u4e00\u81f4\u6027&#xff0c;\u4f46\u5728\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b&#xff08;\u5982\u79d2\u6740&#xff09;&#xff0c;\u5355\u7eaf\u7684\u6570\u636e\u5e93\u884c\u9501\u53ef\u80fd\u6210\u4e3a\u74f6\u9888&#xff0c;\u5e76\u4e14\u5fae\u670d\u52a1\u67b6\u6784\u4e2d\u670d\u52a1\u95f4\u7ade\u4e89\u8d44\u6e90\u9700\u8981\u66f4\u901a\u7528\u7684\u9501\u673a\u5236\u3002\u4eca\u5929\u6211\u4eec\u5c06\u5f15\u5165 Redis \u5206\u5e03\u5f0f\u9501&#xff0c;\u901a\u8fc7 hyperf\/redis-lock \u7ec4\u4ef6\u5b9e\u73b0\u5bf9\u5171\u4eab\u8d44\u6e90\u7684\u5b89\u5168\u8bbf\u95ee&#xff0c;\u9632\u6b62\u8d85\u5356\u7b49\u5e76\u53d1\u95ee\u9898&#xff0c;\u5e76\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684\u79d2\u6740\u63a5\u53e3&#xff0c;\u4eb2\u8eab\u4f53\u9a8c\u9501\u7684\u5a01\u529b\u3002<\/p>\n<hr \/>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001005702-6abdafde69fe6.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>\u4eca\u65e5\u76ee\u6807<\/h4>\n<li>\u7406\u89e3\u5206\u5e03\u5f0f\u9501\u7684\u6838\u5fc3\u8981\u6c42&#xff1a;\u4e92\u65a5\u3001\u9632\u6b7b\u9501\u3001\u9ad8\u53ef\u7528\u3001\u53ef\u91cd\u5165\u3002<\/li>\n<li>\u638c\u63e1 Redis \u5b9e\u73b0\u5206\u5e03\u5f0f\u9501\u7684\u539f\u7406&#xff08;SETNX\u3001\u9501\u7eed\u671f\u3001RedLock \u7b97\u6cd5&#xff09;\u3002<\/li>\n<li>\u5728 Hyperf \u4e2d\u5b89\u88c5\u5e76\u914d\u7f6e hyperf\/redis-lock&#xff0c;\u4f7f\u7528\u6ce8\u89e3\u6216 API \u65b9\u5f0f\u52a0\u9501\u3002<\/li>\n<li>\u6539\u9020\u5e93\u5b58\u6263\u51cf\u903b\u8f91&#xff0c;\u5728\u51bb\u7ed3\u5e93\u5b58\u65f6\u6dfb\u52a0\u5206\u5e03\u5f0f\u9501&#xff0c;\u9632\u6b62\u5e76\u53d1\u8d85\u5356\u3002<\/li>\n<li>\u4f7f\u7528 JMeter \u6216 ab \u8fdb\u884c\u9ad8\u5e76\u53d1\u79d2\u6740\u538b\u6d4b&#xff0c;\u5bf9\u6bd4\u52a0\u9501\u524d\u540e\u7684\u5e93\u5b58\u4e00\u81f4\u6027\u3002<\/li>\n<li>\u7b80\u5355\u4ecb\u7ecd Redis \u7ea2\u9501&#xff08;RedLock&#xff09;\u914d\u7f6e&#xff0c;\u63d0\u5347\u751f\u4ea7\u73af\u5883\u7684\u9501\u53ef\u9760\u6027\u3002<\/li>\n<hr \/>\n<h4>\u4e00\u3001\u73af\u5883\u51c6\u5907&#xff08;\u7ea6 20 \u5206\u949f&#xff09;<\/h4>\n<p>\u7ee7\u7eed\u5728 hyperf-app \u5bb9\u5668\u4e2d\u64cd\u4f5c&#xff0c;\u786e\u4fdd Redis \u5bb9\u5668\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<p><span class=\"token function\">docker-compose<\/span> <span class=\"token builtin class-name\">exec<\/span> swoole <span class=\"token function\">bash<\/span><br \/>\n<span class=\"token builtin class-name\">cd<\/span> \/var\/www\/hyperf-app<\/p>\n<h5>\u5b89\u88c5\u9501\u7ec4\u4ef6<\/h5>\n<p><span class=\"token function\">composer<\/span> require hyperf\/redis-lock<\/p>\n<p>\u8be5\u7ec4\u4ef6\u4f9d\u8d56 hyperf\/redis&#xff08;\u5df2\u5b89\u88c5&#xff09;\u3002\u65e0\u9700\u989d\u5916\u53d1\u5e03\u914d\u7f6e&#xff0c;\u9501\u7684\u914d\u7f6e\u901a\u8fc7 Redis \u8fde\u63a5\u6c60\u5373\u53ef\u3002<\/p>\n<hr \/>\n<h4>\u4e8c\u3001\u77e5\u8bc6\u6838\u5fc3&#xff1a;\u5206\u5e03\u5f0f\u9501\u4e0e Redis \u5b9e\u73b0&#xff08;\u7ea6 1 \u5c0f\u65f6&#xff09;<\/h4>\n<h5>1. \u4e3a\u4ec0\u4e48\u9700\u8981\u5206\u5e03\u5f0f\u9501&#xff1f;<\/h5>\n<p>\u5728\u5355\u4f53\u5e94\u7528\u4e2d&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u8bed\u8a00\u7ea7\u522b\u7684\u9501&#xff08;\u5982 synchronized&#xff09;\u6216\u6570\u636e\u5e93\u884c\u9501\u6765\u4fdd\u8bc1\u5e76\u53d1\u5b89\u5168\u3002\u4f46\u5728\u5fae\u670d\u52a1\u4e2d&#xff0c;\u591a\u4e2a\u5b9e\u4f8b\u53ef\u80fd\u540c\u65f6\u64cd\u4f5c\u540c\u4e00\u4e2a\u8d44\u6e90&#xff08;\u5982\u6263\u51cf\u5e93\u5b58&#xff09;&#xff0c;\u9700\u8981\u8de8\u8fdb\u7a0b\u7684\u9501\u3002\u5206\u5e03\u5f0f\u9501\u5e94\u6ee1\u8db3&#xff1a;<\/p>\n<ul>\n<li>\u4e92\u65a5\u6027&#xff1a;\u540c\u4e00\u65f6\u523b\u53ea\u6709\u4e00\u4e2a\u5ba2\u6237\u7aef\u6301\u6709\u9501\u3002<\/li>\n<li>\u9632\u6b7b\u9501&#xff1a;\u5373\u4f7f\u6301\u6709\u9501\u7684\u8fdb\u7a0b\u5d29\u6e83&#xff0c;\u9501\u4e5f\u80fd\u88ab\u81ea\u52a8\u91ca\u653e&#xff08;\u901a\u8fc7 TTL&#xff09;\u3002<\/li>\n<li>\u9ad8\u53ef\u7528&#xff1a;\u9501\u670d\u52a1\u672c\u8eab\u4e0d\u80fd\u5355\u70b9\u6545\u969c&#xff08;\u5982 Redis \u96c6\u7fa4\u6216\u7ea2\u9501&#xff09;\u3002<\/li>\n<li>\u53ef\u91cd\u5165\u6027&#xff1a;\u540c\u4e00\u7ebf\u7a0b\u53ef\u591a\u6b21\u83b7\u53d6\u540c\u4e00\u628a\u9501&#xff08;Hyperf \u652f\u6301&#xff09;\u3002<\/li>\n<\/ul>\n<h5>2. Redis \u5206\u5e03\u5f0f\u9501\u6f14\u8fdb<\/h5>\n<p>\u9636\u6bb5\u4e00&#xff1a;SETNX &#043; EXPIRE&#xff08;\u4e0d\u63a8\u8350&#xff09;<\/p>\n<p><span class=\"token comment\">\/\/ \u95ee\u9898&#xff1a;SETNX \u548c EXPIRE \u4e0d\u662f\u539f\u5b50\u64cd\u4f5c&#xff0c;\u82e5 SETNX \u540e\u8fdb\u7a0b\u5d29\u6e83&#xff0c;\u5219\u9501\u6c38\u4e0d\u8fc7\u671f<\/span><\/p>\n<p>\u9636\u6bb5\u4e8c&#xff1a;SET key value NX EX timeout&#xff08;\u539f\u5b50\u64cd\u4f5c&#xff09;<br \/>\nRedis 2.6.12 \u8d77\u652f\u6301 SET key value NX EX seconds&#xff0c;\u83b7\u53d6\u9501\u548c\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4\u539f\u5b50\u6267\u884c\u3002<\/p>\n<p><span class=\"token variable\">$ok<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token variable\">$redis<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">set<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;lock:product:1&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token variable\">$uniqueValue<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string single-quoted-string\">&#039;NX&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string single-quoted-string\">&#039;EX&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token number\">30<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u9636\u6bb5\u4e09&#xff1a;\u9501\u7eed\u671f&#xff08;\u770b\u95e8\u72d7&#xff09;<br \/>\n\u82e5\u4efb\u52a1\u6267\u884c\u65f6\u95f4\u8d85\u8fc7\u9501\u7684 TTL&#xff0c;\u9501\u4f1a\u81ea\u52a8\u91ca\u653e&#xff0c;\u5bfc\u81f4\u5176\u4ed6\u8fdb\u7a0b\u83b7\u53d6\u9501&#xff0c;\u4ea7\u751f\u5e76\u53d1\u95ee\u9898\u3002\u9700\u8981\u540e\u53f0\u534f\u7a0b\u5b9a\u671f\u7eed\u671f\u3002<\/p>\n<p>\u9636\u6bb5\u56db&#xff1a;RedLock \u7b97\u6cd5<br \/>\n\u5728\u591a\u4e2a\u72ec\u7acb\u7684 Redis \u5b9e\u4f8b\u4e0a\u4f9d\u6b21\u83b7\u53d6\u9501&#xff0c;\u5927\u591a\u6570\u6210\u529f\u624d\u7b97\u83b7\u53d6\u6210\u529f&#xff0c;\u9632\u6b62\u5355\u70b9 Redis \u6545\u969c\u5bfc\u81f4\u9501\u5931\u6548\u3002<\/p>\n<h5>3. hyperf\/redis-lock \u7ec4\u4ef6<\/h5>\n<p>\u57fa\u4e8e\u4ee5\u4e0a\u539f\u7406&#xff0c;hyperf\/redis-lock \u63d0\u4f9b\u4e86&#xff1a;<\/p>\n<ul>\n<li>Hyperf\\\\Redis\\\\Lock\\\\RedisLock&#xff1a;\u57fa\u672c\u7684\u9501\u5b9e\u73b0&#xff0c;\u652f\u6301\u7eed\u671f&#xff08;WatchDog&#xff09;\u3002<\/li>\n<li>#[RedisLock] \u6ce8\u89e3&#xff1a;\u53ef\u5e94\u7528\u4e8e\u65b9\u6cd5&#xff0c;\u81ea\u52a8\u52a0\u9501\u91ca\u653e\u3002<\/li>\n<li>\u914d\u7f6e\u7ea2\u9501&#xff1a;\u901a\u8fc7 RedisLockFactory \u6216\u914d\u7f6e\u6587\u4ef6\u6307\u5b9a\u591a\u4e2a Redis \u8fde\u63a5\u3002<\/li>\n<\/ul>\n<p>\u6211\u4eec\u5c06\u5728\u79d2\u6740\u573a\u666f\u4e2d\u4f7f\u7528\u6ce8\u89e3\u65b9\u5f0f&#xff0c;\u7b80\u5355\u9ad8\u6548\u3002<\/p>\n<hr \/>\n<h4>\u4e09\u3001\u5b9e\u6218&#xff1a;\u79d2\u6740\u63a5\u53e3\u52a0\u9501\u9632\u8d85\u5356&#xff08;\u7ea6 2.5 \u5c0f\u65f6&#xff09;<\/h4>\n<h5>\u6b65\u9aa4 1&#xff1a;\u79d2\u6740\u4e1a\u52a1\u51c6\u5907<\/h5>\n<p>\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u9ad8\u5e76\u53d1\u573a\u666f\u6765\u4f53\u73b0\u9501\u7684\u4f5c\u7528\u3002\u8bbe\u8ba1\u4e00\u4e2a\u79d2\u6740\u63a5\u53e3 POST \/seckill&#xff0c;\u903b\u8f91\u4e3a&#xff1a;\u6263\u51cf\u6307\u5b9a\u5546\u54c1\u7684\u5e93\u5b58&#xff08;\u76f4\u63a5\u6263\u51cf total_stock&#xff0c;\u4e0d\u4f7f\u7528\u51bb\u7ed3\u6a21\u5f0f&#xff0c;\u7b80\u5316\u6f14\u793a&#xff09;\u3002\u4e0d\u52a0\u9501\u65f6\u5fc5\u7136\u8d85\u5356&#xff0c;\u52a0\u9501\u540e\u5e93\u5b58\u6b63\u786e\u3002<\/p>\n<p>\u521b\u5efa app\/Controller\/SeckillController.php&#xff1a;<\/p>\n<p><span class=\"token delimiter important\">&lt;?php<\/span><br \/>\n<span class=\"token keyword\">namespace<\/span> <span class=\"token package\">App<span class=\"token punctuation\">\\\\<\/span>Controller<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">use<\/span> <span class=\"token package\">Hyperf<span class=\"token punctuation\">\\\\<\/span>DbConnection<span class=\"token punctuation\">\\\\<\/span>Db<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">use<\/span> <span class=\"token package\">Hyperf<span class=\"token punctuation\">\\\\<\/span>HttpServer<span class=\"token punctuation\">\\\\<\/span>Annotation<span class=\"token punctuation\">\\\\<\/span>Controller<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">use<\/span> <span class=\"token package\">Hyperf<span class=\"token punctuation\">\\\\<\/span>HttpServer<span class=\"token punctuation\">\\\\<\/span>Annotation<span class=\"token punctuation\">\\\\<\/span>RequestMapping<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">use<\/span> <span class=\"token package\">Hyperf<span class=\"token punctuation\">\\\\<\/span>Redis<span class=\"token punctuation\">\\\\<\/span>Lock<span class=\"token punctuation\">\\\\<\/span>RedisLock<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">use<\/span> <span class=\"token package\">Hyperf<span class=\"token punctuation\">\\\\<\/span>Di<span class=\"token punctuation\">\\\\<\/span>Annotation<span class=\"token punctuation\">\\\\<\/span>Inject<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">use<\/span> <span class=\"token package\">Hyperf<span class=\"token punctuation\">\\\\<\/span>Redis<span class=\"token punctuation\">\\\\<\/span>Redis<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token attribute\"><span class=\"token delimiter punctuation\">#[<\/span><span class=\"token attribute-content\"><span class=\"token attribute-class-name class-name\">Controller<\/span><span class=\"token punctuation\">(<\/span><span class=\"token attribute-class-name class-name\">prefix<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string single-quoted-string\">&#039;\/seckill&#039;<\/span><span class=\"token punctuation\">)<\/span><\/span><span class=\"token delimiter punctuation\">]<\/span><\/span><br \/>\n<span class=\"token keyword\">class<\/span> <span class=\"token class-name-definition class-name\">SeckillController<\/span> <span class=\"token keyword\">extends<\/span> <span class=\"token class-name\">AbstractController<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token attribute\"><span class=\"token delimiter punctuation\">#[<\/span><span class=\"token attribute-content\"><span class=\"token attribute-class-name class-name\">Inject<\/span><\/span><span class=\"token delimiter punctuation\">]<\/span><\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token class-name type-declaration\">Redis<\/span> <span class=\"token variable\">$redis<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token attribute\"><span class=\"token delimiter punctuation\">#[<\/span><span class=\"token attribute-content\"><span class=\"token attribute-class-name class-name\">RequestMapping<\/span><span class=\"token punctuation\">(<\/span><span class=\"token attribute-class-name class-name\">path<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string single-quoted-string\">&#039;buy&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token attribute-class-name class-name\">methods<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string single-quoted-string\">&#039;post&#039;<\/span><span class=\"token punctuation\">)<\/span><\/span><span class=\"token delimiter punctuation\">]<\/span><\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token function-definition function\">buy<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token variable\">$productId<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token variable\">$this<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token property\">request<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">input<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;product_id&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u65e0\u9501\u7248\u672c&#xff08;\u7528\u4e8e\u5bf9\u6bd4&#xff09;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token variable\">$this<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">doBuyWithoutLock<\/span><span class=\"token punctuation\">(<\/span><span class=\"token variable\">$productId<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token function-definition function\">doBuyWithoutLock<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword type-hint\">int<\/span> <span class=\"token variable\">$productId<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u67e5\u8be2\u5f53\u524d\u5e93\u5b58<\/span><br \/>\n        <span class=\"token variable\">$stock<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name static-context\">Db<\/span><span class=\"token operator\">::<\/span><span class=\"token function\">table<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;products&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">where<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;id&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token variable\">$productId<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">value<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;total_stock&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token variable\">$stock<\/span> <span class=\"token operator\">&lt;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string single-quoted-string\">&#039;code&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string single-quoted-string\">&#039;message&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token string single-quoted-string\">&#039;\u5e93\u5b58\u4e0d\u8db3&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u6a21\u62df\u5e76\u53d1\u95f4\u9699<\/span><br \/>\n        <span class=\"token class-name class-name-fully-qualified static-context\"><span class=\"token punctuation\">\\\\<\/span>Swoole<span class=\"token punctuation\">\\\\<\/span>Coroutine<\/span><span class=\"token operator\">::<\/span><span class=\"token function\">sleep<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0.001<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u6263\u51cf<\/span><br \/>\n        <span class=\"token class-name static-context\">Db<\/span><span class=\"token operator\">::<\/span><span class=\"token function\">table<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;products&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">where<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;id&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token variable\">$productId<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">decrement<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;total_stock&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string single-quoted-string\">&#039;code&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token number\">200<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string single-quoted-string\">&#039;message&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token string single-quoted-string\">&#039;\u8d2d\u4e70\u6210\u529f&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6d4b\u8bd5&#xff1a;\u5c06\u5546\u54c1\u5e93\u5b58\u8bbe\u4e3a 10&#xff0c;\u5e76\u53d1 100 \u8bf7\u6c42&#xff0c;\u4e0d\u52a0\u9501\u65f6\u6700\u7ec8\u5e93\u5b58\u53ef\u80fd\u4e3a\u8d1f\u6570\u3002<\/p>\n<h5>\u6b65\u9aa4 2&#xff1a;\u4f7f\u7528 RedisLock \u52a0\u9501<\/h5>\n<p>\u4fee\u6539 buy \u65b9\u6cd5&#xff0c;\u4f7f\u7528\u6ce8\u89e3\u65b9\u5f0f\u81ea\u52a8\u52a0\u9501&#xff1a;<\/p>\n<p><span class=\"token keyword\">use<\/span> <span class=\"token package\">Hyperf<span class=\"token punctuation\">\\\\<\/span>Redis<span class=\"token punctuation\">\\\\<\/span>Lock<span class=\"token punctuation\">\\\\<\/span>Annotation<span class=\"token punctuation\">\\\\<\/span>RedisLock<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token attribute\"><span class=\"token delimiter punctuation\">#[<\/span><span class=\"token attribute-content\"><span class=\"token attribute-class-name class-name\">RequestMapping<\/span><span class=\"token punctuation\">(<\/span><span class=\"token attribute-class-name class-name\">path<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string single-quoted-string\">&#039;buy&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token attribute-class-name class-name\">methods<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string single-quoted-string\">&#039;post&#039;<\/span><span class=\"token punctuation\">)<\/span><\/span><span class=\"token delimiter punctuation\">]<\/span><\/span><br \/>\n<span class=\"token attribute\"><span class=\"token delimiter punctuation\">#[<\/span><span class=\"token attribute-content\"><span class=\"token attribute-class-name class-name\">RedisLock<\/span><span class=\"token punctuation\">(<\/span><span class=\"token attribute-class-name class-name\">key<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string single-quoted-string\">&#039;lock:seckill:#{product_id}&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token attribute-class-name class-name\">ttl<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">)<\/span><\/span><span class=\"token delimiter punctuation\">]<\/span><\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token function-definition function\">buy<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token variable\">$productId<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword type-casting\">int<\/span><span class=\"token punctuation\">)<\/span><span class=\"token variable\">$this<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token property\">request<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">input<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;product_id&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token variable\">$this<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">doBuyWithLock<\/span><span class=\"token punctuation\">(<\/span><span class=\"token variable\">$productId<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">private<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token function-definition function\">doBuyWithLock<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword type-hint\">int<\/span> <span class=\"token variable\">$productId<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token variable\">$stock<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name static-context\">Db<\/span><span class=\"token operator\">::<\/span><span class=\"token function\">table<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;products&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">where<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;id&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token variable\">$productId<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">value<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;total_stock&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token variable\">$stock<\/span> <span class=\"token operator\">&lt;&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string single-quoted-string\">&#039;code&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string single-quoted-string\">&#039;message&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token string single-quoted-string\">&#039;\u5e93\u5b58\u4e0d\u8db3&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token class-name class-name-fully-qualified static-context\"><span class=\"token punctuation\">\\\\<\/span>Swoole<span class=\"token punctuation\">\\\\<\/span>Coroutine<\/span><span class=\"token operator\">::<\/span><span class=\"token function\">sleep<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0.001<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token class-name static-context\">Db<\/span><span class=\"token operator\">::<\/span><span class=\"token function\">table<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;products&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">where<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;id&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token variable\">$productId<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">decrement<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;total_stock&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string single-quoted-string\">&#039;code&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token number\">200<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string single-quoted-string\">&#039;message&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token string single-quoted-string\">&#039;\u8d2d\u4e70\u6210\u529f&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li>#[RedisLock] \u6ce8\u89e3\u652f\u6301 SpEL \u8868\u8fbe\u5f0f&#xff0c;#{product_id} \u4f1a\u4ece\u8bf7\u6c42\u53c2\u6570\u4e2d\u83b7\u53d6&#xff0c;\u751f\u6210\u9501\u952e lock:seckill:1\u3002<\/li>\n<li>ttl \u8bbe\u7f6e\u9501\u7684\u6709\u6548\u671f 5 \u79d2&#xff0c;\u9632\u6b62\u6b7b\u9501\u3002<\/li>\n<li>\u5f53\u65b9\u6cd5\u6267\u884c\u5b8c\u6bd5\u6216\u5f02\u5e38\u65f6&#xff0c;\u9501\u81ea\u52a8\u91ca\u653e&#xff08;\u901a\u8fc7 AOP \u5207\u9762&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u5982\u679c\u672a\u5f15\u5165 hyperf\/redis-lock \u7684\u81ea\u52a8\u914d\u7f6e&#xff0c;\u53ef\u80fd\u9700\u8981\u6ce8\u518c\u5207\u9762&#xff0c;\u4f46\u8be5\u7ec4\u4ef6\u5df2\u81ea\u52a8\u5b8c\u6210\u3002<\/p>\n<h5>\u6b65\u9aa4 3&#xff1a;\u6d4b\u8bd5\u9501\u6548\u679c<\/h5>\n<p>\u521d\u59cb\u5316\u5e93\u5b58&#xff1a;<\/p>\n<p><span class=\"token keyword\">UPDATE<\/span> products <span class=\"token keyword\">SET<\/span> total_stock <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">100<\/span> <span class=\"token keyword\">WHERE<\/span> id <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u4f7f\u7528 ab \u6216 wrk \u5e76\u53d1\u6d4b\u8bd5&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u65e0\u9501\u7248\u672c&#xff08;\u6ce8\u91ca\u6389 RedisLock \u6ce8\u89e3&#xff09;<\/span><br \/>\nwrk <span class=\"token parameter variable\">-t4<\/span> <span class=\"token parameter variable\">-c100<\/span> <span class=\"token parameter variable\">-d5s<\/span> <span class=\"token parameter variable\">&#8211;latency<\/span> <span class=\"token parameter variable\">-s<\/span> post.lua http:\/\/localhost:9501\/seckill\/buy<br \/>\n<span class=\"token comment\"># post.lua \u53ef\u6784\u9020 POST \u8bf7\u6c42&#xff0c;\u6216\u7528 ab -n 500 -c 50 -p data.txt &#8230;<\/span><\/p>\n<p>\u89c2\u5bdf\u6700\u7ec8\u5e93\u5b58&#xff1a;SELECT total_stock FROM products WHERE id&#061;1; \u65e0\u9501\u7248\u672c\u4f1a\u5c0f\u4e8e 0 \u6216\u8fdc\u5c0f\u4e8e\u9884\u671f\u3002\u52a0\u9501\u7248\u672c\u5e93\u5b58\u7cbe\u786e\u5f52\u96f6\u3002<\/p>\n<p>Redis \u76d1\u63a7&#xff1a;<br \/>\n\u5728\u538b\u6d4b\u671f\u95f4&#xff0c;\u4f7f\u7528 redis-cli monitor \u6216 keys *lock* \u89c2\u5bdf\u9501\u7684\u521b\u5efa\u548c\u5220\u9664\u3002<\/p>\n<h5>\u6b65\u9aa4 4&#xff1a;\u9501\u7eed\u671f\u4e0e\u53ef\u91cd\u5165<\/h5>\n<p>RedisLock \u652f\u6301 watchDog \u53c2\u6570&#xff0c;\u5f53\u4efb\u52a1\u6267\u884c\u65f6\u95f4\u53ef\u80fd\u8d85\u8fc7 ttl \u65f6&#xff0c;\u53ef\u4ee5\u5f00\u542f\u7eed\u671f\u3002\u4f46\u6ce8\u89e3\u6a21\u5f0f\u9ed8\u8ba4\u4e0d\u5f00\u542f&#xff0c;\u9700\u624b\u52a8\u521b\u5efa RedisLock \u5b9e\u4f8b\u3002<\/p>\n<p>\u793a\u4f8b\u624b\u52a8\u52a0\u9501&#xff08;\u6f14\u793a&#xff09;&#xff1a;<\/p>\n<p><span class=\"token variable\">$lock<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token variable\">$this<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token property\">redis<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">lock<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;lock:product:&#039;<\/span> <span class=\"token operator\">.<\/span> <span class=\"token variable\">$productId<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token variable\">$lock<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">try<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u4e1a\u52a1<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">finally<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token variable\">$lock<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">release<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>lock() \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u9501\u5bf9\u8c61&#xff0c;\u5185\u90e8\u5b9e\u73b0\u5305\u542b WatchDog\u3002<\/p>\n<p>\u53ef\u91cd\u5165\u6027&#xff1a;\u540c\u4e00\u534f\u7a0b\u518d\u6b21\u83b7\u53d6\u76f8\u540c\u9501\u65f6\u81ea\u52a8\u652f\u6301&#xff0c;\u4e0d\u4f1a\u6b7b\u9501\u3002<\/p>\n<h5>\u6b65\u9aa4 5&#xff1a;Redis \u7ea2\u9501&#xff08;RedLock&#xff09;\u914d\u7f6e&#xff08;\u6982\u5ff5\u4e0e\u5b9e\u73b0&#xff09;<\/h5>\n<p>\u5728\u591a\u4e2a Redis \u5b9e\u4f8b\u4e0a\u83b7\u53d6\u9501\u53ef\u4ee5\u63d0\u9ad8\u53ef\u9760\u6027\u3002hyperf\/redis-lock \u652f\u6301\u7ea2\u9501&#xff0c;\u9700\u8981\u5728 config\/autoload\/redis.php \u4e2d\u914d\u7f6e\u591a\u4e2a\u8fde\u63a5&#xff08;\u6216\u4f7f\u7528 Redis Cluster&#xff09;&#xff0c;\u7136\u540e\u901a\u8fc7 RedisLockFactory \u521b\u5efa\u3002<\/p>\n<p>\u7b80\u5355\u914d\u7f6e\u591a\u4e2a Redis \u5b9e\u4f8b&#xff08;\u5f00\u53d1\u73af\u5883\u53ef\u6a21\u62df\u4e0d\u540c\u7aef\u53e3&#xff09;&#xff0c;\u5728 redis.php \u4e2d\u6dfb\u52a0\u989d\u5916\u8fde\u63a5&#xff0c;\u7136\u540e\u4f7f\u7528&#xff1a;<\/p>\n<p><span class=\"token variable\">$factory<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token variable\">$this<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token property\">container<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name class-name-fully-qualified static-context\"><span class=\"token punctuation\">\\\\<\/span>Hyperf<span class=\"token punctuation\">\\\\<\/span>Redis<span class=\"token punctuation\">\\\\<\/span>Lock<span class=\"token punctuation\">\\\\<\/span>RedisLockFactory<\/span><span class=\"token operator\">::<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token variable\">$lock<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token variable\">$factory<\/span><span class=\"token operator\">-&gt;<\/span><span class=\"token function\">make<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">&#039;lock:redlock:product:1&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string single-quoted-string\">&#039;connection&#039;<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string single-quoted-string\">&#039;default&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string single-quoted-string\">&#039;redis2&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u7531\u4e8e\u6211\u4eec\u5f00\u53d1\u73af\u5883\u53ea\u6709\u4e00\u4e2a Redis&#xff0c;\u4eca\u5929\u91cd\u70b9\u662f\u7406\u89e3\u7ea2\u9501\u601d\u8def&#xff1a;\u5411 N \u4e2a\u72ec\u7acb Redis \u5b9e\u4f8b\u4f9d\u6b21\u83b7\u53d6\u9501&#xff0c;\u82e5\u6210\u529f\u6570 &gt;&#061; N\/2&#043;1&#xff0c;\u4e14\u603b\u8017\u65f6\u5c0f\u4e8e\u9501\u6709\u6548\u671f&#xff0c;\u5219\u83b7\u53d6\u6210\u529f\u3002<\/p>\n<hr \/>\n<h4>\u56db\u3001\u6210\u679c\u6d4b\u8bd5\u4e0e\u5e76\u53d1\u9a8c\u8bc1&#xff08;\u7ea6 1 \u5c0f\u65f6&#xff09;<\/h4>\n<h5>1. \u65e0\u9501\u8d85\u5356\u9a8c\u8bc1<\/h5>\n<ul>\n<li>\u8bbe\u7f6e\u5e93\u5b58 10\u3002<\/li>\n<li>\u53d1\u9001 100 \u5e76\u53d1\u8bf7\u6c42\u3002<\/li>\n<li>\u67e5\u8be2\u5e93\u5b58 total_stock&#xff0c;\u503c\u53ef\u80fd\u4e3a\u8d1f\u3002<\/li>\n<\/ul>\n<h5>2. \u52a0\u9501\u4e00\u81f4\u6027\u9a8c\u8bc1<\/h5>\n<ul>\n<li>\u91cd\u7f6e\u5e93\u5b58 10\u3002<\/li>\n<li>\u540c\u6837 100 \u5e76\u53d1\u8bf7\u6c42\u3002<\/li>\n<li>\u5e93\u5b58\u5f52\u96f6&#xff0c;\u8ba2\u5355\u8868\u4e2d\u6210\u529f\u8ba2\u5355\u6570\u7b49\u4e8e 10\u3002<\/li>\n<\/ul>\n<p>\u6027\u80fd\u5bf9\u6bd4&#xff1a;<br \/>\n\u52a0\u9501\u4f1a\u5f15\u5165\u5c11\u91cf\u5ef6\u8fdf&#xff08;Redis \u7f51\u7edc\u5f80\u8fd4&#xff09;&#xff0c;\u4f46\u4fdd\u8bc1\u4e86\u6570\u636e\u6b63\u786e\u6027\u3002\u8bb0\u5f55\u52a0\u9501\u524d\u540e\u7684 QPS \u548c P99 \u5ef6\u8fdf&#xff0c;\u5206\u6790\u53d6\u820d\u3002<\/p>\n<h5>3. \u9501\u8d85\u65f6\u6a21\u62df<\/h5>\n<p>\u5c06\u9501 TTL \u8bbe\u4e3a 2 \u79d2&#xff0c;\u5728\u4e1a\u52a1\u4ee3\u7801\u4e2d sleep(5)&#xff0c;\u89c2\u5bdf\u9501\u662f\u5426\u5728 2 \u79d2\u540e\u91ca\u653e&#xff0c;\u5176\u4ed6\u8bf7\u6c42\u662f\u5426\u80fd\u83b7\u53d6\u9501&#xff08;\u9020\u6210\u5e76\u53d1&#xff09;\u3002\u518d\u5f00\u542f WatchDog&#xff0c;\u9a8c\u8bc1\u9501\u662f\u5426\u88ab\u7eed\u671f\u76f4\u5230\u4efb\u52a1\u7ed3\u675f\u3002<\/p>\n<h5>4. \u6d4b\u8bd5\u6e05\u5355<\/h5>\n<table>\n<tr>\u68c0\u9a8c\u9879\u65b9\u6cd5\u901a\u8fc7\u6807\u51c6<\/tr>\n<tbody>\n<tr>\n<td>\u65e0\u9501\u8d85\u5356<\/td>\n<td>\u5e76\u53d1\u8bf7\u6c42\u65e0\u9501\u63a5\u53e3<\/td>\n<td>\u5e93\u5b58\u8d85\u5356&#xff0c;\u6700\u7ec8 total_stock &lt; 0<\/td>\n<\/tr>\n<tr>\n<td>\u6ce8\u89e3\u52a0\u9501\u9632\u8d85\u5356<\/td>\n<td>\u5e76\u53d1\u8bf7\u6c42\u52a0\u9501\u63a5\u53e3<\/td>\n<td>\u5e93\u5b58\u6263\u51cf\u81f3 0&#xff0c;\u65e0\u8d85\u5356<\/td>\n<\/tr>\n<tr>\n<td>\u9501\u81ea\u52a8\u91ca\u653e<\/td>\n<td>\u65b9\u6cd5\u6b63\u5e38\u7ed3\u675f\u6216\u5f02\u5e38&#xff0c;Redis \u4e2d\u9501\u6d88\u5931<\/td>\n<td>keys \u4e0d\u518d\u5305\u542b\u9501\u952e<\/td>\n<\/tr>\n<tr>\n<td>\u9501\u91cd\u5165<\/td>\n<td>\u540c\u4e00\u65b9\u6cd5\u5185\u518d\u6b21\u83b7\u53d6\u540c\u4e00\u9501<\/td>\n<td>\u4e0d\u963b\u585e<\/td>\n<\/tr>\n<tr>\n<td>\u7ea2\u9501\u914d\u7f6e<\/td>\n<td>\u4f7f\u7528\u591a\u4e2a Redis \u8fde\u63a5<\/td>\n<td>\u5f53\u90e8\u5206 Redis \u6545\u969c\u65f6\u9501\u4ecd\u53ef\u7528&#xff08;\u9700\u591a\u5b9e\u4f8b&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u6b7b\u9501\u9884\u9632<\/td>\n<td>\u6740\u6b7b\u6301\u9501\u8fdb\u7a0b&#xff0c;\u7b49\u5f85 TTL \u540e\u9501\u91ca\u653e<\/td>\n<td>\u9501\u8fc7\u671f\u81ea\u52a8\u5220\u9664<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h4>\u4e94\u3001\u4eca\u65e5\u4f5c\u4e1a\u4e0e\u5b66\u4e60\u4ea7\u51fa<\/h4>\n<li>\u63d0\u4ea4\u4ee3\u7801&#xff1a;\u5c06\u79d2\u6740\u63a5\u53e3\u3001\u9501\u6ce8\u89e3\u7528\u6cd5\u3001Redis \u9501\u914d\u7f6e\u63d0\u4ea4\u5230 Git\u3002<\/li>\n<li>\u5b8c\u5584\u79d2\u6740\u573a\u666f&#xff1a;\n<ul>\n<li>\u5c06\u79d2\u6740\u4e0e Saga \u51bb\u7ed3\u5e93\u5b58\u903b\u8f91\u7ed3\u5408&#xff1a;\u4e0b\u5355\u65f6\u7528\u9501\u4fdd\u62a4\u51bb\u7ed3\u5e93\u5b58\u64cd\u4f5c&#xff0c;\u907f\u514d\u8d85\u5356\u3002<\/li>\n<li>\u7f16\u5199\u4e00\u4e2a\u9501\u76d1\u63a7\u547d\u4ee4&#xff0c;\u7528\u4e8e\u67e5\u770b\u5f53\u524d\u6240\u6709\u6d3b\u8dc3\u9501\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u5b66\u4e60\u7b14\u8bb0&#xff1a;\n<ul>\n<li>\u753b\u51fa Redis \u5206\u5e03\u5f0f\u9501\u7684\u72b6\u6001\u8f6c\u6362\u56fe&#xff08;\u83b7\u53d6\u3001\u7eed\u671f\u3001\u91ca\u653e\u3001\u8fc7\u671f&#xff09;\u3002<\/li>\n<li>\u5bf9\u6bd4 Redis \u9501\u4e0e ZooKeeper \u9501\u7684\u5b9e\u73b0\u590d\u6742\u5ea6\u53ca\u9002\u7528\u573a\u666f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u6311\u6218\u4efb\u52a1&#xff1a;\n<ul>\n<li>\u5b9e\u73b0 \u57fa\u4e8e Lua \u811a\u672c\u7684\u539f\u5b50\u5e93\u5b58\u6263\u51cf&#xff08;\u4e0d\u4f9d\u8d56\u9501&#xff09;&#xff0c;\u6bd4\u8f83\u6027\u80fd\u3002<\/li>\n<li>\u7814\u7a76 Swoole\\\\Lock \u6216 etcd \u5b9e\u73b0\u7684\u5206\u5e03\u5f0f\u9501&#xff0c;\u4e0e Redis \u9501\u8fdb\u884c\u538b\u529b\u6d4b\u8bd5\u5bf9\u6bd4\u3002<\/li>\n<\/ul>\n<\/li>\n<p>\u901a\u8fc7\u4eca\u5929\u7684\u5b66\u4e60&#xff0c;\u4f60\u5df2\u7ecf\u638c\u63e1\u4e86\u9ad8\u5e76\u53d1\u4e0b\u4fdd\u8bc1\u6570\u636e\u4e00\u81f4\u6027\u7684\u5173\u952e\u6b66\u5668\u2014\u2014\u5206\u5e03\u5f0f\u9501\u3002\u73b0\u5728\u4f60\u7684 Saga \u6d41\u7a0b\u5373\u4f7f\u5728\u79d2\u6740\u573a\u666f\u4e0b\u4e5f\u80fd\u5b89\u5168\u8fd0\u884c&#xff0c;\u4e0d\u4f1a\u51fa\u73b0\u8d85\u5356\u7b49\u6570\u636e\u5f02\u5e38\u3002\u660e\u5929\u6211\u4eec\u5c06\u7ed3\u5408\u5206\u5e03\u5f0f\u4f1a\u8bdd\u548c\u8de8\u670d\u52a1\u8ba4\u8bc1\u4f18\u5316&#xff0c;\u8ba9\u6574\u4e2a\u7cfb\u7edf\u7684\u5b89\u5168\u8ba4\u8bc1\u4f53\u7cfb\u66f4\u52a0\u6210\u719f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3010\u57fa\u4e8e SwooleHyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011\u7b2c\u516b\u5468\u00b7\u5468\u56db&#xff1a;\u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236\u4eca\u5929\u6211\u4eec\u8fdb\u5165\u7b2c\u516b\u5468\u5468\u56db&#xff0c;\u4e3b\u9898\u662f \u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236\u3002\u6628\u5929\u6211\u4eec\u7684 Saga \u534f\u8c03\u5668\u5df2\u7ecf\u80fd\u591f\u4fdd\u8bc1\u5206\u5e03\u5f0f\u4e8b\u52a1\u7684\u6700\u7ec8\u4e00\u81f4\u6027&#xff0c;\u4f46\u5728\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b&#xff08;\u5982\u79d2\u6740&#xff09;&#xff0c;\u5355\u7eaf\u7684\u6570\u636e\u5e93\u884c\u9501\u53ef\u80fd\u6210\u4e3a\u74f6\u9888&#xff0c;\u5e76\u4e14\u5fae\u670d\u52a1\u67b6\u6784\u4e2d\u670d\u52a1\u95f4\u7ade\u4e89\u8d44\u6e90\u9700\u8981\u66f4\u901a\u7528\u7684\u9501\u673a\u5236\u3002\u4eca\u5929\u6211\u4eec\u5c06\u5f15\u5165 Redis \u5206\u5e03\u5f0f\u9501&#xff0c;\u901a\u8fc7 hyperf\/red<\/p>\n","protected":false},"author":2,"featured_media":111458,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2140,664,1348],"topic":[],"class_list":["post-111459","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-swoole","tag-664","tag-1348"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011\u7b2c\u516b\u5468\u00b7\u5468\u56db\uff1a\u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/111459.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011\u7b2c\u516b\u5468\u00b7\u5468\u56db\uff1a\u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u3010\u57fa\u4e8e SwooleHyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011\u7b2c\u516b\u5468\u00b7\u5468\u56db&#xff1a;\u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236\u4eca\u5929\u6211\u4eec\u8fdb\u5165\u7b2c\u516b\u5468\u5468\u56db&#xff0c;\u4e3b\u9898\u662f \u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236\u3002\u6628\u5929\u6211\u4eec\u7684 Saga \u534f\u8c03\u5668\u5df2\u7ecf\u80fd\u591f\u4fdd\u8bc1\u5206\u5e03\u5f0f\u4e8b\u52a1\u7684\u6700\u7ec8\u4e00\u81f4\u6027&#xff0c;\u4f46\u5728\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b&#xff08;\u5982\u79d2\u6740&#xff09;&#xff0c;\u5355\u7eaf\u7684\u6570\u636e\u5e93\u884c\u9501\u53ef\u80fd\u6210\u4e3a\u74f6\u9888&#xff0c;\u5e76\u4e14\u5fae\u670d\u52a1\u67b6\u6784\u4e2d\u670d\u52a1\u95f4\u7ade\u4e89\u8d44\u6e90\u9700\u8981\u66f4\u901a\u7528\u7684\u9501\u673a\u5236\u3002\u4eca\u5929\u6211\u4eec\u5c06\u5f15\u5165 Redis \u5206\u5e03\u5f0f\u9501&#xff0c;\u901a\u8fc7 hyperf\/red\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/111459.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-01T00:57:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001005702-6abdafde69fe6.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/111459.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/111459.html\",\"name\":\"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011\u7b2c\u516b\u5468\u00b7\u5468\u56db\uff1a\u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-01T00:57:09+00:00\",\"dateModified\":\"2026-10-01T00:57:09+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/111459.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/111459.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/111459.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011\u7b2c\u516b\u5468\u00b7\u5468\u56db\uff1a\u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011\u7b2c\u516b\u5468\u00b7\u5468\u56db\uff1a\u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/111459.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011\u7b2c\u516b\u5468\u00b7\u5468\u56db\uff1a\u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u3010\u57fa\u4e8e SwooleHyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011\u7b2c\u516b\u5468\u00b7\u5468\u56db&#xff1a;\u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236\u4eca\u5929\u6211\u4eec\u8fdb\u5165\u7b2c\u516b\u5468\u5468\u56db&#xff0c;\u4e3b\u9898\u662f \u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236\u3002\u6628\u5929\u6211\u4eec\u7684 Saga \u534f\u8c03\u5668\u5df2\u7ecf\u80fd\u591f\u4fdd\u8bc1\u5206\u5e03\u5f0f\u4e8b\u52a1\u7684\u6700\u7ec8\u4e00\u81f4\u6027&#xff0c;\u4f46\u5728\u9ad8\u5e76\u53d1\u573a\u666f\u4e0b&#xff08;\u5982\u79d2\u6740&#xff09;&#xff0c;\u5355\u7eaf\u7684\u6570\u636e\u5e93\u884c\u9501\u53ef\u80fd\u6210\u4e3a\u74f6\u9888&#xff0c;\u5e76\u4e14\u5fae\u670d\u52a1\u67b6\u6784\u4e2d\u670d\u52a1\u95f4\u7ade\u4e89\u8d44\u6e90\u9700\u8981\u66f4\u901a\u7528\u7684\u9501\u673a\u5236\u3002\u4eca\u5929\u6211\u4eec\u5c06\u5f15\u5165 Redis \u5206\u5e03\u5f0f\u9501&#xff0c;\u901a\u8fc7 hyperf\/red","og_url":"https:\/\/www.wsisp.com\/helps\/111459.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-01T00:57:09+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261001005702-6abdafde69fe6.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/111459.html","url":"https:\/\/www.wsisp.com\/helps\/111459.html","name":"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011\u7b2c\u516b\u5468\u00b7\u5468\u56db\uff1a\u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-01T00:57:09+00:00","dateModified":"2026-10-01T00:57:09+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/111459.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/111459.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/111459.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010\u57fa\u4e8e Swoole+Hyperf \u7684\u5fae\u670d\u52a1\u5b9e\u6218\u3011\u7b2c\u516b\u5468\u00b7\u5468\u56db\uff1a\u5206\u5e03\u5f0f\u9501\u4e0e\u5e76\u53d1\u63a7\u5236"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/111459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=111459"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/111459\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/111458"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=111459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=111459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=111459"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=111459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}