{"id":15412,"date":"2024-11-17T20:58:54","date_gmt":"2024-11-17T12:58:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/?p=15412"},"modified":"2024-11-17T20:58:54","modified_gmt":"2024-11-17T12:58:54","slug":"openresty%e5%ad%a6%e4%b9%a0%e4%b8%ad%e7%9a%84%e7%9f%a5%e8%af%86%e7%82%b9%ef%bc%88%e4%b8%80%ef%bc%89","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/15412\/","title":{"rendered":"openResty\u5b66\u4e60\u4e2d\u7684\u77e5\u8bc6\u70b9\uff08\u4e00\uff09"},"content":{"rendered":"<p>1\u3001\u53d8\u91cf\u7533\u660e\u540e\uff0c\u9ed8\u8ba4\u7684\u503c\u662fnil\uff1b\u5c06 nil \u8d4b\u7ed9\u53d8\u91cf\u540e\uff0c\u76f8\u5f53\u4e8e\u5220\u9664\u53d8\u91cf\u3002\u6ce8\u610fnil \u548c ngx.null\u7684\u533a\u522b\u3002<\/p>\n<p>2\u3001\u5728 lua\u4e2d\u53ea\u6709 false\u548c nil \u503c\u4e3a false ,\u5176\u4ed6\u503c\u90fd\u4e3a true \uff0c\u5305\u62ec0,\u201d\u201d\u7b49<\/p>\n<p>3\u3001lua\u4e2d\u7684\u6570\u5b57\uff08\u4e00\u5207\u6570\u5b57\uff09\u90fd\u662f number\u7c7b\u578b\u3002<\/p>\n<p>4\u3001table \u7684\u4e0b\u6807\u4ece 1 \u5f00\u59cb\u3002<\/p>\n<p>5\u3001\u903b\u8f91\u8fd0\u7b97\u6cd5 and \u3001or \u3001not\u7684\u7528\u6cd5\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>6 \u3001\u5b57\u7b26\u4e32\u7684\u8fde\u63a5\u53ef\u4f7f\u7528string.format \uff0c\u6216\u8005 table.concat\uff0c\u666e\u901a..\u8fde\u63a5\u6d88\u8017\u6027\u80fd\u6bd4\u8f83\u5927\uff08\u6bcf\u6b21\u8fde\u63a5\u751f\u6210\u65b0\u7684\u66f4\u5927\u5b57\u7b26\u4e32\uff09<\/p>\n<p>7\u3001lua\u4e2d\u6ca1\u6709 switch \u7684\u8bed\u6cd5\uff0c\u4f46\u53ef\u4f7f\u7528 table \u5b9e\u73b0\u3002<\/p>\n<p>8\u3001lua\u5faa\u73af\u8bed\u6cd5\u4e2d\u6ca1\u6709continue\uff0c\u4f46\u6709break<\/p>\n<p>9\u3001return\u53ea\u80fd\u51fa\u73b0\u5728\u8bed\u53e5\u5757\u7684\u6700\u540e\u3002\u6216\u8005\u4f7f\u7528 do return end<\/p>\n<p><strong>10\u3001\u5143\u8868\uff3b\u91cd\u70b9\uff3d<\/strong><\/p>\n<p><strong>11\u3001\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff3b\u91cd\u70b9\uff3d<\/strong><\/p>\n<p>12\u3001\u5c40\u90e8\u53d8\u91cf\uff1aLua \u7684\u8bbe\u8ba1\u6709\u4e00\u70b9\u5f88\u5947\u602a\uff0c\u5728\u4e00\u4e2ablock \u4e2d\u7684\u53d8\u91cf\uff0c\u5982\u679c\u4e4b\u524d\u6ca1\u6709\u5b9a\u4e49\u8fc7\uff0c\u90a3\u4e48\u8ba4\u4e3a\u5b83\u662f\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\uff0c\u800c\u4e0d\u662f\u8fd9\u4e2ablock \u7684\u5c40\u90e8\u53d8\u91cf\u3002\u8fd9\u4e00\u70b9\u548c\u522b\u7684\u8bed\u8a00\u4e0d\u540c\u3002\u5bb9\u6613\u9020\u6210\u4e0d\u5c0f\u5fc3\u8986\u76d6\u4e86\u5168\u5c40\u540c\u540d\u53d8\u91cf\u7684\u9519\u8bef\u3002<\/p>\n<p><strong>13\u3001\u517b\u6210\u5b9a\u4e49\u5c40\u90e8\u53d8\u91cf\u7684\u4e60\u60ef\uff08local\uff09<\/strong><\/p>\n<p><strong>14\u3001Lua \u5185\u90e8\u5b9e\u9645\u91c7\u7528\u54c8\u5e0c\u8868\u548c\u6570\u7ec4\uff0c\u5206\u522b\u4fdd\u5b58\u952e\u503c\u5bf9\u3001\u666e\u901a\u503c\uff0c\u6240\u4ee5\u4e0d\u63a8\u8350\u6df7\u5408\u4f7f\u7528\u8fd9\u4e24\u79cd\u8d4b\u503c\u65b9\u5f0f\u3002<\/strong><\/p>\n<p><strong>15\u3001\u6570\u7ec4\u4e2d\u4e0d\u8981\u4f7f\u7528 nil,\u5982\u679c\u5220\u9664\u6570\u7ec4\u67d0\u4e00key\u91c7\u7528 table.remove<\/strong><\/p>\n<p>16\u3001\u8c03\u7528\u4ee3\u7801\u524d\u5148\u5b9a\u4e49\u51fd\u6570<\/p>\n<p>17\u3001Lua module \u53ea\u4f1a\u5728\u7b2c\u4e00\u6b21\u8bf7\u6c42\u65f6\u52a0\u8f7d\u4e00\u6b21\uff08\u9664\u975e\u663e\u5f0f\u7981\u7528\u4e86 lua_code_cache \u914d\u7f6e\u6307\u4ee4\uff09<\/p>\n<p>18\u3001\u70b9\u53f7\u4e0e\u5192\u53f7\u64cd\u4f5c\u7b26\u7684\u533a\u522b<\/p>\n<h3><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u53d8\u91cf\u7533\u660e\u540e\uff0c\u9ed8\u8ba4\u7684\u503c\u662fnil\uff1b\u5c06 nil \u8d4b\u7ed9\u53d8\u91cf\u540e\uff0c\u76f8\u5f53\u4e8e\u5220\u9664\u53d8\u91cf\u3002\u6ce8\u610fnil \u548c ngx.null\u7684\u533a\u522b\u3002 2\u3001\u5728 lua\u4e2d\u53ea\u6709 false\u548c nil \u503c\u4e3a false ,\u5176\u4ed6\u503c\u90fd\u4e3a true \uff0c\u5305\u62ec0,\u201d\u201d\u7b49 3\u3001lua\u4e2d\u7684\u6570\u5b57\uff08\u4e00\u5207\u6570\u5b57\uff09\u90fd\u662f number\u7c7b\u578b\u3002 4\u3001table \u7684\u4e0b\u6807\u4ece 1 \u5f00\u59cb\u3002 5\u3001\u903b\u8f91\u8fd0\u7b97\u6cd5 and \u3001or \u3001not\u7684\u7528\u6cd5\u3002 &nbsp; 6 \u3001\u5b57\u7b26\u4e32\u7684\u8fde\u63a5\u53ef\u4f7f\u7528string.format \uff0c\u6216\u8005 table.concat\uff0c\u666e\u901a..\u8fde\u63a5\u6d88\u8017\u6027\u80fd\u6bd4\u8f83\u5927\uff08\u6bcf\u6b21\u8fde\u63a5\u751f\u6210\u65b0\u7684\u66f4\u5927\u5b57\u7b26\u4e32\uff09 7\u3001lua\u4e2d\u6ca1\u6709 switch \u7684\u8bed\u6cd5\uff0c\u4f46\u53ef\u4f7f\u7528 table \u5b9e\u73b0\u3002 8\u3001lua\u5faa\u73af\u8bed\u6cd5\u4e2d\u6ca1\u6709continue\uff0c\u4f46\u6709break 9\u3001return\u53ea\u80fd\u51fa\u73b0\u5728\u8bed\u53e5\u5757\u7684\u6700\u540e\u3002\u6216\u8005\u4f7f\u7528 do return end 10\u3001\u5143\u8868\uff3b\u91cd\u70b9\uff3d 11\u3001\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff3b\u91cd\u70b9\uff3d 12\u3001\u5c40\u90e8\u53d8\u91cf\uff1aLua \u7684\u8bbe\u8ba1\u6709\u4e00\u70b9\u5f88\u5947\u602a\uff0c\u5728\u4e00\u4e2ablock \u4e2d\u7684\u53d8\u91cf\uff0c\u5982\u679c\u4e4b\u524d\u6ca1\u6709\u5b9a\u4e49\u8fc7\uff0c\u90a3\u4e48\u8ba4\u4e3a\u5b83\u662f\u4e00\u4e2a\u5168\u5c40\u53d8\u91cf\uff0c\u800c\u4e0d\u662f\u8fd9\u4e2ablock \u7684\u5c40\u90e8\u53d8\u91cf\u3002\u8fd9\u4e00\u70b9\u548c\u522b\u7684\u8bed\u8a00\u4e0d\u540c\u3002\u5bb9\u6613\u9020\u6210\u4e0d\u5c0f\u5fc3\u8986\u76d6\u4e86\u5168\u5c40\u540c\u540d\u53d8\u91cf\u7684\u9519\u8bef\u3002 13\u3001\u517b\u6210\u5b9a\u4e49\u5c40\u90e8\u53d8\u91cf\u7684\u4e60\u60ef\uff08local\uff09 14\u3001Lua \u5185\u90e8\u5b9e\u9645\u91c7\u7528\u54c8\u5e0c\u8868\u548c\u6570\u7ec4\uff0c\u5206\u522b\u4fdd\u5b58\u952e\u503c\u5bf9\u3001\u666e\u901a\u503c\uff0c\u6240\u4ee5\u4e0d\u63a8\u8350\u6df7\u5408\u4f7f\u7528\u8fd9\u4e24\u79cd\u8d4b\u503c\u65b9\u5f0f\u3002 15\u3001\u6570\u7ec4\u4e2d\u4e0d\u8981\u4f7f\u7528 nil,\u5982\u679c\u5220\u9664\u6570\u7ec4\u67d0\u4e00key\u91c7\u7528 table.remove 16\u3001\u8c03\u7528\u4ee3\u7801\u524d\u5148\u5b9a\u4e49\u51fd\u6570 17\u3001Lua module \u53ea\u4f1a\u5728\u7b2c\u4e00\u6b21\u8bf7\u6c42\u65f6\u52a0\u8f7d\u4e00\u6b21\uff08\u9664\u975e\u663e\u5f0f\u7981\u7528\u4e86 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-15412","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=15412"}],"version-history":[{"count":1,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15412\/revisions"}],"predecessor-version":[{"id":15413,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15412\/revisions\/15413"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=15412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=15412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=15412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}