{"id":185086,"date":"2024-11-10T18:37:20","date_gmt":"2024-11-10T10:37:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/185086\/"},"modified":"2024-11-10T18:37:21","modified_gmt":"2024-11-10T10:37:21","slug":"%e4%bd%bf%e7%94%a8redis%e6%8f%90%e5%8d%87%e7%b6%b2%e7%ab%99%e6%80%a7%e8%83%bd%e7%9a%84%e6%9c%89%e6%95%88%e4%b9%8b%e9%81%93%ef%bc%88%e7%b6%b2%e7%ab%99%e4%bd%bf%e7%94%a8redis%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/185086\/","title":{"rendered":"\u4f7f\u7528Redis\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u7684\u6709\u6548\u4e4b\u9053\uff08\u7db2\u7ad9\u4f7f\u7528redis\uff09"},"content":{"rendered":"<h1 id=\"%e4%bd%bf%e7%94%a8redis%e6%8f%90%e5%8d%87%e7%b6%b2%e7%ab%99%e6%80%a7%e8%83%bd%e7%9a%84%e6%9c%89%e6%95%88%e4%b9%8b%e9%81%93-RRYcqOqJwO\">\u4f7f\u7528Redis\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u7684\u6709\u6548\u4e4b\u9053<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u7db2\u7ad9\u6027\u80fd\u5c0d\u65bc\u7528\u6236\u9ad4\u9a57\u548c\u641c\u7d22\u5f15\u64ce\u6392\u540d\u81f3\u95dc\u91cd\u8981\u3002\u96a8\u8457\u7528\u6236\u5c0d\u7db2\u7ad9\u901f\u5ea6\u548c\u97ff\u61c9\u6642\u9593\u7684\u671f\u671b\u4e0d\u65b7\u63d0\u9ad8\uff0c\u8a31\u591a\u7db2\u7ad9\u7ba1\u7406\u54e1\u958b\u59cb\u5c0b\u6c42\u6709\u6548\u7684\u89e3\u6c7a\u65b9\u6848\u4f86\u512a\u5316\u5176\u7db2\u7ad9\u6027\u80fd\u3002Redis\uff0c\u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u5167\u5b58\u6578\u64da\u5eab\uff0c\u5df2\u6210\u70ba\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u7684\u71b1\u9580\u9078\u64c7\u4e4b\u4e00\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u4f7f\u7528Redis\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u7684\u6709\u6548\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afredis%ef%bc%9f-RRYcqOqJwO\">\u4ec0\u9ebc\u662fRedis\uff1f<\/h2>\n<p>Redis\uff08Remote Dictionary Server\uff09\u662f\u4e00\u7a2e\u958b\u6e90\u7684\u9ad8\u6027\u80fd\u9375\u503c\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\u7531\u65bc\u5176\u5728\u5167\u5b58\u4e2d\u64cd\u4f5c\u6578\u64da\u7684\u7279\u6027\uff0cRedis\u80fd\u5920\u63d0\u4f9b\u6975\u5feb\u7684\u6578\u64da\u8b80\u53d6\u548c\u5beb\u5165\u901f\u5ea6\uff0c\u9019\u4f7f\u5f97\u5b83\u6210\u70ba\u7de9\u5b58\u89e3\u6c7a\u65b9\u6848\u7684\u7406\u60f3\u9078\u64c7\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%81%b8%e6%93%87redis%ef%bc%9f-RRYcqOqJwO\">\u70ba\u4ec0\u9ebc\u9078\u64c7Redis\uff1f<\/h2>\n<ul>\n<li><strong>\u9ad8\u6027\u80fd\uff1a<\/strong>Redis\u7684\u6578\u64da\u64cd\u4f5c\u901f\u5ea6\u975e\u5e38\u5feb\uff0c\u80fd\u5920\u5728\u6beb\u79d2\u7d1a\u5225\u5167\u5b8c\u6210\u8b80\u53d6\u548c\u5beb\u5165\uff0c\u9019\u5c0d\u65bc\u9700\u8981\u5feb\u901f\u97ff\u61c9\u7684\u7db2\u7ad9\u81f3\u95dc\u91cd\u8981\u3002<\/li>\n<li><strong>\u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff1a<\/strong>Redis\u4e0d\u50c5\u50c5\u662f\u9375\u503c\u5b58\u5132\uff0c\u9084\u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff0c\u9019\u4f7f\u5f97\u5b83\u80fd\u5920\u9748\u6d3b\u61c9\u5c0d\u4e0d\u540c\u7684\u61c9\u7528\u5834\u666f\u3002<\/li>\n<li><strong>\u6301\u4e45\u5316\u9078\u9805\uff1a<\/strong>Redis\u63d0\u4f9b\u591a\u7a2e\u6301\u4e45\u5316\u9078\u9805\uff0c\u80fd\u5920\u5728\u7cfb\u7d71\u91cd\u555f\u5f8c\u6062\u5fa9\u6578\u64da\uff0c\u9019\u5c0d\u65bc\u9700\u8981\u6578\u64da\u6301\u4e45\u6027\u7684\u61c9\u7528\u975e\u5e38\u91cd\u8981\u3002<\/li>\n<li><strong>\u5206\u4f48\u5f0f\u652f\u6301\uff1a<\/strong>Redis\u652f\u6301\u4e3b\u5f9e\u8907\u88fd\u548c\u5206\u7247\uff0c\u80fd\u5920\u8f15\u9b06\u64f4\u5c55\u4ee5\u61c9\u5c0d\u9ad8\u6d41\u91cf\u7684\u9700\u6c42\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8redis%e6%8f%90%e5%8d%87%e7%b6%b2%e7%ab%99%e6%80%a7%e8%83%bd-RRYcqOqJwO\">\u5982\u4f55\u4f7f\u7528Redis\u63d0\u5347\u7db2\u7ad9\u6027\u80fd<\/h2>\n<h3 id=\"1-%e7%b7%a9%e5%ad%98%e9%9d%9c%e6%85%8b%e5%85%a7%e5%ae%b9-RRYcqOqJwO\">1. \u7de9\u5b58\u975c\u614b\u5167\u5bb9<\/h3>\n<p>\u7db2\u7ad9\u4e2d\u7684\u975c\u614b\u5167\u5bb9\uff08\u5982\u5716\u7247\u3001CSS\u548cJavaScript\u6587\u4ef6\uff09\u901a\u5e38\u4e0d\u6703\u983b\u7e41\u8b8a\u52d5\u3002\u4f7f\u7528Redis\u4f5c\u70ba\u7de9\u5b58\u5c64\uff0c\u53ef\u4ee5\u5c07\u9019\u4e9b\u975c\u614b\u5167\u5bb9\u5b58\u5132\u5728\u5167\u5b58\u4e2d\uff0c\u5f9e\u800c\u6e1b\u5c11\u5c0d\u5f8c\u7aef\u4f3a\u670d\u5668\u7684\u8acb\u6c42\uff0c\u63d0\u9ad8\u52a0\u8f09\u901f\u5ea6\u3002<\/p>\n<pre><code>SET image:logo \"http:\/\/example.com\/logo.png\"<\/code><\/pre>\n<h3 id=\"2-%e7%b7%a9%e5%ad%98%e6%95%b8%e6%93%9a%e5%ba%ab%e6%9f%a5%e8%a9%a2%e7%b5%90%e6%9e%9c-RRYcqOqJwO\">2. \u7de9\u5b58\u6578\u64da\u5eab\u67e5\u8a62\u7d50\u679c<\/h3>\n<p>\u5c0d\u65bc\u9700\u8981\u983b\u7e41\u67e5\u8a62\u7684\u6578\u64da\uff0c\u5c07\u67e5\u8a62\u7d50\u679c\u7de9\u5b58\u5230Redis\u4e2d\u53ef\u4ee5\u986f\u8457\u6e1b\u5c11\u6578\u64da\u5eab\u7684\u8ca0\u64d4\u3002\u4f8b\u5982\uff0c\u7576\u7528\u6236\u8acb\u6c42\u67d0\u500b\u7522\u54c1\u7684\u8a73\u7d30\u4fe1\u606f\u6642\uff0c\u53ef\u4ee5\u5148\u6aa2\u67e5Redis\u4e2d\u662f\u5426\u5b58\u5728\u8a72\u4fe1\u606f\uff0c\u5982\u679c\u5b58\u5728\u5247\u76f4\u63a5\u8fd4\u56de\uff0c\u5426\u5247\u518d\u67e5\u8a62\u6578\u64da\u5eab\u4e26\u5c07\u7d50\u679c\u5b58\u5165Redis\u3002<\/p>\n<pre><code>GET product:123<\/code><\/pre>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8redis%e4%bd%9c%e7%82%ba%e6%9c%83%e8%a9%b1%e5%ad%98%e5%84%b2-RRYcqOqJwO\">3. \u4f7f\u7528Redis\u4f5c\u70ba\u6703\u8a71\u5b58\u5132<\/h3>\n<p>\u5728\u8a31\u591a\u7db2\u7ad9\u4e2d\uff0c\u7528\u6236\u6703\u8a71\u4fe1\u606f\u9700\u8981\u88ab\u5feb\u901f\u8b80\u53d6\u548c\u5beb\u5165\u3002\u4f7f\u7528Redis\u4f5c\u70ba\u6703\u8a71\u5b58\u5132\u53ef\u4ee5\u63d0\u9ad8\u6703\u8a71\u7ba1\u7406\u7684\u6548\u7387\uff0c\u7279\u5225\u662f\u5728\u9ad8\u6d41\u91cf\u7684\u60c5\u6cc1\u4e0b\u3002<\/p>\n<pre><code>SET session:userid123 \"user_data\"<\/code><\/pre>\n<h3 id=\"4-%e5%af%a6%e6%99%82%e6%95%b8%e6%93%9a%e8%99%95%e7%90%86-RRYcqOqJwO\">4. \u5be6\u6642\u6578\u64da\u8655\u7406<\/h3>\n<p>Redis\u7684\u767c\u5e03\/\u8a02\u95b1\u529f\u80fd\u4f7f\u5176\u6210\u70ba\u5be6\u6642\u6578\u64da\u8655\u7406\u7684\u7406\u60f3\u9078\u64c7\u3002\u7db2\u7ad9\u53ef\u4ee5\u5229\u7528\u9019\u4e00\u7279\u6027\u4f86\u5be6\u73fe\u5373\u6642\u901a\u77e5\u3001\u804a\u5929\u61c9\u7528\u7b49\u529f\u80fd\uff0c\u5f9e\u800c\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<pre><code>PUBLISH channel \"message\"<\/code><\/pre>\n<h2 id=\"%e7%b5%90%e8%ab%96-RRYcqOqJwO\">\u7d50\u8ad6<\/h2>\n<p>\u4f7f\u7528Redis\u4f5c\u70ba\u7db2\u7ad9\u6027\u80fd\u63d0\u5347\u7684\u5de5\u5177\uff0c\u80fd\u5920\u6709\u6548\u5730\u6e1b\u5c11\u5ef6\u9072\uff0c\u63d0\u9ad8\u97ff\u61c9\u901f\u5ea6\uff0c\u4e26\u6e1b\u8f15\u5f8c\u7aef\u4f3a\u670d\u5668\u7684\u8ca0\u64d4\u3002\u7121\u8ad6\u662f\u7de9\u5b58\u975c\u614b\u5167\u5bb9\u3001\u67e5\u8a62\u7d50\u679c\uff0c\u9084\u662f\u7528\u4f5c\u6703\u8a71\u5b58\u5132\uff0cRedis\u90fd\u80fd\u63d0\u4f9b\u986f\u8457\u7684\u6027\u80fd\u512a\u52e2\u3002\u96a8\u8457\u7db2\u7ad9\u6d41\u91cf\u7684\u589e\u9577\uff0c\u9078\u64c7\u5408\u9069\u7684\u6280\u8853\u4f86\u512a\u5316\u6027\u80fd\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002\u5c0d\u65bc\u5e0c\u671b\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u7684\u4f01\u696d\u548c\u958b\u767c\u8005\u4f86\u8aaa\uff0cRedis\u7121\u7591\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\u90e8\u7f72Redis\uff0cServer.HK\u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u5e6b\u52a9\u60a8\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\uff0c\u6eff\u8db3\u696d\u52d9\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u4f7f\u7528Redis\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u7684\u6709\u6548\u7b56\u7565\uff0c\u512a\u5316\u6578\u64da\u5b58\u53d6\u901f\u5ea6\uff0c\u589e\u5f37\u7528\u6236\u9ad4\u9a57\uff0c\u5be6\u73fe\u9ad8\u6548\u80fd\u7db2\u7ad9\u904b\u884c\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-185086","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/185086","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=185086"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/185086\/revisions"}],"predecessor-version":[{"id":185087,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/185086\/revisions\/185087"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=185086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=185086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=185086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}