{"id":167171,"date":"2024-11-05T22:57:20","date_gmt":"2024-11-05T14:57:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/167171\/"},"modified":"2024-11-05T22:57:21","modified_gmt":"2024-11-05T14:57:21","slug":"%e5%88%a9%e7%94%a8redis%e7%9a%84%e8%a8%aa%e5%95%8f%e4%bb%a3%e7%90%86%e6%8f%90%e5%8d%87%e6%9c%8d%e5%8b%99%e6%80%a7%e8%83%bd%ef%bc%88redis%e8%a8%aa%e5%95%8f%e4%bb%a3%e7%90%86%e9%a1%9e%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/167171\/","title":{"rendered":"\u5229\u7528Redis\u7684\u8a2a\u554f\u4ee3\u7406\u63d0\u5347\u670d\u52d9\u6027\u80fd\uff08redis\u8a2a\u554f\u4ee3\u7406\u985e\uff09"},"content":{"rendered":"<h1 id=\"%e5%88%a9%e7%94%a8redis%e7%9a%84%e8%a8%aa%e5%95%8f%e4%bb%a3%e7%90%86%e6%8f%90%e5%8d%87%e6%9c%8d%e5%8b%99%e6%80%a7%e8%83%bd%ef%bc%88redis%e8%a8%aa%e5%95%8f%e4%bb%a3%e7%90%86%e9%a1%9e%ef%bc%89-VWHkvOTiJQ\">\u5229\u7528Redis\u7684\u8a2a\u554f\u4ee3\u7406\u63d0\u5347\u670d\u52d9\u6027\u80fd\uff08redis\u8a2a\u554f\u4ee3\u7406\u985e\uff09<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u6027\u80fd\u548c\u6548\u7387\u662f\u6bcf\u500b\u4f01\u696d\u90fd\u5fc5\u9808\u8003\u616e\u7684\u95dc\u9375\u56e0\u7d20\u3002\u96a8\u8457\u7528\u6236\u9700\u6c42\u7684\u589e\u52a0\uff0c\u5982\u4f55\u6709\u6548\u5730\u7ba1\u7406\u548c\u512a\u5316\u6578\u64da\u8a2a\u554f\u6210\u70ba\u4e86\u6280\u8853\u4eba\u54e1\u9762\u81e8\u7684\u4e00\u5927\u6311\u6230\u3002Redis\u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u5167\u5b58\u6578\u64da\u5eab\uff0c\u56e0\u5176\u5feb\u901f\u7684\u6578\u64da\u8b80\u53d6\u548c\u5beb\u5165\u80fd\u529b\uff0c\u8d8a\u4f86\u8d8a\u53d7\u5230\u958b\u767c\u8005\u7684\u9752\u775e\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5229\u7528Redis\u7684\u8a2a\u554f\u4ee3\u7406\u4f86\u63d0\u5347\u670d\u52d9\u6027\u80fd\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afredis%e8%a8%aa%e5%95%8f%e4%bb%a3%e7%90%86%ef%bc%9f-VWHkvOTiJQ\">\u4ec0\u9ebc\u662fRedis\u8a2a\u554f\u4ee3\u7406\uff1f<\/h2>\n<p>Redis\u8a2a\u554f\u4ee3\u7406\u662f\u4e00\u7a2e\u4e2d\u4ecb\u5c64\uff0c\u4e3b\u8981\u7528\u65bc\u5728\u5ba2\u6236\u7aef\u548cRedis\u670d\u52d9\u5668\u4e4b\u9593\u9032\u884c\u6578\u64da\u8acb\u6c42\u7684\u8f49\u767c\u3002\u9019\u7a2e\u67b6\u69cb\u7684\u4e3b\u8981\u76ee\u7684\u662f\u6e1b\u5c11\u76f4\u63a5\u8a2a\u554fRedis\u670d\u52d9\u5668\u7684\u8acb\u6c42\u6578\u91cf\uff0c\u5f9e\u800c\u964d\u4f4e\u670d\u52d9\u5668\u7684\u8ca0\u64d4\uff0c\u63d0\u9ad8\u6574\u9ad4\u6027\u80fd\u3002<\/p>\n<h2 id=\"redis%e7%9a%84%e5%84%aa%e5%8b%a2-VWHkvOTiJQ\">Redis\u7684\u512a\u52e2<\/h2>\n<ul>\n<li><strong>\u9ad8\u6027\u80fd\uff1a<\/strong>Redis\u80fd\u5920\u5728\u5167\u5b58\u4e2d\u9032\u884c\u6578\u64da\u64cd\u4f5c\uff0c\u9019\u4f7f\u5f97\u5176\u8b80\u53d6\u548c\u5beb\u5165\u901f\u5ea6\u6975\u5feb\uff0c\u901a\u5e38\u5728\u6beb\u79d2\u7d1a\u5225\u3002<\/li>\n<li><strong>\u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff1a<\/strong>Redis\u4e0d\u50c5\u652f\u6301\u5b57\u7b26\u4e32\uff0c\u9084\u652f\u6301\u54c8\u5e0c\u3001\u5217\u8868\u3001\u96c6\u5408\u7b49\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff0c\u9019\u4f7f\u5f97\u5b83\u5728\u8655\u7406\u8907\u96dc\u6578\u64da\u6642\u66f4\u52a0\u9748\u6d3b\u3002<\/li>\n<li><strong>\u6301\u4e45\u5316\u9078\u9805\uff1a<\/strong>Redis\u63d0\u4f9b\u591a\u7a2e\u6301\u4e45\u5316\u6a5f\u5236\uff0c\u80fd\u5920\u5728\u7cfb\u7d71\u91cd\u555f\u5f8c\u6062\u5fa9\u6578\u64da\uff0c\u9019\u5c0d\u65bc\u9700\u8981\u9ad8\u53ef\u7528\u6027\u7684\u61c9\u7528\u5c24\u70ba\u91cd\u8981\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%af%a6%e7%8f%beredis%e8%a8%aa%e5%95%8f%e4%bb%a3%e7%90%86-VWHkvOTiJQ\">\u5982\u4f55\u5be6\u73feRedis\u8a2a\u554f\u4ee3\u7406<\/h2>\n<p>\u5be6\u73feRedis\u8a2a\u554f\u4ee3\u7406\u7684\u904e\u7a0b\u53ef\u4ee5\u5206\u70ba\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e8%a8%ad%e7%bd%aeredis%e6%9c%8d%e5%8b%99%e5%99%a8-VWHkvOTiJQ\">1. \u8a2d\u7f6eRedis\u670d\u52d9\u5668<\/h3>\n<p>\u9996\u5148\uff0c\u9700\u8981\u5728\u670d\u52d9\u5668\u4e0a\u5b89\u88dd\u548c\u914d\u7f6eRedis\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5728Ubuntu\u4e0a\u5b89\u88ddRedis\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install redis-server<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u78ba\u4fddRedis\u670d\u52d9\u6b63\u5728\u904b\u884c\uff1a<\/p>\n<pre><code>sudo systemctl start redis\nsudo systemctl enable redis<\/code><\/pre>\n<h3 id=\"2-%e9%85%8d%e7%bd%ae%e8%a8%aa%e5%95%8f%e4%bb%a3%e7%90%86-VWHkvOTiJQ\">2. \u914d\u7f6e\u8a2a\u554f\u4ee3\u7406<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u9700\u8981\u8a2d\u7f6e\u4e00\u500b\u8a2a\u554f\u4ee3\u7406\u3002\u53ef\u4ee5\u4f7f\u7528Nginx\u4f5c\u70ba\u53cd\u5411\u4ee3\u7406\uff0c\u5c07\u8acb\u6c42\u8f49\u767c\u5230Redis\u670d\u52d9\u5668\u3002\u4ee5\u4e0b\u662fNginx\u7684\u57fa\u672c\u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n<pre><code>server {\n    listen 80;\n    server_name yourdomain.com;\n\n    location \/redis {\n        proxy_pass http:\/\/127.0.0.1:6379;\n        proxy_set_header Host $host;\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n    }\n}<\/code><\/pre>\n<h3 id=\"3-%e6%b8%ac%e8%a9%a6%e8%a8%aa%e5%95%8f%e4%bb%a3%e7%90%86-VWHkvOTiJQ\">3. \u6e2c\u8a66\u8a2a\u554f\u4ee3\u7406<\/h3>\n<p>\u914d\u7f6e\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528Redis\u5ba2\u6236\u7aef\u9032\u884c\u6e2c\u8a66\uff0c\u78ba\u4fdd\u8a2a\u554f\u4ee3\u7406\u6b63\u5e38\u5de5\u4f5c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u6e2c\u8a66\uff1a<\/p>\n<pre><code>redis-cli -h yourdomain.com -p 80 ping<\/code><\/pre>\n<p>\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u61c9\u8a72\u6703\u6536\u5230&#8221;PONG&#8221;\u7684\u56de\u61c9\u3002<\/p>\n<h2 id=\"%e6%80%a7%e8%83%bd%e6%8f%90%e5%8d%87%e7%9a%84%e6%95%88%e6%9e%9c-VWHkvOTiJQ\">\u6027\u80fd\u63d0\u5347\u7684\u6548\u679c<\/h2>\n<p>\u901a\u904e\u4f7f\u7528Redis\u8a2a\u554f\u4ee3\u7406\uff0c\u53ef\u4ee5\u986f\u8457\u6e1b\u5c11\u76f4\u63a5\u8a2a\u554fRedis\u670d\u52d9\u5668\u7684\u8acb\u6c42\u6578\u91cf\uff0c\u5f9e\u800c\u964d\u4f4e\u670d\u52d9\u5668\u7684\u8ca0\u64d4\u3002\u9019\u4e0d\u50c5\u63d0\u9ad8\u4e86\u6578\u64da\u8a2a\u554f\u7684\u901f\u5ea6\uff0c\u9084\u80fd\u5920\u5728\u9ad8\u4e26\u767c\u7684\u60c5\u6cc1\u4e0b\u4fdd\u6301\u7cfb\u7d71\u7684\u7a69\u5b9a\u6027\u3002\u6b64\u5916\uff0c\u8a2a\u554f\u4ee3\u7406\u9084\u53ef\u4ee5\u5be6\u73fe\u8ca0\u8f09\u5747\u8861\uff0c\u9032\u4e00\u6b65\u63d0\u5347\u7cfb\u7d71\u7684\u6027\u80fd\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-VWHkvOTiJQ\">\u7d50\u8ad6<\/h2>\n<p>\u5229\u7528Redis\u7684\u8a2a\u554f\u4ee3\u7406\u53ef\u4ee5\u6709\u6548\u63d0\u5347\u670d\u52d9\u6027\u80fd\uff0c\u7279\u5225\u662f\u5728\u9ad8\u6d41\u91cf\u7684\u61c9\u7528\u5834\u666f\u4e2d\u3002\u901a\u904e\u5408\u7406\u7684\u914d\u7f6e\u548c\u512a\u5316\uff0c\u4f01\u696d\u53ef\u4ee5\u5728\u4e0d\u589e\u52a0\u786c\u9ad4\u6210\u672c\u7684\u60c5\u6cc1\u4e0b\uff0c\u986f\u8457\u63d0\u9ad8\u7cfb\u7d71\u7684\u97ff\u61c9\u901f\u5ea6\u548c\u7a69\u5b9a\u6027\u3002\u5c0d\u65bc\u5e0c\u671b\u63d0\u5347\u670d\u52d9\u6027\u80fd\u7684\u4f01\u696d\u4f86\u8aaa\uff0cRedis\u8a2a\u554f\u4ee3\u7406\u7121\u7591\u662f\u4e00\u500b\u503c\u5f97\u8003\u616e\u7684\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc<em><a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a><\/em>\u548c<em><a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a><\/em>\u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5982\u4f55\u5229\u7528Redis\u8a2a\u554f\u4ee3\u7406\u63d0\u5347\u670d\u52d9\u6027\u80fd\uff0c\u512a\u5316\u6578\u64da\u5b58\u53d6\u6548\u7387\uff0c\u5be6\u73fe\u5feb\u901f\u97ff\u61c9\u548c\u9ad8\u6548\u80fd\u61c9\u7528\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-167171","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/167171","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=167171"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/167171\/revisions"}],"predecessor-version":[{"id":167172,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/167171\/revisions\/167172"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=167171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=167171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=167171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}