{"id":116616,"date":"2024-10-24T15:54:26","date_gmt":"2024-10-24T07:54:26","guid":{"rendered":"https:\/\/server.hk\/cnblog\/116616\/"},"modified":"2024-10-24T15:54:27","modified_gmt":"2024-10-24T07:54:27","slug":"redis-%e5%bf%ab%e5%8f%96%e8%ae%93%e7%a8%8b%e5%ba%8f%e9%81%8b%e8%a1%8c%e6%9b%b4%e9%ab%98%e6%95%88-2","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/116616\/","title":{"rendered":"Redis \u5feb\u53d6\u8b93\u7a0b\u5e8f\u904b\u884c\u66f4\u9ad8\u6548"},"content":{"rendered":"<h1 id=\"redis-%e5%bf%ab%e5%8f%96%e8%ae%93%e7%a8%8b%e5%ba%8f%e9%81%8b%e8%a1%8c%e6%9b%b4%e9%ab%98%e6%95%88-LqokfGpliM\">Redis \u5feb\u53d6\u8b93\u7a0b\u5e8f\u904b\u884c\u66f4\u9ad8\u6548<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u61c9\u7528\u4e2d\uff0c\u6027\u80fd\u548c\u6548\u7387\u662f\u958b\u767c\u8005\u6700\u95dc\u6ce8\u7684\u554f\u984c\u4e4b\u4e00\u3002\u96a8\u8457\u7528\u6236\u9700\u6c42\u7684\u589e\u52a0\uff0c\u5982\u4f55\u5feb\u901f\u97ff\u61c9\u8acb\u6c42\u4e26\u63d0\u4f9b\u6d41\u66a2\u7684\u4f7f\u7528\u9ad4\u9a57\u6210\u70ba\u4e86\u6bcf\u500b\u958b\u767c\u8005\u7684\u6311\u6230\u3002Redis \u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u5feb\u53d6\u89e3\u6c7a\u65b9\u6848\uff0c\u80fd\u5920\u986f\u8457\u63d0\u9ad8\u7a0b\u5e8f\u7684\u904b\u884c\u6548\u7387\u3002\u672c\u6587\u5c07\u63a2\u8a0e Redis \u7684\u57fa\u672c\u6982\u5ff5\u3001\u5de5\u4f5c\u539f\u7406\u4ee5\u53ca\u5982\u4f55\u5728\u5be6\u969b\u61c9\u7528\u4e2d\u5229\u7528 Redis \u5feb\u53d6\u4f86\u63d0\u5347\u6027\u80fd\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-redis%ef%bc%9f-LqokfGpliM\">\u4ec0\u9ebc\u662f Redis\uff1f<\/h2>\n<p>Redis\uff08Remote Dictionary Server\uff09\u662f\u4e00\u7a2e\u958b\u6e90\u7684\u9ad8\u6027\u80fd\u9375\u503c\u6578\u64da\u5eab\uff0c\u4e3b\u8981\u7528\u65bc\u6578\u64da\u7684\u5feb\u53d6\u548c\u5b58\u5132\u3002\u5b83\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\u975e\u5e38\u5feb\uff0c\u901a\u5e38\u5728\u6beb\u79d2\u7d1a\u5225\u3002<\/p>\n<h2 id=\"redis-%e7%9a%84%e5%b7%a5%e4%bd%9c%e5%8e%9f%e7%90%86-LqokfGpliM\">Redis \u7684\u5de5\u4f5c\u539f\u7406<\/h2>\n<p>Redis \u7684\u5de5\u4f5c\u539f\u7406\u57fa\u65bc\u9375\u503c\u5c0d\u7684\u5b58\u5132\u65b9\u5f0f\u3002\u7576\u61c9\u7528\u7a0b\u5e8f\u9700\u8981\u5b58\u53d6\u6578\u64da\u6642\uff0c\u9996\u5148\u6703\u67e5\u8a62 Redis \u5feb\u53d6\u3002\u5982\u679c\u6578\u64da\u5b58\u5728\u65bc\u5feb\u53d6\u4e2d\uff0c\u5247\u76f4\u63a5\u8fd4\u56de\uff1b\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5247\u5f9e\u6578\u64da\u5eab\u4e2d\u8b80\u53d6\u6578\u64da\uff0c\u4e26\u5c07\u5176\u5b58\u5165 Redis \u5feb\u53d6\uff0c\u4ee5\u4fbf\u4e0b\u6b21\u4f7f\u7528\u3002\u9019\u7a2e\u65b9\u5f0f\u5927\u5927\u6e1b\u5c11\u4e86\u5c0d\u5f8c\u7aef\u6578\u64da\u5eab\u7684\u8acb\u6c42\uff0c\u5f9e\u800c\u63d0\u9ad8\u4e86\u6574\u9ad4\u6027\u80fd\u3002<\/p>\n<h3 id=\"%e5%bf%ab%e5%8f%96%e7%9a%84%e5%84%aa%e5%8b%a2-LqokfGpliM\">\u5feb\u53d6\u7684\u512a\u52e2<\/h3>\n<ul>\n<li><strong>\u6e1b\u5c11\u5ef6\u9072\uff1a<\/strong>\u901a\u904e\u5c07\u5e38\u7528\u6578\u64da\u5b58\u5132\u5728\u5167\u5b58\u4e2d\uff0cRedis \u80fd\u5920\u5feb\u901f\u97ff\u61c9\u8acb\u6c42\uff0c\u986f\u8457\u964d\u4f4e\u5ef6\u9072\u3002<\/li>\n<li><strong>\u6e1b\u5c11\u6578\u64da\u5eab\u8ca0\u64d4\uff1a<\/strong>\u5c07\u983b\u7e41\u8a2a\u554f\u7684\u6578\u64da\u653e\u5165\u5feb\u53d6\u4e2d\uff0c\u53ef\u4ee5\u6e1b\u5c11\u5c0d\u5f8c\u7aef\u6578\u64da\u5eab\u7684\u8acb\u6c42\uff0c\u964d\u4f4e\u6578\u64da\u5eab\u7684\u8ca0\u64d4\u3002<\/li>\n<li><strong>\u64f4\u5c55\u6027\uff1a<\/strong>Redis \u652f\u6301\u5206\u4f48\u5f0f\u67b6\u69cb\uff0c\u53ef\u4ee5\u8f15\u9b06\u64f4\u5c55\u4ee5\u61c9\u5c0d\u66f4\u9ad8\u7684\u6d41\u91cf\u9700\u6c42\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8%e6%87%89%e7%94%a8%e4%b8%ad%e4%bd%bf%e7%94%a8-redis-%e5%bf%ab%e5%8f%96-LqokfGpliM\">\u5982\u4f55\u5728\u61c9\u7528\u4e2d\u4f7f\u7528 Redis \u5feb\u53d6<\/h2>\n<p>\u5728\u5be6\u969b\u61c9\u7528\u4e2d\uff0c\u4f7f\u7528 Redis \u5feb\u53d6\u7684\u904e\u7a0b\u901a\u5e38\u5305\u62ec\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e5%ae%89%e8%a3%9d-redis-LqokfGpliM\">1. \u5b89\u88dd Redis<\/h3>\n<p>\u9996\u5148\uff0c\u9700\u8981\u5728\u4f3a\u670d\u5668\u4e0a\u5b89\u88dd Redis\u3002\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u5728 Ubuntu \u7cfb\u7d71\u4e0a\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install redis-server<\/code><\/pre>\n<h3 id=\"2-%e9%85%8d%e7%bd%ae-redis-LqokfGpliM\">2. \u914d\u7f6e Redis<\/h3>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u901a\u904e\u7de8\u8f2f\u914d\u7f6e\u6587\u4ef6\u4f86\u8abf\u6574 Redis \u7684\u8a2d\u7f6e\u3002\u914d\u7f6e\u6587\u4ef6\u901a\u5e38\u4f4d\u65bc \/etc\/redis\/redis.conf\u3002\u53ef\u4ee5\u6839\u64da\u9700\u8981\u8abf\u6574\u5167\u5b58\u9650\u5236\u3001\u6301\u4e45\u5316\u9078\u9805\u7b49\u3002<\/p>\n<h3 id=\"3-%e9%9b%86%e6%88%90-redis-%e5%88%b0%e6%87%89%e7%94%a8%e4%b8%ad-LqokfGpliM\">3. \u96c6\u6210 Redis \u5230\u61c9\u7528\u4e2d<\/h3>\n<p>\u5728\u61c9\u7528\u4e2d\u96c6\u6210 Redis\uff0c\u901a\u5e38\u9700\u8981\u4f7f\u7528\u76f8\u61c9\u7684\u5ba2\u6236\u7aef\u5eab\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528 Python \u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>import redis\n\n# \u9023\u63a5\u5230 Redis\nr = redis.Redis(host='localhost', port=6379, db=0)\n\n# \u8a2d\u7f6e\u5feb\u53d6\nr.set('key', 'value')\n\n# \u7372\u53d6\u5feb\u53d6\nvalue = r.get('key')\nprint(value.decode('utf-8'))  # \u8f38\u51fa: value<\/code><\/pre>\n<h3 id=\"4-%e5%af%a6%e7%8f%be%e5%bf%ab%e5%8f%96%e9%82%8f%e8%bc%af-LqokfGpliM\">4. \u5be6\u73fe\u5feb\u53d6\u908f\u8f2f<\/h3>\n<p>\u5728\u61c9\u7528\u4e2d\uff0c\u53ef\u4ee5\u6839\u64da\u696d\u52d9\u9700\u6c42\u8a2d\u8a08\u5feb\u53d6\u908f\u8f2f\u3002\u4f8b\u5982\uff0c\u5728\u67e5\u8a62\u6578\u64da\u6642\uff0c\u9996\u5148\u6aa2\u67e5 Redis \u4e2d\u662f\u5426\u5b58\u5728\u8a72\u6578\u64da\uff0c\u5982\u679c\u5b58\u5728\u5247\u76f4\u63a5\u8fd4\u56de\uff0c\u5426\u5247\u5f9e\u6578\u64da\u5eab\u4e2d\u67e5\u8a62\u4e26\u66f4\u65b0\u5feb\u53d6\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-LqokfGpliM\">\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\u61c9\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u3002\u901a\u904e\u5408\u7406\u5730\u4f7f\u7528 Redis \u5feb\u53d6\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6e1b\u5c11\u5ef6\u9072\u3001\u964d\u4f4e\u6578\u64da\u5eab\u8ca0\u64d4\uff0c\u4e26\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002\u5728\u7576\u4eca\u7af6\u722d\u6fc0\u70c8\u7684\u5e02\u5834\u4e2d\uff0c\u9078\u64c7\u5408\u9069\u7684\u6280\u8853\u67b6\u69cb\u81f3\u95dc\u91cd\u8981\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u80fd\u7684\u61c9\u7528\uff0c\u8003\u616e\u4f7f\u7528 Redis \u5feb\u53d6\u5c07\u662f\u4e00\u500b\u660e\u667a\u7684\u9078\u64c7\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u548c\u5176\u4ed6\u4f3a\u670d\u5668\u89e3\u6c7a\u65b9\u6848\u7684\u4fe1\u606f\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis \u5feb\u53d6\u63d0\u5347\u7a0b\u5e8f\u904b\u884c\u6548\u7387\uff0c\u6e1b\u5c11\u5ef6\u9072\uff0c\u52a0\u901f\u6578\u64da\u5b58\u53d6\uff0c\u8b93\u61c9\u7528\u7a0b\u5f0f\u66f4\u6d41\u66a2\uff0c\u63d0\u5347\u7528\u6236\u9ad4\u9a57\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-116616","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/116616","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=116616"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/116616\/revisions"}],"predecessor-version":[{"id":116617,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/116616\/revisions\/116617"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=116616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=116616"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=116616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}