\u5b9e\u73b0 2<\/strong><\/div>\n\u603b\u7ed3\u4e86\u5c0f A \u5931\u8d25\u7684\u6559\u8bad\uff0c\u5c0f B \u5f00\u59cb\u5bf9 SQL \u8fdb\u884c\u4e86\u4f18\u5316\uff0c\u5148\u662f\u901a\u8fc7\u4e86 explain \u5173\u952e\u5b57\u8fdb\u884c SQL \u6027\u80fd\u5206\u6790\uff0c\u5bf9\u8be5\u52a0\u7d22\u5f15\u7684\u5730\u65b9\u90fd\u52a0\u4e0a\u4e86\u7d22\u5f15\u3002<\/p>\n
\u540c\u65f6\u5c06\u4e00\u6761\u590d\u6742 SQL \u62c6\u5206\u6210\u4e86\u591a\u6761 SQL\uff0c\u8ba1\u7b97\u7ed3\u679c\u5728\u7a0b\u5e8f\u5185\u5b58\u4e2d\u8fdb\u884c\u8ba1\u7b97\u3002<\/p>\n
\u4f2a\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n
\r\n$result_1 = query('select ... from table_1 where ...'); \r\n$result_2 = query('select ... from table_2 where ...'); \r\n$result_3 = query('select ... from table_3 where ...'); \r\n... \r\n \r\n$result = array_intersect($result_1, $result_2, $result_3, ...); \r\n<\/pre>\n\u8fd9\u79cd\u65b9\u6848\u4ece\u6027\u80fd\u4e0a\u660e\u663e\u6bd4\u7b2c\u4e00\u79cd\u8981\u597d\u5f88\u591a\uff0c\u53ef\u662f\u5728\u529f\u80fd\u9a8c\u6536\u7684\u65f6\u5019\uff0c\u4ea7\u54c1\u7ecf\u7406\u8fd8\u662f\u89c9\u5f97\u67e5\u8be2\u901f\u5ea6\u4e0d\u591f\u5feb\u3002<\/p>\n
\u5c0f B \u81ea\u5df1\u4e5f\u77e5\u9053\uff0c\u6bcf\u6b21\u67e5\u8be2\u90fd\u4f1a\u5411\u6570\u636e\u5e93\u67e5\u8be2\u591a\u6b21\uff0c\u800c\u4e14\u6709\u4e9b\u5386\u53f2\u539f\u56e0\uff0c\u90e8\u5206\u6761\u4ef6\u662f\u505a\u4e0d\u5230\u5355\u8868\u67e5\u8be2\u7684\uff0c\u6240\u4ee5\u67e5\u8be2\u7b49\u5f85\u7684\u65f6\u95f4\u662f\u907f\u514d\u4e0d\u4e86\u7684\u3002<\/p>\n
\u5b9e\u73b0 3<\/strong><\/div>\n\u5c0f C \u4ece\u4e0a\u9762\u7684\u65b9\u6848\u4e2d\u770b\u5230\u4e86\u4f18\u5316\u7684\u7a7a\u95f4\u3002\u4ed6\u53d1\u73b0\u5c0f B \u5728\u601d\u8def\u4e0a\u662f\u6ca1\u95ee\u9898\u7684\uff0c\u5c06\u590d\u6742\u6761\u4ef6\u62c6\u5206\uff0c\u8ba1\u7b97\u5404\u4e2a\u5b50\u7ef4\u5ea6\u7684\u7ed3\u679c\u96c6\uff0c\u6700\u540e\u5c06\u6240\u6709\u7684\u5b50\u7ed3\u679c\u96c6\u8fdb\u884c\u4e00\u4e2a\u6c47\u603b\u5408\u5e76\uff0c\u5f97\u5230\u6700\u7ec8\u60f3\u8981\u7684\u7ed3\u679c\u3002<\/p>\n
\u4e8e\u662f\u4ed6\u7a81\u53d1\u5947\u60f3\uff0c\u80fd\u5426\u4e8b\u5148\u5c06\u5404\u4e2a\u5b50\u7ef4\u5ea6\u7684\u7ed3\u679c\u96c6\u7ed9\u7f13\u5b58\u8d77\u6765\uff0c\u8fd9\u8981\u67e5\u8be2\u7684\u65f6\u5019\u76f4\u63a5\u53bb\u53d6\u60f3\u8981\u7684\u5b50\u96c6\uff0c\u800c\u4e0d\u7528\u6bcf\u6b21\u53bb\u67e5\u5e93\u8ba1\u7b97\u3002<\/p>\n
\u8fd9\u91cc\u5c0f C \u91c7\u7528 Redis \u6765\u5b58\u50a8\u7f13\u5b58\u6570\u636e\uff0c\u7528\u5b83\u7684\u4e3b\u8981\u539f\u56e0\u662f\uff0c\u5b83\u63d0\u4f9b\u4e86\u591a\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u5e76\u4e14\u5728 Redis \u4e2d\u8fdb\u884c\u96c6\u5408\u7684\u4ea4\u5e76\u96c6\u64cd\u4f5c\u662f\u4e00\u4ef6\u5f88\u5bb9\u6613\u7684\u4e8b\u60c5\u3002<\/p>\n
\u5177\u4f53\u65b9\u6848\uff0c\u5982\u56fe\u6240\u793a\uff1a<\/p>\n
<\/p>\n
\u8fd9\u91cc\u6bcf\u4e2a\u6761\u4ef6\u90fd\u4e8b\u5148\u5c06\u8ba1\u7b97\u597d\u7684\u7ed3\u679c\u96c6 ID \u5b58\u5165\u5bf9\u5e94\u7684 Key \u4e2d\uff0c\u9009\u7528\u7684\u6570\u636e\u7ed3\u6784\u662f\u96c6\u5408(Set)\u3002<\/p>\n
\u67e5\u8be2\u64cd\u4f5c\u5305\u62ec\uff1a<\/p>\n
\u5b50\u7c7b\u5355\u9009\uff1a\u76f4\u63a5\u6839\u636e\u6761\u4ef6 Key\uff0c\u83b7\u53d6\u5bf9\u5e94\u7ed3\u679c\u96c6\u3002<\/li>\n\u5b50\u7c7b\u591a\u9009\uff1a\u6839\u636e\u591a\u4e2a\u6761\u4ef6 Key\uff0c\u8fdb\u884c\u5e76\u96c6\u64cd\u4f5c\uff0c\u83b7\u53d6\u5bf9\u5e94\u7ed3\u679c\u96c6\u3002<\/li>\n\u6700\u7ec8\u7ed3\u679c\uff1a\u5c06\u83b7\u53d6\u7684\u6240\u6709\u5b50\u7c7b\u7ed3\u679c\u96c6\u8fdb\u884c\u4ea4\u96c6\u64cd\u4f5c\uff0c\u5f97\u5230\u6700\u7ec8\u7ed3\u679c\u3002<\/li>\n\u8fd9\u5176\u5b9e\u5c31\u662f\u6240\u8c13\u7684\u53cd\u5411\u7d22\u5f15\u3002\u8fd9\u91cc\u4f1a\u53d1\u73b0\uff0c\u6f0f\u4e86\u4e00\u4e2a\u4ef7\u683c\u7684\u6761\u4ef6\u3002\u4ece\u9700\u6c42\u4e2d\u53ef\u77e5\uff0c\u4ef7\u683c\u6761\u4ef6\u662f\u4e2a\u533a\u95f4\uff0c\u5e76\u4e14\u662f\u65e0\u7a77\u4e3e\u7684\u3002<\/p>\n
\u6240\u4ee5\u4e0a\u8ff0\u7684\u8fd9\u79cd\u7a77\u4e3e\u6761\u4ef6\u7684 Key-Value \u65b9\u5f0f\u662f\u505a\u4e0d\u5230\u7684\u3002\u8fd9\u91cc\u6211\u4eec\u91c7\u7528 Redis \u7684\u53e6\u4e00\u79cd\u6570\u636e\u7ed3\u6784\u8fdb\u884c\u5b9e\u73b0\uff0c\u6709\u5e8f\u96c6\u5408(Sorted Set)\uff1a<\/p>\n
<\/p>\n
\u5c06\u6240\u6709\u5546\u54c1\u52a0\u5165 Key \u4e3a\u4ef7\u683c\u7684\u6709\u5e8f\u96c6\u5408\u4e2d\uff0c\u503c\u4e3a\u5546\u54c1 ID\uff0c\u6bcf\u4e2a\u503c\u5bf9\u5e94\u7684\u5206\u6570\u4e3a\u5546\u54c1\u4ef7\u683c\u7684\u6570\u503c\u3002<\/p>\n
\u8fd9\u6837\u5728 Redis \u7684\u6709\u5e8f\u96c6\u5408\u4e2d\u5c31\u53ef\u4ee5\u901a\u8fc7 ZRANGEBYSCORE \u547d\u4ee4\uff0c\u6839\u636e\u5206\u6570(\u4ef7\u683c)\u533a\u95f4\uff0c\u83b7\u53d6\u76f8\u5e94\u7ed3\u679c\u96c6\u3002<\/p>\n
\u81f3\u6b64\uff0c\u65b9\u6848\u4e09\u7684\u4f18\u5316\u5df2\u5168\u90e8\u7ed3\u675f\uff0c\u5c06\u6570\u636e\u7684\u67e5\u8be2\u4e0e\u8ba1\u7b97\u901a\u8fc7\u7f13\u5b58\u7684\u624b\u6bb5\uff0c\u8fdb\u884c\u4e86\u5206\u79bb\u3002<\/p>\n
\u5728\u6bcf\u6b21\u67e5\u627e\u65f6\uff0c\u53ea\u9700\u8981\u7b80\u5355\u7684\u67e5\u627e Redis \u51e0\u6b21\u5c31\u80fd\u5f97\u51fa\u7ed3\u679c\u3002\u67e5\u8be2\u901f\u5ea6\u4e0a\u7b26\u5408\u4e86\u9a8c\u6536\u7684\u8981\u6c42\u3002<\/p>\n
\u6269\u5c55<\/strong><\/div>\n\u2460\u5206\u9875<\/strong><\/span><\/div>\n\u8fd9\u91cc\u4f60\u6216\u8bb8\u53d1\u73b0\u4e86\u4e00\u4e2a\u4e25\u91cd\u7684\u529f\u80fd\u7f3a\u9677\uff0c\u5217\u8868\u67e5\u8be2\u600e\u4e48\u80fd\u6ca1\u6709\u5206\u9875\u3002\u662f\u7684\uff0c\u6211\u4eec\u9a6c\u4e0a\u6765\u770b Redis \u662f\u5982\u4f55\u5b9e\u73b0\u5206\u9875\u7684\u3002<\/p>\n
\u5206\u9875\u4e3b\u8981\u6d89\u53ca\u6392\u5e8f\uff0c\u8fd9\u91cc\u7b80\u5355\u8d77\u89c1\uff0c\u5c31\u4ee5\u521b\u5efa\u65f6\u95f4\u4e3a\u4f8b\u3002\u5982\u56fe\u6240\u793a\uff1a<\/p>\n
<\/p>\n
\u56fe\u4e2d\u84dd\u8272\u90e8\u5206\u662f\u4ee5\u521b\u5efa\u65f6\u95f4\u4e3a\u5206\u503c\u7684\u5546\u54c1\u6709\u5e8f\u96c6\u5408\uff0c\u84dd\u8272\u4e0b\u65b9\u7684\u7ed3\u679c\u96c6\u5373\u4e3a\u6761\u4ef6\u8ba1\u7b97\u800c\u5f97\u7684\u7ed3\u679c\uff0c\u901a\u8fc7 ZINTERSTORE \u547d\u4ee4\uff0c\u8d4b\u7ed3\u679c\u96c6\u6743\u91cd\u4e3a 0\uff0c\u5546\u54c1\u65f6\u95f4\u7ed3\u679c\u4e3a 1\uff0c\u53d6\u4ea4\u96c6\u800c\u5f97\u7684\u7ed3\u679c\u96c6\u8d4b\u4e88\u521b\u5efa\u65f6\u95f4\u5206\u503c\u7684\u65b0\u6709\u5e8f\u96c6\u5408\u3002<\/p>\n
\u5bf9\u65b0\u7ed3\u679c\u96c6\u7684\u64cd\u4f5c\u5373\u80fd\u5f97\u5230\u5206\u9875\u6240\u9700\u7684\u5404\u4e2a\u6570\u636e\uff1a<\/p>\n
\u9875\u9762\u603b\u6570\u4e3a\uff1aZCOUNT \u547d\u4ee4\u3002<\/li>\n\u5f53\u524d\u9875\u5185\u5bb9\uff1aZRANGE \u547d\u4ee4\u3002<\/li>\n\u82e5\u4ee5\u5012\u5e8f\u6392\u5217\uff1aZREVRANGE\u547d\u4ee4\u3002<\/li>\n\u2461\u6570\u636e\u66f4\u65b0<\/strong><\/span><\/div>\n\u5173\u4e8e\u7d22\u5f15\u6570\u636e\u66f4\u65b0\u7684\u95ee\u9898\uff0c\u6709\u4e24\u79cd\u65b9\u5f0f\u6765\u8fdb\u884c\u3002\u4e00\u79cd\u662f\u901a\u8fc7\u5546\u54c1\u6570\u636e\u7684\u4fee\u6539\uff0c\u6765\u5373\u65f6\u89e6\u53d1\u66f4\u65b0\u64cd\u4f5c\uff0c\u4e00\u79cd\u662f\u901a\u8fc7\u5b9a\u65f6\u811a\u672c\u6765\u8fdb\u884c\u6279\u91cf\u66f4\u65b0\u3002<\/p>\n
\u8fd9\u91cc\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5173\u4e8e\u7d22\u5f15\u5185\u5bb9\u7684\u66f4\u65b0\uff0c\u5982\u679c\u66b4\u529b\u7684\u5220\u9664 Key\uff0c\u518d\u91cd\u65b0\u8bbe\u7f6e Key\u3002<\/p>\n
\u56e0\u4e3a Redis \u4e2d\u4e24\u4e2a\u64cd\u4f5c\u4e0d\u4f1a\u662f\u539f\u5b50\u6027\u8fdb\u884c\u7684\uff0c\u6240\u4ee5\u4e2d\u95f4\u53ef\u80fd\u5b58\u5728\u7a7a\u767d\u95f4\u9699\uff0c\u5efa\u8bae\u91c7\u7528\u4ec5\u79fb\u9664\u96c6\u5408\u4e2d\u5931\u6548\u5143\u7d20\uff0c\u6dfb\u52a0\u65b0\u5143\u7d20\u7684\u65b9\u5f0f\u8fdb\u884c\u3002<\/p>\n
\u2462\u6027\u80fd\u4f18\u5316<\/strong><\/span><\/div>\nRedis \u662f\u5185\u5b58\u7ea7\u64cd\u4f5c\uff0c\u6240\u4ee5\u5355\u6b21\u7684\u67e5\u8be2\u4f1a\u5f88\u5feb\u3002\u4f46\u662f\u5982\u679c\u6211\u4eec\u7684\u5b9e\u73b0\u4e2d\u4f1a\u8fdb\u884c\u591a\u6b21\u7684 Redis \u64cd\u4f5c\uff0cRedis \u7684\u591a\u6b21\u8fde\u63a5\u65f6\u95f4\u53ef\u80fd\u662f\u4e0d\u5fc5\u8981\u65f6\u95f4\u6d88\u8017\u3002<\/p>\n
\u901a\u8fc7\u4f7f\u7528 MULTI \u547d\u4ee4\uff0c\u5f00\u542f\u4e00\u4e2a\u4e8b\u52a1\uff0c\u5c06 Redis \u7684\u591a\u6b21\u64cd\u4f5c\u653e\u5728\u4e00\u4e2a\u4e8b\u52a1\u4e2d\uff0c\u6700\u540e\u901a\u8fc7 EXEC \u6765\u8fdb\u884c\u539f\u5b50\u6027\u6267\u884c\u3002<\/p>\n
\u6ce8\u610f\uff1a\u8fd9\u91cc\u6240\u8c13\u7684\u4e8b\u52a1\uff0c\u53ea\u662f\u5c06\u591a\u4e2a\u64cd\u4f5c\u5728\u4e00\u6b21\u8fde\u63a5\u4e2d\u6267\u884c\uff0c\u5982\u679c\u6267\u884c\u8fc7\u7a0b\u4e2d\u9047\u5230\u5931\u8d25\uff0c\u662f\u4e0d\u4f1a\u56de\u6eda\u7684\u3002<\/p>\n
\u603b\u7ed3<\/strong><\/div>\n\u8fd9\u91cc\u53ea\u662f\u4e00\u4e2a\u91c7\u7528 Redis \u4f18\u5316\u67e5\u8be2\u641c\u7d22\u7684\u4e00\u4e2a\u7b80\u5355 Demo\uff0c\u548c\u73b0\u6709\u7684\u5f00\u6e90\u641c\u7d22\u5f15\u64ce\u76f8\u6bd4\uff0c\u5b83\u66f4\u8f7b\u91cf\uff0c\u5b66\u4e60\u6210\u672c\u9875\u76f8\u5e94\u4f4e\u4e9b\u3002<\/p>\n
\u5176\u6b21\uff0c\u5b83\u7684\u4e00\u4e9b\u601d\u60f3\u4e0e\u5f00\u6e90\u641c\u7d22\u5f15\u64ce\u662f\u7c7b\u4f3c\u7684\uff0c\u5982\u679c\u518d\u52a0\u4e0a\u8bcd\u8bed\u89e3\u6790\uff0c\u4e5f\u53ef\u4ee5\u5b9e\u73b0\u7c7b\u4f3c\u5168\u6587\u68c0\u7d22\u7684\u529f\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u4f46\u6709\u7684\u67e5\u8be2\u6761\u4ef6\u6781\u5176\u590d\u6742\uff0c\u518d\u52a0\u4e0a\u5e93\u8868\u4e2d\u8bbe\u8ba1\u7684\u5404\u79cd\u4e0d\u5408\u7406\uff0c\u5bfc\u81f4\u67e5\u8be2\u63a5\u53e3\u7279\u522b\u96be\u5199\uff0c\u7136\u540e\u52a0\u73ed\u4ec0\u4e48\u7684\u5c31\u4e0d\u7528\u8bf4\u4e86(\u4e0d\u77e5\u5404\u4f4d […]<\/p>\n","protected":false},"author":1479,"featured_media":7058,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-209834","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/209834","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=209834"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/209834\/revisions"}],"predecessor-version":[{"id":210269,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/209834\/revisions\/210269"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/7058"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=209834"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=209834"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=209834"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}