{"id":174703,"date":"2024-11-07T23:02:20","date_gmt":"2024-11-07T15:02:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/174703\/"},"modified":"2024-11-07T23:02:20","modified_gmt":"2024-11-07T15:02:20","slug":"%e5%a6%82%e4%bd%95%e5%bf%ab%e9%80%9f%e5%95%9f%e5%8b%95redis%e6%9c%8d%e5%8b%99%e7%ab%af%ef%bc%88%e5%a6%82%e4%bd%95-%e6%89%93%e9%96%8bredis%e6%9c%8d%e5%8b%99%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/174703\/","title":{"rendered":"\u5982\u4f55\u5feb\u901f\u555f\u52d5Redis\u670d\u52d9\u7aef\uff08\u5982\u4f55 \u6253\u958bredis\u670d\u52d9\uff09"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e5%bf%ab%e9%80%9f%e5%95%9f%e5%8b%95redis%e6%9c%8d%e5%8b%99%e7%ab%af%ef%bc%88%e5%a6%82%e4%bd%95%e6%89%93%e9%96%8bredis%e6%9c%8d%e5%8b%99%ef%bc%89-wmsbErgZTR\">\u5982\u4f55\u5feb\u901f\u555f\u52d5Redis\u670d\u52d9\u7aef\uff08\u5982\u4f55\u6253\u958bRedis\u670d\u52d9\uff09<\/h1>\n<p>Redis\u662f\u4e00\u500b\u9ad8\u6548\u80fd\u7684\u9375\u503c\u6578\u64da\u5eab\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u7de9\u5b58\u3001\u6d88\u606f\u968a\u5217\u548c\u6578\u64da\u5b58\u5132\u7b49\u5834\u666f\u3002\u7531\u65bc\u5176\u5feb\u901f\u7684\u8b80\u5beb\u901f\u5ea6\u548c\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\uff0cRedis\u6210\u70ba\u8a31\u591a\u958b\u767c\u8005\u548c\u4f01\u696d\u7684\u9996\u9078\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5feb\u901f\u555f\u52d5Redis\u670d\u52d9\u7aef\uff0c\u5e6b\u52a9\u60a8\u5728\u81ea\u5df1\u7684\u74b0\u5883\u4e2d\u8f15\u9b06\u8a2d\u7f6e\u548c\u904b\u884cRedis\u3002<\/p>\n<h2 id=\"1-%e7%92%b0%e5%a2%83%e6%ba%96%e5%82%99-wmsbErgZTR\">1. \u74b0\u5883\u6e96\u5099<\/h2>\n<p>\u5728\u555f\u52d5Redis\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u60a8\u7684\u7cfb\u7d71\u74b0\u5883\u5df2\u7d93\u6e96\u5099\u597d\u3002Redis\u652f\u6301\u591a\u7a2e\u64cd\u4f5c\u7cfb\u7d71\uff0c\u5305\u62ecLinux\u3001macOS\u548cWindows\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684\u74b0\u5883\u8981\u6c42\uff1a<\/p>\n<ul>\n<li>\u64cd\u4f5c\u7cfb\u7d71\uff1aLinux\uff08\u5982Ubuntu\u3001CentOS\uff09\u3001macOS\u6216Windows<\/li>\n<li>\u5167\u5b58\uff1a\u81f3\u5c11512MB\u7684\u53ef\u7528\u5167\u5b58<\/li>\n<li>\u78c1\u789f\u7a7a\u9593\uff1a\u81f3\u5c11100MB\u7684\u53ef\u7528\u78c1\u789f\u7a7a\u9593<\/li>\n<\/ul>\n<h2 id=\"2-%e5%ae%89%e8%a3%9dredis-wmsbErgZTR\">2. \u5b89\u88ddRedis<\/h2>\n<p>\u5728Linux\u7cfb\u7d71\u4e0a\uff0c\u60a8\u53ef\u4ee5\u901a\u904e\u5305\u7ba1\u7406\u5668\u8f15\u9b06\u5b89\u88ddRedis\u3002\u4ee5\u4e0b\u662f\u4ee5Ubuntu\u70ba\u4f8b\u7684\u5b89\u88dd\u6b65\u9a5f\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install redis-server<\/code><\/pre>\n<p>\u5c0d\u65bcCentOS\u7528\u6236\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo yum install epel-release\nsudo yum install redis<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5Redis\u7684\u7248\u672c\uff1a<\/p>\n<pre><code>redis-server --version<\/code><\/pre>\n<h2 id=\"3-%e9%85%8d%e7%bd%aeredis-wmsbErgZTR\">3. \u914d\u7f6eRedis<\/h2>\n<p>Redis\u7684\u914d\u7f6e\u6587\u4ef6\u901a\u5e38\u4f4d\u65bc\/etc\/redis\/redis.conf\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u6587\u672c\u7de8\u8f2f\u5668\u6253\u958b\u6b64\u6587\u4ef6\u9032\u884c\u914d\u7f6e\uff1a<\/p>\n<pre><code>sudo nano \/etc\/redis\/redis.conf<\/code><\/pre>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u60a8\u53ef\u4ee5\u8a2d\u7f6e\u4ee5\u4e0b\u5e7e\u500b\u91cd\u8981\u53c3\u6578\uff1a<\/p>\n<ul>\n<li><strong>bind<\/strong>\uff1a\u8a2d\u7f6eRedis\u670d\u52d9\u5668\u7684\u7d81\u5b9aIP\u5730\u5740\uff0c\u9ed8\u8a8d\u70ba127.0.0.1\uff0c\u9019\u610f\u5473\u8457\u53ea\u6709\u672c\u5730\u8a2a\u554f\u3002\u5982\u679c\u9700\u8981\u9060\u7a0b\u8a2a\u554f\uff0c\u53ef\u4ee5\u5c07\u5176\u8a2d\u7f6e\u70ba0.0.0.0\u3002<\/li>\n<li><strong>protected-mode<\/strong>\uff1a\u4fdd\u8b77\u6a21\u5f0f\u9ed8\u8a8d\u70ba\u958b\u555f\uff0c\u5efa\u8b70\u5728\u751f\u7522\u74b0\u5883\u4e2d\u4fdd\u6301\u958b\u555f\u3002<\/li>\n<li><strong>port<\/strong>\uff1a\u8a2d\u7f6eRedis\u670d\u52d9\u5668\u7684\u7aef\u53e3\uff0c\u9ed8\u8a8d\u70ba6379\u3002<\/li>\n<\/ul>\n<h2 id=\"4-%e5%95%9f%e5%8b%95redis%e6%9c%8d%e5%8b%99-wmsbErgZTR\">4. \u555f\u52d5Redis\u670d\u52d9<\/h2>\n<p>\u914d\u7f6e\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5Redis\u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl start redis.service<\/code><\/pre>\n<p>\u8981\u6aa2\u67e5Redis\u670d\u52d9\u7684\u72c0\u614b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo systemctl status redis.service<\/code><\/pre>\n<p>\u5982\u679c\u60a8\u5e0c\u671bRedis\u5728\u7cfb\u7d71\u555f\u52d5\u6642\u81ea\u52d5\u555f\u52d5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo systemctl enable redis.service<\/code><\/pre>\n<h2 id=\"5-%e6%b8%ac%e8%a9%a6redis%e6%9c%8d%e5%8b%99-wmsbErgZTR\">5. \u6e2c\u8a66Redis\u670d\u52d9<\/h2>\n<p>\u555f\u52d5Redis\u670d\u52d9\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Redis\u81ea\u5e36\u7684\u5ba2\u6236\u7aef\u9032\u884c\u6e2c\u8a66\u3002\u8f38\u5165\u4ee5\u4e0b\u547d\u4ee4\u9032\u5165Redis\u547d\u4ee4\u884c\u754c\u9762\uff1a<\/p>\n<pre><code>redis-cli<\/code><\/pre>\n<p>\u5728\u547d\u4ee4\u884c\u4e2d\uff0c\u60a8\u53ef\u4ee5\u57f7\u884c\u4e00\u4e9b\u57fa\u672c\u7684\u547d\u4ee4\u4f86\u78ba\u8a8dRedis\u662f\u5426\u6b63\u5e38\u904b\u884c\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8a2d\u7f6e\u548c\u7372\u53d6\u4e00\u500b\u9375\u503c\uff1a<\/p>\n<pre><code>set test \"Hello, Redis!\"\nget test<\/code><\/pre>\n<p>\u5982\u679c\u8fd4\u56de\u201cHello, Redis!\u201d\u5247\u8868\u793aRedis\u670d\u52d9\u904b\u884c\u6b63\u5e38\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-wmsbErgZTR\">\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u5feb\u901f\u555f\u52d5Redis\u670d\u52d9\u7aef\uff0c\u5305\u62ec\u74b0\u5883\u6e96\u5099\u3001\u5b89\u88dd\u3001\u914d\u7f6e\u3001\u555f\u52d5\u548c\u6e2c\u8a66\u7b49\u6b65\u9a5f\u3002Redis\u4f5c\u70ba\u4e00\u500b\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u80fd\u5920\u70ba\u60a8\u7684\u61c9\u7528\u63d0\u4f9b\u5f37\u5927\u7684\u652f\u6301\u3002\u5982\u679c\u60a8\u9700\u8981\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u4f86\u904b\u884cRedis\uff0cServer.HK\u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u7528\u6236\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u5730\u5340\u7684\u670d\u52d9\u5668\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u53ef\u9760\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5feb\u901f\u555f\u52d5Redis\u670d\u52d9\u7aef\u7684\u6307\u5357\uff0c\u6559\u4f60\u5982\u4f55\u8f15\u9b06\u6253\u958bRedis\u670d\u52d9\uff0c\u63d0\u5347\u6578\u64da\u5b58\u53d6\u6548\u7387\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-174703","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/174703","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=174703"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/174703\/revisions"}],"predecessor-version":[{"id":174704,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/174703\/revisions\/174704"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=174703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=174703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=174703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}