{"id":113271,"date":"2024-10-24T11:25:31","date_gmt":"2024-10-24T03:25:31","guid":{"rendered":"https:\/\/server.hk\/cnblog\/113271\/"},"modified":"2024-10-24T11:25:32","modified_gmt":"2024-10-24T03:25:32","slug":"redis-%e5%bf%ab%e5%8f%96%e6%a5%b5%e5%a4%a7%e6%8f%90%e9%ab%98%e6%95%b8%e6%93%9a%e8%ae%80%e5%8f%96%e6%80%a7%e8%83%bd","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/113271\/","title":{"rendered":"Redis \u5feb\u53d6\u6975\u5927\u63d0\u9ad8\u6578\u64da\u8b80\u53d6\u6027\u80fd"},"content":{"rendered":"<h1 id=\"redis-%e5%bf%ab%e5%8f%96%e6%a5%b5%e5%a4%a7%e6%8f%90%e9%ab%98%e6%95%b8%e6%93%9a%e8%ae%80%e5%8f%96%e6%80%a7%e8%83%bd-uguYrJdHSV\">Redis \u5feb\u53d6\u6975\u5927\u63d0\u9ad8\u6578\u64da\u8b80\u53d6\u6027\u80fd<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u64da\u9a45\u52d5\u7684\u4e16\u754c\u4e2d\uff0c\u61c9\u7528\u7a0b\u5f0f\u7684\u6027\u80fd\u5c0d\u65bc\u7528\u6236\u9ad4\u9a57\u81f3\u95dc\u91cd\u8981\u3002\u96a8\u8457\u7528\u6236\u6578\u91cf\u7684\u589e\u52a0\u548c\u6578\u64da\u91cf\u7684\u6fc0\u589e\uff0c\u5982\u4f55\u6709\u6548\u5730\u7ba1\u7406\u548c\u8b80\u53d6\u6578\u64da\u6210\u70ba\u4e86\u958b\u767c\u8005\u9762\u81e8\u7684\u4e00\u5927\u6311\u6230\u3002Redis \u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u5feb\u53d6\u89e3\u6c7a\u65b9\u6848\uff0c\u80fd\u5920\u986f\u8457\u63d0\u9ad8\u6578\u64da\u8b80\u53d6\u6027\u80fd\uff0c\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e Redis \u7684\u5de5\u4f5c\u539f\u7406\u53ca\u5176\u5728\u6578\u64da\u8b80\u53d6\u4e2d\u7684\u61c9\u7528\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-redis%ef%bc%9f-uguYrJdHSV\">\u4ec0\u9ebc\u662f Redis\uff1f<\/h2>\n<p>Redis\uff08Remote Dictionary Server\uff09\u662f\u4e00\u7a2e\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\u9ad8\u6548\u7684\u6027\u80fd\u548c\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\uff0cRedis \u88ab\u5ee3\u6cdb\u61c9\u7528\u65bc\u5feb\u53d6\u3001\u6d88\u606f\u968a\u5217\u548c\u5be6\u6642\u6578\u64da\u5206\u6790\u7b49\u5834\u666f\u3002<\/p>\n<h2 id=\"redis-%e7%9a%84%e5%b7%a5%e4%bd%9c%e5%8e%9f%e7%90%86-uguYrJdHSV\">Redis \u7684\u5de5\u4f5c\u539f\u7406<\/h2>\n<p>Redis \u5c07\u6578\u64da\u5b58\u5132\u5728\u5167\u5b58\u4e2d\uff0c\u9019\u4f7f\u5f97\u6578\u64da\u7684\u8b80\u53d6\u901f\u5ea6\u6975\u5feb\u3002\u8207\u50b3\u7d71\u7684\u95dc\u4fc2\u578b\u6578\u64da\u5eab\u76f8\u6bd4\uff0cRedis \u7684\u8b80\u53d6\u5ef6\u9072\u901a\u5e38\u5728\u6beb\u79d2\u7d1a\u5225\uff0c\u9019\u5c0d\u65bc\u9700\u8981\u5feb\u901f\u97ff\u61c9\u7684\u61c9\u7528\u7a0b\u5f0f\u4f86\u8aaa\u81f3\u95dc\u91cd\u8981\u3002<\/p>\n<h3 id=\"%e5%bf%ab%e5%8f%96%e6%a9%9f%e5%88%b6-uguYrJdHSV\">\u5feb\u53d6\u6a5f\u5236<\/h3>\n<p>Redis \u7684\u5feb\u53d6\u6a5f\u5236\u4e3b\u8981\u4f9d\u8cf4\u65bc\u4ee5\u4e0b\u5e7e\u500b\u65b9\u9762\uff1a<\/p>\n<ul>\n<li><strong>\u5167\u5b58\u5b58\u5132\uff1a<\/strong>\u6578\u64da\u76f4\u63a5\u5b58\u5132\u5728\u5167\u5b58\u4e2d\uff0c\u907f\u514d\u4e86\u78c1\u789f I\/O \u7684\u5ef6\u9072\u3002<\/li>\n<li><strong>\u6578\u64da\u7d50\u69cb\uff1a<\/strong>\u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff0c\u80fd\u5920\u6839\u64da\u4e0d\u540c\u7684\u9700\u6c42\u9078\u64c7\u6700\u5408\u9069\u7684\u5b58\u5132\u65b9\u5f0f\u3002<\/li>\n<li><strong>\u6301\u4e45\u5316\u9078\u9805\uff1a<\/strong>\u96d6\u7136\u4e3b\u8981\u7528\u4f5c\u5feb\u53d6\uff0cRedis \u4e5f\u63d0\u4f9b\u4e86\u6301\u4e45\u5316\u9078\u9805\uff0c\u78ba\u4fdd\u6578\u64da\u4e0d\u6703\u56e0\u70ba\u670d\u52d9\u5668\u91cd\u555f\u800c\u4e1f\u5931\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%8f%90%e9%ab%98%e6%95%b8%e6%93%9a%e8%ae%80%e5%8f%96%e6%80%a7%e8%83%bd%e7%9a%84%e5%af%a6%e9%9a%9b%e6%a1%88%e4%be%8b-uguYrJdHSV\">\u63d0\u9ad8\u6578\u64da\u8b80\u53d6\u6027\u80fd\u7684\u5be6\u969b\u6848\u4f8b<\/h2>\n<p>\u8a31\u591a\u4f01\u696d\u5df2\u7d93\u6210\u529f\u5730\u5c07 Redis \u61c9\u7528\u65bc\u5176\u7cfb\u7d71\u4e2d\uff0c\u4ee5\u63d0\u9ad8\u6578\u64da\u8b80\u53d6\u6027\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5177\u9ad4\u7684\u61c9\u7528\u6848\u4f8b\uff1a<\/p>\n<h3 id=\"1-%e9%9b%bb%e5%ad%90%e5%95%86%e5%8b%99%e5%b9%b3%e5%8f%b0-uguYrJdHSV\">1. \u96fb\u5b50\u5546\u52d9\u5e73\u53f0<\/h3>\n<p>\u5728\u96fb\u5b50\u5546\u52d9\u5e73\u53f0\u4e2d\uff0c\u5546\u54c1\u4fe1\u606f\u7684\u8b80\u53d6\u901f\u5ea6\u76f4\u63a5\u5f71\u97ff\u7528\u6236\u7684\u8cfc\u7269\u9ad4\u9a57\u3002\u901a\u904e\u5c07\u71b1\u9580\u5546\u54c1\u4fe1\u606f\u7de9\u5b58\u5728 Redis \u4e2d\uff0c\u5e73\u53f0\u80fd\u5920\u5feb\u901f\u97ff\u61c9\u7528\u6236\u7684\u67e5\u8a62\u8acb\u6c42\uff0c\u5f9e\u800c\u63d0\u9ad8\u8f49\u5316\u7387\u3002<\/p>\n<h3 id=\"2-%e7%a4%be%e4%ba%a4%e5%aa%92%e9%ab%94%e6%87%89%e7%94%a8-uguYrJdHSV\">2. \u793e\u4ea4\u5a92\u9ad4\u61c9\u7528<\/h3>\n<p>\u793e\u4ea4\u5a92\u9ad4\u61c9\u7528\u9700\u8981\u5be6\u6642\u66f4\u65b0\u7528\u6236\u7684\u52d5\u614b\u4fe1\u606f\u3002\u4f7f\u7528 Redis \u4f5c\u70ba\u5feb\u53d6\u5c64\uff0c\u80fd\u5920\u5feb\u901f\u8b80\u53d6\u7528\u6236\u7684\u6700\u65b0\u52d5\u614b\uff0c\u6e1b\u5c11\u6578\u64da\u5eab\u7684\u8ca0\u64d4\uff0c\u63d0\u5347\u6574\u9ad4\u6027\u80fd\u3002<\/p>\n<h2 id=\"redis-%e7%9a%84%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b-uguYrJdHSV\">Redis \u7684\u4f7f\u7528\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684 Redis \u4f7f\u7528\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5c07\u6578\u64da\u5b58\u5132\u5230 Redis \u4e2d\u4e26\u9032\u884c\u8b80\u53d6\uff1a<\/p>\n<pre><code>import redis\n\n# \u9023\u63a5\u5230 Redis\nr = redis.Redis(host='localhost', port=6379, db=0)\n\n# \u5b58\u5132\u6578\u64da\nr.set('user:1000', 'John Doe')\n\n# \u8b80\u53d6\u6578\u64da\nuser = r.get('user:1000')\nprint(user.decode('utf-8'))  # \u8f38\u51fa: John Doe\n<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-uguYrJdHSV\">\u7d50\u8ad6<\/h2>\n<p>Redis \u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u5feb\u53d6\u89e3\u6c7a\u65b9\u6848\uff0c\u80fd\u5920\u986f\u8457\u63d0\u9ad8\u6578\u64da\u8b80\u53d6\u6027\u80fd\uff0c\u7279\u5225\u662f\u5728\u9ad8\u4e26\u767c\u7684\u61c9\u7528\u5834\u666f\u4e2d\u3002\u901a\u904e\u5408\u7406\u5730\u4f7f\u7528 Redis\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6e1b\u5c11\u6578\u64da\u5eab\u7684\u8ca0\u64d4\uff0c\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002\u96a8\u8457\u6280\u8853\u7684\u767c\u5c55\uff0cRedis \u7684\u61c9\u7528\u7bc4\u570d\u5c07\u6703\u66f4\u52a0\u5ee3\u6cdb\uff0c\u6210\u70ba\u672a\u4f86\u6578\u64da\u8655\u7406\u7684\u91cd\u8981\u5de5\u5177\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u95dc\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u548c <a href=\"https:\/\/server.hk\">\u4e91\u670d\u52a1\u5668<\/a> \u7684\u4fe1\u606f\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis \u5feb\u53d6\u986f\u8457\u63d0\u5347\u6578\u64da\u8b80\u53d6\u6027\u80fd\uff0c\u5be6\u73fe\u5feb\u901f\u97ff\u61c9\u548c\u9ad8\u6548\u6578\u64da\u8655\u7406\uff0c\u52a9\u529b\u61c9\u7528\u7a0b\u5e8f\u6027\u80fd\u512a\u5316\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-113271","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/113271","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=113271"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/113271\/revisions"}],"predecessor-version":[{"id":113272,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/113271\/revisions\/113272"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=113271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=113271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=113271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}