{"id":45689,"date":"2024-12-01T14:33:07","date_gmt":"2024-12-01T06:33:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/45689\/"},"modified":"2024-12-01T14:33:07","modified_gmt":"2024-12-01T06:33:07","slug":"%e6%80%8e%e4%b9%88%e7%94%a8phpredis%e5%ae%9e%e7%8e%b0%e4%b9%90%e8%a7%82%e9%94%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/45689\/","title":{"rendered":"\u600e\u4e48\u7528php+redis\u5b9e\u73b0\u4e50\u89c2\u9501"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u600e\u4e48\u7528php+redis\u5b9e\u73b0\u4e50\u89c2\u9501<\/h1>\n<p><span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u600e\u4e48\u7528php+redis\u5b9e\u73b0\u4e50\u89c2\u9501\u300b<\/span>\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6570\u636e\u5e93<\/span>\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6570\u636e\u5e93<\/span>\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01<\/p>\n<p>header(\u201ccontent-type:text\/html;charset=utf-8\u201d);<br \/>$redis = new redis();<br \/>$result = $redis-&gt;connect(\u2018127.0.0.1\u2019, 6379);<br \/>$mywatchkey = $redis-&gt;get(\u201c\u201d);<br \/>$rob_total = 10;<br \/>\/\/\u62a2\u8d2d\u6570\u91cf<br \/>if($mywatchkey&lt;$rob_total) {<br \/>$redis-&gt;watch(\u201cmywatchkey\u201d);<br \/>$redis-&gt;multi();<br \/>\/\/\u8bbe\u7f6e\u5ef6\u8fdf\uff0c\u65b9\u4fbf\u6d4b\u8bd5\u6548\u679c\u3002<br \/>sleep(5);<br \/>\/\/\u63d2\u5165\u62a2\u8d2d\u6570\u636e<br \/>$redis-&gt;hSet(\u201cmywatchlist\u201c,\u201duser_id_\u201d.mt_rand(1, 9999),time());<br \/>$redis-&gt;set(\u201cmywatchkey\u201d,$mywatchkey+1);<br \/>$rob_result = $redis-&gt;exec();<br \/>if($rob_result) {<br \/>$mywatchlist = $redis-&gt;hGetAll(\u201cmywatchlist\u201c);<br \/>echo \u201c\u62a2\u8d2d\u6210\u529f\uff01\u201d;<br \/>echo \u201c\u5269\u4f59\u6570\u91cf\uff1a\u201d.($rob_total-$mywatchkey-1).\u201d\u201d;<br \/>echo \u201c\u7528\u6237\u5217\u8868\uff1a\u201d;<br \/>var_dump($mywatchlist);<br \/>} else {<br \/>echo \u201c\u624b\u6c14\u4e0d\u597d\uff0c\u518d\u62a2\u8d2d\uff01\u201d;<br \/>exit;<br \/>}<br \/>}<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u600e\u4e48\u7528php+redis\u5b9e\u73b0\u4e50\u89c2\u9501\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8golang\u5b66\u4e60\u7f51\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6570\u636e\u5e93\u77e5\u8bc6\uff01<\/p>\n<p>   \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1a\u4ebf\u901f\u4e91 \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664  <\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   JDBC \u8bed\u53e5\u63a5\u53e3\u7684 setFetchSize() \u548c setMaxRows() \u65b9\u6cd5\u6709\u4ec0\u4e48\u7528\uff1f\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u5982\u4f55\u5728MySQL\u4e2d\u4f7f\u7528select\u8bed\u53e5\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u600e\u4e48\u7528php+redis\u5b9e\u73b0\u4e50\u89c2\u9501 0\u6d4f\u89c8 \u6536\u85cf \u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86\u300a\u600e\u4e48\u7528php+redis\u5b9e\u73b0\u4e50\u89c2\u9501\u300b\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9\u6570\u636e\u5e93\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60\u6570\u636e\u5e93\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01 header(\u201ccontent-type:text\/html;charset=utf-8\u201d);$redis = new redis();$result = $redis-&gt;connect(\u2018127.0.0.1\u2019, 6379);$mywatchkey = $redis-&gt;get(\u201c\u201d);$rob_total = 10;\/\/\u62a2\u8d2d\u6570\u91cfif($mywatchkey&lt;$rob_total) {$redis-&gt;watch(\u201cmywatchkey\u201d);$redis-&gt;multi();\/\/\u8bbe\u7f6e\u5ef6\u8fdf\uff0c\u65b9\u4fbf\u6d4b\u8bd5\u6548\u679c\u3002sleep(5);\/\/\u63d2\u5165\u62a2\u8d2d\u6570\u636e$redis-&gt;hSet(\u201cmywatchlist\u201c,\u201duser_id_\u201d.mt_rand(1, 9999),time());$redis-&gt;set(\u201cmywatchkey\u201d,$mywatchkey+1);$rob_result = $redis-&gt;exec();if($rob_result) {$mywatchlist = $redis-&gt;hGetAll(\u201cmywatchlist\u201c);echo \u201c\u62a2\u8d2d\u6210\u529f\uff01\u201d;echo \u201c\u5269\u4f59\u6570\u91cf\uff1a\u201d.($rob_total-$mywatchkey-1).\u201d\u201d;echo \u201c\u7528\u6237\u5217\u8868\uff1a\u201d;var_dump($mywatchlist);} else {echo \u201c\u624b\u6c14\u4e0d\u597d\uff0c\u518d\u62a2\u8d2d\uff01\u201d;exit;}} \u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u600e\u4e48\u7528php+redis\u5b9e\u73b0\u4e50\u89c2\u9501\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8golang\u5b66\u4e60\u7f51\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6570\u636e\u5e93\u77e5\u8bc6\uff01 \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1a\u4ebf\u901f\u4e91 \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664 JDBC \u8bed\u53e5\u63a5\u53e3\u7684 setFetchSize() \u548c setMaxRows() \u65b9\u6cd5\u6709\u4ec0\u4e48\u7528\uff1f \u5982\u4f55\u5728MySQL\u4e2d\u4f7f\u7528select\u8bed\u53e5\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff1f<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-45689","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/45689","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=45689"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/45689\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=45689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=45689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=45689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}