{"id":97820,"date":"2024-10-20T21:24:16","date_gmt":"2024-10-20T13:24:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/97820\/"},"modified":"2024-10-20T21:24:17","modified_gmt":"2024-10-20T13:24:17","slug":"redis%e6%af%94%e9%97%9c%e4%bf%82%e6%95%b8%e6%93%9a%e5%ba%ab%e6%9b%b4%e5%bf%ab%e7%9a%84%e9%80%9f%e5%ba%a6%ef%bc%88redis%e6%af%94%e9%97%9c%e4%bf%82%e6%95%b8%e6%93%9a%e5%ba%ab%e5%bf%ab%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/97820\/","title":{"rendered":"Redis\u6bd4\u95dc\u4fc2\u6578\u64da\u5eab\u66f4\u5feb\u7684\u901f\u5ea6\uff08redis\u6bd4\u95dc\u4fc2\u6578\u64da\u5eab\u5feb\uff09"},"content":{"rendered":"<h1 id=\"redis%e6%af%94%e9%97%9c%e4%bf%82%e6%95%b8%e6%93%9a%e5%ba%ab%e6%9b%b4%e5%bf%ab%e7%9a%84%e9%80%9f%e5%ba%a6-QwBYjoTniy\">Redis\u6bd4\u95dc\u4fc2\u6578\u64da\u5eab\u66f4\u5feb\u7684\u901f\u5ea6<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u8655\u7406\u74b0\u5883\u4e2d\uff0c\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u7cfb\u7d71\u5c0d\u65bc\u61c9\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u81f3\u95dc\u91cd\u8981\u3002Redis\u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u9375\u503c\u5b58\u5132\u7cfb\u7d71\uff0c\u8207\u50b3\u7d71\u7684\u95dc\u4fc2\u6578\u64da\u5eab\u76f8\u6bd4\uff0c\u63d0\u4f9b\u4e86\u66f4\u5feb\u7684\u6578\u64da\u5b58\u53d6\u901f\u5ea6\u3002\u672c\u6587\u5c07\u63a2\u8a0eRedis\u7684\u901f\u5ea6\u512a\u52e2\u53ca\u5176\u80cc\u5f8c\u7684\u6280\u8853\u539f\u7406\u3002<\/p>\n<h2 id=\"redis%e7%9a%84%e5%9f%ba%e6%9c%ac%e7%89%b9%e6%80%a7-QwBYjoTniy\">Redis\u7684\u57fa\u672c\u7279\u6027<\/h2>\n<p>Redis\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\u548c\u6709\u5e8f\u96c6\u5408\u3002\u5176\u4e3b\u8981\u7279\u9ede\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u5167\u5b58\u5b58\u5132\uff1a<\/strong>Redis\u5c07\u6578\u64da\u5b58\u5132\u5728\u5167\u5b58\u4e2d\uff0c\u9019\u4f7f\u5f97\u6578\u64da\u7684\u8b80\u53d6\u548c\u5beb\u5165\u901f\u5ea6\u6975\u5feb\u3002<\/li>\n<li><strong>\u6301\u4e45\u5316\u9078\u9805\uff1a<\/strong>\u96d6\u7136Redis\u4e3b\u8981\u662f\u5167\u5b58\u6578\u64da\u5eab\uff0c\u4f46\u5b83\u4e5f\u63d0\u4f9b\u4e86\u6301\u4e45\u5316\u9078\u9805\uff0c\u5141\u8a31\u7528\u6236\u5c07\u6578\u64da\u4fdd\u5b58\u5230\u78c1\u789f\u4e2d\u3002<\/li>\n<li><strong>\u9ad8\u6548\u7684\u6578\u64da\u7d50\u69cb\uff1a<\/strong>Redis\u652f\u6301\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<\/ul>\n<h2 id=\"%e9%80%9f%e5%ba%a6%e6%af%94%e8%bc%83%ef%bc%9aredis-vs-%e9%97%9c%e4%bf%82%e6%95%b8%e6%93%9a%e5%ba%ab-QwBYjoTniy\">\u901f\u5ea6\u6bd4\u8f03\uff1aRedis vs. \u95dc\u4fc2\u6578\u64da\u5eab<\/h2>\n<p>\u95dc\u4fc2\u6578\u64da\u5eab\uff08\u5982MySQL\u3001PostgreSQL\uff09\u901a\u5e38\u4f7f\u7528\u78c1\u789f\u5b58\u5132\u6578\u64da\uff0c\u9019\u5c0e\u81f4\u4e86\u76f8\u5c0d\u8f03\u6162\u7684\u6578\u64da\u5b58\u53d6\u901f\u5ea6\u3002\u4ee5\u4e0b\u662fRedis\u8207\u95dc\u4fc2\u6578\u64da\u5eab\u5728\u901f\u5ea6\u4e0a\u7684\u4e00\u4e9b\u5177\u9ad4\u6bd4\u8f03\uff1a<\/p>\n<h3 id=\"1-%e6%95%b8%e6%93%9a%e5%ad%98%e5%8f%96%e9%80%9f%e5%ba%a6-QwBYjoTniy\">1. \u6578\u64da\u5b58\u53d6\u901f\u5ea6<\/h3>\n<p>Redis\u7684\u6578\u64da\u5b58\u53d6\u901f\u5ea6\u901a\u5e38\u5728\u6beb\u79d2\u7d1a\u5225\uff0c\u751a\u81f3\u5fae\u79d2\u7d1a\u5225\u3002\u6839\u64da\u4e00\u4e9b\u57fa\u6e96\u6e2c\u8a66\uff0cRedis\u7684\u8b80\u53d6\u901f\u5ea6\u53ef\u9054\u5230\u6bcf\u79d2\u6578\u5341\u842c\u6b21\u8acb\u6c42\uff0c\u800c\u95dc\u4fc2\u6578\u64da\u5eab\u7684\u8b80\u53d6\u901f\u5ea6\u5247\u901a\u5e38\u5728\u6bcf\u79d2\u5e7e\u5343\u5230\u5e7e\u842c\u6b21\u8acb\u6c42\u4e4b\u9593\u3002<\/p>\n<pre><code>SET key \"value\"  # Redis\u547d\u4ee4\nGET key           # Redis\u547d\u4ee4\n<\/code><\/pre>\n<h3 id=\"2-%e8%a4%87%e9%9b%9c%e6%9f%a5%e8%a9%a2%e7%9a%84%e6%80%a7%e8%83%bd-QwBYjoTniy\">2. \u8907\u96dc\u67e5\u8a62\u7684\u6027\u80fd<\/h3>\n<p>\u95dc\u4fc2\u6578\u64da\u5eab\u5728\u8655\u7406\u8907\u96dc\u67e5\u8a62\u6642\uff0c\u901a\u5e38\u9700\u8981\u9032\u884c\u591a\u6b21\u78c1\u789f\u8b80\u53d6\u548c\u8a08\u7b97\uff0c\u9019\u6703\u589e\u52a0\u5ef6\u9072\u3002\u800cRedis\u5247\u53ef\u4ee5\u901a\u904e\u5176\u9ad8\u6548\u7684\u6578\u64da\u7d50\u69cb\u548c\u5167\u5b58\u5b58\u5132\uff0c\u5feb\u901f\u8fd4\u56de\u7d50\u679c\u3002\u4f8b\u5982\uff0c\u4f7f\u7528Redis\u7684\u96c6\u5408\u64cd\u4f5c\u53ef\u4ee5\u5728O(1)\u7684\u6642\u9593\u5167\u5b8c\u6210\u3002<\/p>\n<pre><code>SADD myset \"value1\" \"value2\"  # Redis\u96c6\u5408\u64cd\u4f5c\nSMEMBERS myset                  # \u7372\u53d6\u96c6\u5408\u4e2d\u7684\u6240\u6709\u5143\u7d20\n<\/code><\/pre>\n<h3 id=\"3-%e4%b8%a6%e7%99%bc%e8%99%95%e7%90%86%e8%83%bd%e5%8a%9b-QwBYjoTniy\">3. \u4e26\u767c\u8655\u7406\u80fd\u529b<\/h3>\n<p>Redis\u652f\u6301\u55ae\u7dda\u7a0b\u6a21\u578b\uff0c\u9019\u610f\u5473\u8457\u5b83\u5728\u8655\u7406\u8acb\u6c42\u6642\u4e0d\u6703\u56e0\u70ba\u4e0a\u4e0b\u6587\u5207\u63db\u800c\u7522\u751f\u984d\u5916\u7684\u5ef6\u9072\u3002\u76f8\u5c0d\u800c\u8a00\uff0c\u95dc\u4fc2\u6578\u64da\u5eab\u901a\u5e38\u9700\u8981\u591a\u7dda\u7a0b\u4f86\u8655\u7406\u4e26\u767c\u8acb\u6c42\uff0c\u9019\u53ef\u80fd\u6703\u5c0e\u81f4\u6027\u80fd\u74f6\u9838\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e5%a0%b4%e6%99%af-QwBYjoTniy\">\u4f7f\u7528\u5834\u666f<\/h2>\n<p>\u7531\u65bc\u5176\u9ad8\u6548\u7684\u6027\u80fd\uff0cRedis\u975e\u5e38\u9069\u5408\u7528\u65bc\u4ee5\u4e0b\u5834\u666f\uff1a<\/p>\n<ul>\n<li><strong>\u5be6\u6642\u6578\u64da\u5206\u6790\uff1a<\/strong>\u5982\u5373\u6642\u7d71\u8a08\u548c\u5831\u544a\u751f\u6210\u3002<\/li>\n<li><strong>\u7de9\u5b58\u7cfb\u7d71\uff1a<\/strong>\u7528\u65bc\u6e1b\u5c11\u5c0d\u5f8c\u7aef\u6578\u64da\u5eab\u7684\u8acb\u6c42\u3002<\/li>\n<li><strong>\u6d88\u606f\u968a\u5217\uff1a<\/strong>\u7528\u65bc\u8655\u7406\u9ad8\u983b\u7387\u7684\u6d88\u606f\u50b3\u905e\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-QwBYjoTniy\">\u7d50\u8ad6<\/h2>\n<p>\u7e3d\u7684\u4f86\u8aaa\uff0cRedis\u5728\u901f\u5ea6\u4e0a\u76f8\u5c0d\u65bc\u50b3\u7d71\u7684\u95dc\u4fc2\u6578\u64da\u5eab\u5177\u6709\u660e\u986f\u7684\u512a\u52e2\u3002\u5176\u5167\u5b58\u5b58\u5132\u3001\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\u4ee5\u53ca\u9ad8\u6548\u7684\u4e26\u767c\u8655\u7406\u80fd\u529b\uff0c\u4f7f\u5176\u6210\u70ba\u8a31\u591a\u61c9\u7528\u7a0b\u5e8f\u7684\u7406\u60f3\u9078\u64c7\u3002\u5c0d\u65bc\u9700\u8981\u5feb\u901f\u6578\u64da\u5b58\u53d6\u7684\u5834\u666f\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\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u90e8\u7f72Redis\uff0c\u4eab\u53d7\u66f4\u5feb\u7684\u6578\u64da\u8655\u7406\u901f\u5ea6\u548c\u9748\u6d3b\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis\u63d0\u4f9b\u6bd4\u95dc\u4fc2\u6578\u64da\u5eab\u66f4\u5feb\u7684\u6578\u64da\u5b58\u53d6\u901f\u5ea6\uff0c\u9069\u5408\u9ad8\u6548\u80fd\u61c9\u7528\u548c\u5373\u6642\u6578\u64da\u8655\u7406\u9700\u6c42\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-97820","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/97820","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=97820"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/97820\/revisions"}],"predecessor-version":[{"id":97821,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/97820\/revisions\/97821"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=97820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=97820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=97820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}