{"id":154099,"date":"2024-11-02T12:57:19","date_gmt":"2024-11-02T04:57:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/154099\/"},"modified":"2024-11-02T12:57:20","modified_gmt":"2024-11-02T04:57:20","slug":"%e9%9b%bb%e8%85%a6%e4%b8%8a%e5%a6%82%e4%bd%95%e9%81%8b%e8%a1%8credis%e7%b3%bb%e7%b5%b1%ef%bc%88%e9%9b%bb%e8%85%a6%e6%80%8e%e9%ba%bc%e9%81%8b%e8%a1%8credis%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/154099\/","title":{"rendered":"\u96fb\u8166\u4e0a\u5982\u4f55\u904b\u884cRedis\u7cfb\u7d71\uff08\u96fb\u8166\u600e\u9ebc\u904b\u884credis\uff09"},"content":{"rendered":"<h1 id=\"%e9%9b%bb%e8%85%a6%e4%b8%8a%e5%a6%82%e4%bd%95%e9%81%8b%e8%a1%8credis%e7%b3%bb%e7%b5%b1%ef%bc%88%e9%9b%bb%e8%85%a6%e6%80%8e%e9%ba%bc%e9%81%8b%e8%a1%8credis%ef%bc%89-AqULOBoeAa\">\u96fb\u8166\u4e0a\u5982\u4f55\u904b\u884cRedis\u7cfb\u7d71\uff08\u96fb\u8166\u600e\u9ebc\u904b\u884credis\uff09<\/h1>\n<p>Redis\u662f\u4e00\u500b\u958b\u6e90\u7684\u9ad8\u6027\u80fd\u9375\u503c\u6578\u64da\u5eab\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u7de9\u5b58\u3001\u6d88\u606f\u968a\u5217\u548c\u6578\u64da\u6301\u4e45\u5316\u7b49\u5834\u666f\u3002\u7531\u65bc\u5176\u9ad8\u6548\u7684\u6027\u80fd\u548c\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\uff0cRedis\u5df2\u6210\u70ba\u8a31\u591a\u958b\u767c\u8005\u548c\u4f01\u696d\u7684\u9996\u9078\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728\u96fb\u8166\u4e0a\u904b\u884cRedis\u7cfb\u7d71\uff0c\u4e26\u63d0\u4f9b\u8a73\u7d30\u7684\u6b65\u9a5f\u548c\u793a\u4f8b\u3002<\/p>\n<h2 id=\"1-%e7%92%b0%e5%a2%83%e6%ba%96%e5%82%99-AqULOBoeAa\">1. \u74b0\u5883\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u60a8\u7684\u96fb\u8166\u4e0a\u5df2\u5b89\u88dd\u4ee5\u4e0b\u74b0\u5883\uff1a<\/p>\n<ul>\n<li>\u64cd\u4f5c\u7cfb\u7d71\uff1aRedis\u652f\u6301\u591a\u7a2e\u64cd\u4f5c\u7cfb\u7d71\uff0c\u5305\u62ecLinux\u3001macOS\u548cWindows\u3002<\/li>\n<li>\u5b89\u88dd\u5de5\u5177\uff1a\u5efa\u8b70\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\uff08\u5982Homebrew\u3001apt\u6216yum\uff09\u4f86\u5b89\u88ddRedis\u3002<\/li>\n<\/ul>\n<h2 id=\"2-%e5%ae%89%e8%a3%9dredis-AqULOBoeAa\">2. \u5b89\u88ddRedis<\/h2>\n<h3 id=\"2-1-%e5%9c%a8linux%e4%b8%8a%e5%ae%89%e8%a3%9dredis-AqULOBoeAa\">2.1 \u5728Linux\u4e0a\u5b89\u88ddRedis<\/h3>\n<pre><code>sudo apt update\nsudo apt install redis-server<\/code><\/pre>\n<p>\u5b89\u88dd\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\u662f\u5426\u6b63\u5728\u904b\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo systemctl status redis.service<\/code><\/pre>\n<h3 id=\"2-2-%e5%9c%a8macos%e4%b8%8a%e5%ae%89%e8%a3%9dredis-AqULOBoeAa\">2.2 \u5728macOS\u4e0a\u5b89\u88ddRedis<\/h3>\n<p>\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662fmacOS\uff0c\u5efa\u8b70\u4f7f\u7528Homebrew\u4f86\u5b89\u88ddRedis\uff1a<\/p>\n<pre><code>brew install redis<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5Redis\uff1a<\/p>\n<pre><code>redis-server<\/code><\/pre>\n<h3 id=\"2-3-%e5%9c%a8windows%e4%b8%8a%e5%ae%89%e8%a3%9dredis-AqULOBoeAa\">2.3 \u5728Windows\u4e0a\u5b89\u88ddRedis<\/h3>\n<p>\u5728Windows\u4e0a\u904b\u884cRedis\u7a0d\u5fae\u8907\u96dc\u4e00\u4e9b\uff0c\u56e0\u70baRedis\u5b98\u65b9\u4e26\u4e0d\u76f4\u63a5\u652f\u6301Windows\u3002\u60a8\u53ef\u4ee5\u5f9eMicrosoft\u7684GitHub\u9801\u9762\u4e0b\u8f09Windows\u7248\u672c\u7684Redis\uff1a<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/microsoftarchive\/redis\/releases\" rel=\"nofollow noopener\" target=\"_blank\">Redis for Windows Releases<\/a><\/li>\n<\/ul>\n<p>\u4e0b\u8f09\u5f8c\uff0c\u89e3\u58d3\u7e2e\u4e26\u904b\u884credis-server.exe\u4f86\u555f\u52d5Redis\u670d\u52d9\u3002<\/p>\n<h2 id=\"3-%e9%85%8d%e7%bd%aeredis-AqULOBoeAa\">3. \u914d\u7f6eRedis<\/h2>\n<p>Redis\u7684\u914d\u7f6e\u6587\u4ef6\u901a\u5e38\u4f4d\u65bc\/etc\/redis\/redis.conf\uff08Linux\uff09\u6216\/usr\/local\/etc\/redis.conf\uff08macOS\uff09\u3002\u60a8\u53ef\u4ee5\u6839\u64da\u9700\u8981\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\uff0c\u4f8b\u5982\u8a2d\u7f6e\u5bc6\u78bc\u3001\u4fee\u6539\u7aef\u53e3\u7b49\u3002<\/p>\n<pre><code># \u8a2d\u7f6e\u5bc6\u78bc\nrequirepass yourpassword\n\n# \u4fee\u6539\u7aef\u53e3\nport 6379<\/code><\/pre>\n<p>\u4fee\u6539\u5b8c\u6210\u5f8c\uff0c\u91cd\u555fRedis\u670d\u52d9\u4ee5\u4f7f\u914d\u7f6e\u751f\u6548\uff1a<\/p>\n<pre><code>sudo systemctl restart redis.service  # Linux\n# \u6216\u8005\nredis-server \/usr\/local\/etc\/redis.conf  # macOS<\/code><\/pre>\n<h2 id=\"4-%e4%bd%bf%e7%94%a8redis-AqULOBoeAa\">4. \u4f7f\u7528Redis<\/h2>\n<p>Redis\u63d0\u4f9b\u4e86\u4e00\u500b\u547d\u4ee4\u884c\u754c\u9762\uff08CLI\uff09\u4f86\u8207\u6578\u64da\u5eab\u9032\u884c\u4ea4\u4e92\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u5165Redis CLI\uff1a<\/p>\n<pre><code>redis-cli<\/code><\/pre>\n<p>\u5728CLI\u4e2d\uff0c\u60a8\u53ef\u4ee5\u57f7\u884c\u5404\u7a2e\u64cd\u4f5c\uff0c\u4f8b\u5982\u8a2d\u7f6e\u9375\u503c\u5c0d\u3001\u67e5\u8a62\u6578\u64da\u7b49\uff1a<\/p>\n<pre><code>SET key \"value\"\nGET key<\/code><\/pre>\n<h2 id=\"5-%e6%b8%ac%e8%a9%a6redis-AqULOBoeAa\">5. \u6e2c\u8a66Redis<\/h2>\n<p>\u70ba\u4e86\u78ba\u4fddRedis\u6b63\u5e38\u904b\u884c\uff0c\u60a8\u53ef\u4ee5\u57f7\u884c\u4e00\u4e9b\u57fa\u672c\u7684\u6e2c\u8a66\u3002\u9996\u5148\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8a2d\u7f6e\u4e00\u500b\u9375\u503c\u5c0d\uff1a<\/p>\n<pre><code>SET test_key \"Hello, Redis!\"<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u4f7f\u7528GET\u547d\u4ee4\u6aa2\u7d22\u8a72\u503c\uff1a<\/p>\n<pre><code>GET test_key<\/code><\/pre>\n<p>\u5982\u679c\u8fd4\u56de\u201cHello, Redis!\u201d\uff0c\u5247\u8868\u793aRedis\u5df2\u6210\u529f\u904b\u884c\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-AqULOBoeAa\">\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u5728\u96fb\u8166\u4e0a\u904b\u884cRedis\u7cfb\u7d71\uff0c\u5305\u62ec\u5b89\u88dd\u3001\u914d\u7f6e\u548c\u57fa\u672c\u4f7f\u7528\u3002Redis\u4f5c\u70ba\u4e00\u500b\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\uff0c\u80fd\u5920\u6eff\u8db3\u5404\u7a2e\u61c9\u7528\u9700\u6c42\u3002\u5982\u679c\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684\u6578\u64da\u8655\u7406\u80fd\u529b\uff0c\u53ef\u4ee5\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u90e8\u7f72Redis\uff0c\u9019\u6a23\u53ef\u4ee5\u7372\u5f97\u66f4\u597d\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728\u96fb\u8166\u4e0a\u5b89\u88dd\u548c\u904b\u884cRedis\u7cfb\u7d71\uff0c\u7c21\u55ae\u6b65\u9a5f\u52a9\u4f60\u5feb\u901f\u555f\u52d5\u9ad8\u6548\u7684\u6578\u64da\u5eab\u670d\u52d9\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-154099","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/154099","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=154099"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/154099\/revisions"}],"predecessor-version":[{"id":154100,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/154099\/revisions\/154100"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=154099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=154099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=154099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}