{"id":167771,"date":"2024-11-06T05:42:20","date_gmt":"2024-11-05T21:42:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/167771\/"},"modified":"2024-11-06T05:42:21","modified_gmt":"2024-11-05T21:42:21","slug":"%e5%88%a9%e7%94%a8redis%e7%aa%81%e7%a0%b4%e6%a5%b5%e9%99%90%ef%bc%8c%e8%bc%95%e9%ac%86%e8%a8%98%e9%8c%84%e7%99%be%e8%90%ac%e6%a2%9d%e6%95%b8%e6%93%9a%ef%bc%88redis%e8%a8%98%e9%8c%84%e7%99%be%e8%90%ac","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/167771\/","title":{"rendered":"\u5229\u7528Redis\u7a81\u7834\u6975\u9650\uff0c\u8f15\u9b06\u8a18\u9304\u767e\u842c\u689d\u6578\u64da\uff08redis\u8a18\u9304\u767e\u842c\u689d\u6578\u64da\uff09"},"content":{"rendered":"<h1 id=\"%e5%88%a9%e7%94%a8redis%e7%aa%81%e7%a0%b4%e6%a5%b5%e9%99%90%ef%bc%8c%e8%bc%95%e9%ac%86%e8%a8%98%e9%8c%84%e7%99%be%e8%90%ac%e6%a2%9d%e6%95%b8%e6%93%9a-wNyCUbyzwH\">\u5229\u7528Redis\u7a81\u7834\u6975\u9650\uff0c\u8f15\u9b06\u8a18\u9304\u767e\u842c\u689d\u6578\u64da<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u64da\u9a45\u52d5\u7684\u4e16\u754c\u4e2d\uff0c\u5982\u4f55\u9ad8\u6548\u5730\u5b58\u5132\u548c\u7ba1\u7406\u5927\u91cf\u6578\u64da\u6210\u70ba\u4e86\u4f01\u696d\u548c\u958b\u767c\u8005\u9762\u81e8\u7684\u4e00\u5927\u6311\u6230\u3002Redis\uff0c\u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6027\u80fd\u7684\u9375\u503c\u6578\u64da\u5eab\uff0c\u56e0\u5176\u5353\u8d8a\u7684\u6027\u80fd\u548c\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\uff0c\u6210\u70ba\u4e86\u8a31\u591a\u61c9\u7528\u7a0b\u5e8f\u7684\u9996\u9078\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5229\u7528Redis\u7a81\u7834\u6975\u9650\uff0c\u8f15\u9b06\u8a18\u9304\u767e\u842c\u689d\u6578\u64da\u3002<\/p>\n<h2 id=\"redis%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-wNyCUbyzwH\">Redis\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>Redis\uff08REmote DIctionary Server\uff09\u662f\u4e00\u500b\u958b\u6e90\u7684\u5167\u5b58\u6578\u64da\u7d50\u69cb\u5b58\u5132\u7cfb\u7d71\uff0c\u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff0c\u5982\u5b57\u7b26\u4e32\u3001\u54c8\u5e0c\u3001\u5217\u8868\u3001\u96c6\u5408\u548c\u6709\u5e8f\u96c6\u5408\u7b49\u3002\u7531\u65bc\u5176\u5728\u5167\u5b58\u4e2d\u64cd\u4f5c\u6578\u64da\uff0cRedis\u7684\u8b80\u53d6\u548c\u5beb\u5165\u901f\u5ea6\u6975\u5feb\uff0c\u9019\u4f7f\u5f97\u5b83\u975e\u5e38\u9069\u5408\u7528\u65bc\u9700\u8981\u9ad8\u6027\u80fd\u7684\u61c9\u7528\u5834\u666f\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bd%95%e9%81%b8%e6%93%87redis%e4%be%86%e8%a8%98%e9%8c%84%e5%a4%a7%e9%87%8f%e6%95%b8%e6%93%9a-wNyCUbyzwH\">\u70ba\u4f55\u9078\u64c7Redis\u4f86\u8a18\u9304\u5927\u91cf\u6578\u64da<\/h2>\n<ul>\n<li><strong>\u9ad8\u6027\u80fd\uff1a<\/strong>Redis\u7684\u6027\u80fd\u512a\u52e2\u4f7f\u5176\u80fd\u5920\u6bcf\u79d2\u8655\u7406\u6578\u5341\u842c\u6b21\u7684\u8acb\u6c42\uff0c\u9019\u5c0d\u65bc\u9700\u8981\u5feb\u901f\u97ff\u61c9\u7684\u61c9\u7528\u81f3\u95dc\u91cd\u8981\u3002<\/li>\n<li><strong>\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\uff1a<\/strong>Redis\u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u9078\u64c7\u6700\u5408\u9069\u7684\u6578\u64da\u985e\u578b\u4f86\u5b58\u5132\u6578\u64da\u3002<\/li>\n<li><strong>\u6301\u4e45\u5316\u9078\u9805\uff1a<\/strong>\u96d6\u7136Redis\u4e3b\u8981\u662f\u5167\u5b58\u6578\u64da\u5eab\uff0c\u4f46\u5b83\u63d0\u4f9b\u4e86\u591a\u7a2e\u6301\u4e45\u5316\u6a5f\u5236\uff0c\u5982RDB\u5feb\u7167\u548cAOF\u65e5\u8a8c\uff0c\u78ba\u4fdd\u6578\u64da\u4e0d\u6703\u56e0\u70ba\u7cfb\u7d71\u5d29\u6f70\u800c\u4e1f\u5931\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8redis%e4%b8%ad%e8%a8%98%e9%8c%84%e7%99%be%e8%90%ac%e6%a2%9d%e6%95%b8%e6%93%9a-wNyCUbyzwH\">\u5982\u4f55\u5728Redis\u4e2d\u8a18\u9304\u767e\u842c\u689d\u6578\u64da<\/h2>\n<p>\u8a18\u9304\u767e\u842c\u689d\u6578\u64da\u7684\u904e\u7a0b\u53ef\u4ee5\u5206\u70ba\u5e7e\u500b\u6b65\u9a5f\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528Redis\u7684\u5217\u8868\u7d50\u69cb\u4f86\u5b58\u5132\u6578\u64da\u3002<\/p>\n<pre><code>import redis\n\n# \u9023\u63a5\u5230Redis\u670d\u52d9\u5668\nr = redis.Redis(host='localhost', port=6379, db=0)\n\n# \u5047\u8a2d\u6211\u5011\u8981\u8a18\u9304100\u842c\u689d\u6578\u64da\nfor i in range(1, 1000001):\n    r.lpush('my_data_list', f'data_{i}')\n\n# \u78ba\u8a8d\u6578\u64da\u5df2\u6210\u529f\u5b58\u5132\nprint(r.llen('my_data_list'))  # \u8f38\u51fa\uff1a1000000\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u6211\u5011\u4f7f\u7528\u4e86Redis\u7684\u5217\u8868\u7d50\u69cb\uff08lpush\u547d\u4ee4\uff09\u4f86\u5c07\u6578\u64da\u63a8\u5165\u5217\u8868\u4e2d\u3002\u9019\u6a23\uff0c\u6211\u5011\u53ef\u4ee5\u8f15\u9b06\u5730\u8a18\u9304\u548c\u7ba1\u7406\u5927\u91cf\u6578\u64da\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e6%aa%a2%e7%b4%a2%e8%88%87%e6%93%8d%e4%bd%9c-wNyCUbyzwH\">\u6578\u64da\u6aa2\u7d22\u8207\u64cd\u4f5c<\/h2>\n<p>\u4e00\u65e6\u6578\u64da\u88ab\u5b58\u5132\u5728Redis\u4e2d\uff0c\u6aa2\u7d22\u548c\u64cd\u4f5c\u9019\u4e9b\u6578\u64da\u4e5f\u975e\u5e38\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u64cd\u4f5c\u793a\u4f8b\uff1a<\/p>\n<pre><code># \u7372\u53d6\u5217\u8868\u4e2d\u7684\u524d10\u689d\u6578\u64da\ndata = r.lrange('my_data_list', 0, 9)\nprint(data)\n\n# \u522a\u9664\u5217\u8868\u4e2d\u7684\u4e00\u689d\u6578\u64da\nr.lrem('my_data_list', 1, 'data_1')\n<\/code><\/pre>\n<p>\u9019\u4e9b\u64cd\u4f5c\u5c55\u793a\u4e86Redis\u5728\u6578\u64da\u6aa2\u7d22\u548c\u7ba1\u7406\u65b9\u9762\u7684\u9748\u6d3b\u6027\u548c\u9ad8\u6548\u6027\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-wNyCUbyzwH\">\u7d50\u8ad6<\/h2>\n<p>Redis\u4f5c\u70ba\u4e00\u500b\u9ad8\u6027\u80fd\u7684\u6578\u64da\u5eab\uff0c\u80fd\u5920\u8f15\u9b06\u61c9\u5c0d\u767e\u842c\u689d\u6578\u64da\u7684\u5b58\u5132\u9700\u6c42\u3002\u5176\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\u548c\u9ad8\u6548\u7684\u64cd\u4f5c\u6027\u80fd\uff0c\u4f7f\u5f97\u958b\u767c\u8005\u80fd\u5920\u5728\u5404\u7a2e\u61c9\u7528\u5834\u666f\u4e2d\u5145\u5206\u767c\u63ee\u5176\u6f5b\u529b\u3002\u7121\u8ad6\u662f\u5be6\u6642\u6578\u64da\u5206\u6790\u3001\u6d88\u606f\u968a\u5217\u9084\u662f\u7de9\u5b58\u7cfb\u7d71\uff0cRedis\u90fd\u80fd\u63d0\u4f9b\u5f37\u5927\u7684\u652f\u6301\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u4e00\u500b\u53ef\u9760\u7684\u89e3\u6c7a\u65b9\u6848\u4f86\u7ba1\u7406\u60a8\u7684\u6578\u64da\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u90e8\u7f72Redis\uff0c\u9019\u5c07\u70ba\u60a8\u7684\u61c9\u7528\u63d0\u4f9b\u7a69\u5b9a\u7684\u6027\u80fd\u548c\u9748\u6d3b\u7684\u64f4\u5c55\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5229\u7528Redis\u7a81\u7834\u6975\u9650\uff0c\u8f15\u9b06\u8a18\u9304\u767e\u842c\u689d\u6578\u64da\uff0c\u5be6\u73fe\u9ad8\u6548\u6578\u64da\u5b58\u5132\u8207\u5feb\u901f\u6aa2\u7d22\uff0c\u63d0\u5347\u61c9\u7528\u6027\u80fd\u8207\u53ef\u64f4\u5c55\u6027\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-167771","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/167771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=167771"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/167771\/revisions"}],"predecessor-version":[{"id":167772,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/167771\/revisions\/167772"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=167771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=167771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=167771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}