{"id":116802,"date":"2024-10-24T18:09:13","date_gmt":"2024-10-24T10:09:13","guid":{"rendered":"https:\/\/server.hk\/cnblog\/116802\/"},"modified":"2024-10-24T18:09:14","modified_gmt":"2024-10-24T10:09:14","slug":"redis-%e5%bf%ab%e5%8f%96%e8%ae%93%e7%b6%b2%e7%ab%99%e5%89%8d%e5%8d%81%e9%a0%81%e6%95%88%e7%8e%87%e7%9e%ac%e9%96%93%e6%8f%90%e5%8d%87","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/116802\/","title":{"rendered":"Redis \u5feb\u53d6\u8b93\u7db2\u7ad9\u524d\u5341\u9801\u6548\u7387\u77ac\u9593\u63d0\u5347"},"content":{"rendered":"<h1 id=\"redis-%e5%bf%ab%e5%8f%96%e8%ae%93%e7%b6%b2%e7%ab%99%e5%89%8d%e5%8d%81%e9%a0%81%e6%95%88%e7%8e%87%e7%9e%ac%e9%96%93%e6%8f%90%e5%8d%87-AziAcEaYPN\">Redis \u5feb\u53d6\u8b93\u7db2\u7ad9\u524d\u5341\u9801\u6548\u7387\u77ac\u9593\u63d0\u5347<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u4f4d\u6642\u4ee3\uff0c\u7db2\u7ad9\u7684\u52a0\u8f09\u901f\u5ea6\u5c0d\u65bc\u7528\u6236\u9ad4\u9a57\u548c\u641c\u7d22\u5f15\u64ce\u6392\u540d\u81f3\u95dc\u91cd\u8981\u3002\u6839\u64da\u7814\u7a76\uff0c\u7db2\u7ad9\u52a0\u8f09\u6642\u9593\u6bcf\u5ef6\u9072\u4e00\u79d2\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u8f49\u63db\u7387\u4e0b\u964d\u9ad8\u9054 7%\u3002\u56e0\u6b64\uff0c\u512a\u5316\u7db2\u7ad9\u6027\u80fd\u6210\u70ba\u4e86\u6bcf\u500b\u7db2\u7ad9\u7ba1\u7406\u8005\u7684\u9996\u8981\u4efb\u52d9\u4e4b\u4e00\u3002Redis \u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u5feb\u53d6\u89e3\u6c7a\u65b9\u6848\uff0c\u80fd\u5920\u986f\u8457\u63d0\u5347\u7db2\u7ad9\u7684\u52a0\u8f09\u901f\u5ea6\uff0c\u7279\u5225\u662f\u5728\u524d\u5341\u9801\u7684\u6548\u7387\u4e0a\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-redis%ef%bc%9f-AziAcEaYPN\">\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\u7b49\u3002\u5b83\u901a\u5e38\u7528\u4f5c\u6578\u64da\u5eab\u3001\u5feb\u53d6\u548c\u6d88\u606f\u4ee3\u7406\u3002\u7531\u65bc\u5176\u9ad8\u6548\u7684\u6027\u80fd\u548c\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\uff0cRedis \u6210\u70ba\u4e86\u8a31\u591a\u9ad8\u6d41\u91cf\u7db2\u7ad9\u7684\u9996\u9078\u5feb\u53d6\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h2 id=\"redis-%e7%9a%84%e5%b7%a5%e4%bd%9c%e5%8e%9f%e7%90%86-AziAcEaYPN\">Redis \u7684\u5de5\u4f5c\u539f\u7406<\/h2>\n<p>Redis \u901a\u904e\u5c07\u6578\u64da\u5b58\u5132\u5728\u5167\u5b58\u4e2d\u4f86\u52a0\u5feb\u6578\u64da\u7684\u8b80\u53d6\u901f\u5ea6\u3002\u7576\u7528\u6236\u8acb\u6c42\u67d0\u500b\u9801\u9762\u6642\uff0cRedis \u9996\u5148\u6aa2\u67e5\u8a72\u9801\u9762\u662f\u5426\u5df2\u7d93\u88ab\u5feb\u53d6\u3002\u5982\u679c\u662f\uff0c\u5247\u76f4\u63a5\u5f9e\u5167\u5b58\u4e2d\u8fd4\u56de\u6578\u64da\uff0c\u9019\u6a23\u53ef\u4ee5\u5927\u5e45\u5ea6\u6e1b\u5c11\u5f9e\u6578\u64da\u5eab\u4e2d\u67e5\u8a62\u7684\u6642\u9593\u3002\u82e5\u8a72\u9801\u9762\u4e0d\u5728\u5feb\u53d6\u4e2d\uff0cRedis \u5c07\u5f9e\u6578\u64da\u5eab\u4e2d\u7372\u53d6\u6578\u64da\u4e26\u5c07\u5176\u5b58\u5132\u5728\u5feb\u53d6\u4e2d\uff0c\u4ee5\u4fbf\u672a\u4f86\u7684\u8acb\u6c42\u80fd\u5920\u66f4\u5feb\u5730\u97ff\u61c9\u3002<\/p>\n<h2 id=\"redis-%e5%bf%ab%e5%8f%96%e7%9a%84%e5%84%aa%e5%8b%a2-AziAcEaYPN\">Redis \u5feb\u53d6\u7684\u512a\u52e2<\/h2>\n<ul>\n<li><strong>\u9ad8\u6548\u6027\u80fd\uff1a<\/strong>Redis \u7684\u5167\u5b58\u5b58\u5132\u7279\u6027\u4f7f\u5176\u80fd\u5920\u4ee5\u6beb\u79d2\u7d1a\u7684\u901f\u5ea6\u8655\u7406\u8acb\u6c42\uff0c\u9019\u5c0d\u65bc\u9700\u8981\u5feb\u901f\u97ff\u61c9\u7684\u7db2\u7ad9\u81f3\u95dc\u91cd\u8981\u3002<\/li>\n<li><strong>\u6e1b\u5c11\u6578\u64da\u5eab\u8ca0\u64d4\uff1a<\/strong>\u901a\u904e\u5feb\u53d6\u5e38\u7528\u6578\u64da\uff0cRedis \u80fd\u5920\u986f\u8457\u6e1b\u5c11\u5c0d\u5f8c\u7aef\u6578\u64da\u5eab\u7684\u8acb\u6c42\uff0c\u5f9e\u800c\u63d0\u9ad8\u6574\u9ad4\u7cfb\u7d71\u7684\u7a69\u5b9a\u6027\u548c\u53ef\u64f4\u5c55\u6027\u3002<\/li>\n<li><strong>\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\uff1a<\/strong>Redis \u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff0c\u9019\u4f7f\u5f97\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u5177\u9ad4\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 Redis \u4e3b\u8981\u7528\u4f5c\u5167\u5b58\u5feb\u53d6\uff0c\u4f46\u5b83\u4e5f\u63d0\u4f9b\u4e86\u6578\u64da\u6301\u4e45\u5316\u7684\u9078\u9805\uff0c\u78ba\u4fdd\u6578\u64da\u4e0d\u6703\u56e0\u70ba\u7cfb\u7d71\u5d29\u6f70\u800c\u4e1f\u5931\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%9c%a8%e7%b6%b2%e7%ab%99%e4%b8%ad%e5%af%a6%e7%8f%be-redis-%e5%bf%ab%e5%8f%96-AziAcEaYPN\">\u5982\u4f55\u5728\u7db2\u7ad9\u4e2d\u5be6\u73fe Redis \u5feb\u53d6<\/h2>\n<p>\u8981\u5728\u7db2\u7ad9\u4e2d\u5be6\u73fe Redis \u5feb\u53d6\uff0c\u9996\u5148\u9700\u8981\u5b89\u88dd Redis \u670d\u52d9\u5668\u3002\u4ee5\u4e0b\u662f\u57fa\u672c\u7684\u5b89\u88dd\u6b65\u9a5f\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install redis-server\n<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5 Redis \u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl start redis\n<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5728\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\u4e2d\u96c6\u6210 Redis\u3002\u4ee5 PHP \u70ba\u4f8b\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 Predis \u5eab\u4f86\u9023\u63a5 Redis\uff1a<\/p>\n<pre><code>require 'predis\/autoload.php';\nPredisAutoloader::register();\n\n$client = new PredisClient();\n<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u78bc\u5c07\u6578\u64da\u5b58\u5132\u5230 Redis \u4e2d\uff1a<\/p>\n<pre><code>$client-&gt;set('key', 'value');\n<\/code><\/pre>\n<p>\u8981\u5f9e Redis \u4e2d\u7372\u53d6\u6578\u64da\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>$value = $client-&gt;get('key');\n<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-AziAcEaYPN\">\u7d50\u8ad6<\/h2>\n<p>Redis \u5feb\u53d6\u6280\u8853\u80fd\u5920\u986f\u8457\u63d0\u5347\u7db2\u7ad9\u7684\u52a0\u8f09\u901f\u5ea6\u548c\u6027\u80fd\uff0c\u7279\u5225\u662f\u5728\u8655\u7406\u9ad8\u6d41\u91cf\u7684\u60c5\u6cc1\u4e0b\u3002\u901a\u904e\u6709\u6548\u5730\u7ba1\u7406\u6578\u64da\u5b58\u5132\u548c\u6e1b\u5c11\u5c0d\u6578\u64da\u5eab\u7684\u8acb\u6c42\uff0cRedis \u4e0d\u50c5\u63d0\u9ad8\u4e86\u7528\u6236\u9ad4\u9a57\uff0c\u9084\u589e\u5f37\u4e86\u7db2\u7ad9\u7684\u7a69\u5b9a\u6027\u3002\u5c0d\u65bc\u5e0c\u671b\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u7684\u958b\u767c\u8005\u4f86\u8aaa\uff0cRedis \u662f\u4e00\u500b\u503c\u5f97\u8003\u616e\u7684\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u7db2\u7ad9\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u5be6\u73fe\u6700\u4f73\u6027\u80fd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis \u5feb\u53d6\u63d0\u5347\u7db2\u7ad9\u524d\u5341\u9801\u6548\u7387\uff0c\u986f\u8457\u52a0\u5feb\u52a0\u8f09\u901f\u5ea6\uff0c\u512a\u5316\u7528\u6236\u9ad4\u9a57\uff0c\u8b93\u8a2a\u5ba2\u7559\u5b58\u7387\u5927\u5e45\u63d0\u5347\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-116802","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/116802","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=116802"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/116802\/revisions"}],"predecessor-version":[{"id":116803,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/116802\/revisions\/116803"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=116802"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=116802"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=116802"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}