{"id":129571,"date":"2024-10-26T22:38:23","date_gmt":"2024-10-26T14:38:23","guid":{"rendered":"https:\/\/server.hk\/cnblog\/129571\/"},"modified":"2024-10-26T22:38:24","modified_gmt":"2024-10-26T14:38:24","slug":"redis%e6%8c%ba%e4%b8%8a%e9%ab%98%e9%80%9f%e6%9c%8d%e5%8b%99%e4%b9%8b%e8%b7%af%ef%bc%88redis%e9%ab%98%e7%b4%9a%e6%9c%8d%e5%8b%99%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/129571\/","title":{"rendered":"Redis\u633a\u4e0a\u9ad8\u901f\u670d\u52d9\u4e4b\u8def\uff08redis\u9ad8\u7d1a\u670d\u52d9\uff09"},"content":{"rendered":"<h1 id=\"redis%e6%8c%ba%e4%b8%8a%e9%ab%98%e9%80%9f%e6%9c%8d%e5%8b%99%e4%b9%8b%e8%b7%af%ef%bc%88redis%e9%ab%98%e7%b4%9a%e6%9c%8d%e5%8b%99%ef%bc%89-xHgqkvUjSh\">Redis\u633a\u4e0a\u9ad8\u901f\u670d\u52d9\u4e4b\u8def\uff08redis\u9ad8\u7d1a\u670d\u52d9\uff09<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u6642\u4ee3\uff0c\u5feb\u901f\u4e14\u9ad8\u6548\u7684\u6578\u64da\u5b58\u53d6\u6210\u70ba\u4e86\u4f01\u696d\u6210\u529f\u7684\u95dc\u9375\u3002Redis\uff0c\u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6027\u80fd\u7684\u9375\u503c\u6578\u64da\u5eab\uff0c\u56e0\u5176\u5353\u8d8a\u7684\u6027\u80fd\u548c\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\uff0c\u9010\u6f38\u6210\u70ba\u8a31\u591a\u4f01\u696d\u7684\u9996\u9078\u3002\u672c\u6587\u5c07\u63a2\u8a0eRedis\u7684\u9ad8\u7d1a\u670d\u52d9\u53ca\u5176\u5728\u9ad8\u901f\u670d\u52d9\u4e2d\u7684\u61c9\u7528\u3002<\/p>\n<h2 id=\"redis%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-xHgqkvUjSh\">Redis\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>Redis\uff08Remote Dictionary Server\uff09\u662f\u4e00\u500b\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\u7b49\u3002\u5b83\u7684\u4e3b\u8981\u7279\u9ede\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u9ad8\u6027\u80fd\uff1aRedis\u80fd\u5920\u6bcf\u79d2\u8655\u7406\u6578\u5341\u842c\u6b21\u7684\u8b80\u5beb\u64cd\u4f5c\u3002<\/li>\n<li>\u6301\u4e45\u5316\uff1a\u652f\u6301\u5c07\u6578\u64da\u6301\u4e45\u5316\u5230\u78c1\u789f\uff0c\u78ba\u4fdd\u6578\u64da\u4e0d\u6703\u56e0\u70ba\u7cfb\u7d71\u5d29\u6f70\u800c\u4e1f\u5931\u3002<\/li>\n<li>\u9748\u6d3b\u6027\uff1a\u652f\u6301\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff0c\u80fd\u5920\u6eff\u8db3\u4e0d\u540c\u7684\u61c9\u7528\u9700\u6c42\u3002<\/li>\n<li>\u5206\u4f48\u5f0f\uff1a\u652f\u6301\u4e3b\u5f9e\u8907\u88fd\u548c\u5206\u7247\uff0c\u80fd\u5920\u8f15\u9b06\u64f4\u5c55\u3002<\/li>\n<\/ul>\n<h2 id=\"redis%e7%9a%84%e9%ab%98%e7%b4%9a%e6%9c%8d%e5%8b%99-xHgqkvUjSh\">Redis\u7684\u9ad8\u7d1a\u670d\u52d9<\/h2>\n<p>\u96a8\u8457\u4f01\u696d\u5c0d\u6578\u64da\u8655\u7406\u9700\u6c42\u7684\u589e\u52a0\uff0cRedis\u7684\u9ad8\u7d1a\u670d\u52d9\u9010\u6f38\u53d7\u5230\u91cd\u8996\u3002\u9019\u4e9b\u9ad8\u7d1a\u670d\u52d9\u4e3b\u8981\u5305\u62ec\uff1a<\/p>\n<h3 id=\"1-%e9%9b%86%e7%be%a4%e6%a8%a1%e5%bc%8f-xHgqkvUjSh\">1. \u96c6\u7fa4\u6a21\u5f0f<\/h3>\n<p>Redis\u96c6\u7fa4\u6a21\u5f0f\u5141\u8a31\u7528\u6236\u5c07\u6578\u64da\u5206\u6563\u5230\u591a\u500b\u7bc0\u9ede\u4e0a\uff0c\u9019\u6a23\u4e0d\u50c5\u63d0\u9ad8\u4e86\u6578\u64da\u7684\u53ef\u7528\u6027\uff0c\u9084\u80fd\u5920\u5be6\u73fe\u8ca0\u8f09\u5747\u8861\u3002\u7528\u6236\u53ef\u4ee5\u901a\u904e\u7c21\u55ae\u7684\u914d\u7f6e\u4f86\u8a2d\u7f6e\u96c6\u7fa4\uff0cRedis\u6703\u81ea\u52d5\u8655\u7406\u6578\u64da\u7684\u5206\u7247\u548c\u8def\u7531\u3002<\/p>\n<pre><code>redis-cli --cluster create 192.168.1.1:7000 192.168.1.2:7001 192.168.1.3:7002 --cluster-replicas 1<\/code><\/pre>\n<h3 id=\"2-%e4%ba%8b%e5%8b%99%e6%94%af%e6%8c%81-xHgqkvUjSh\">2. \u4e8b\u52d9\u652f\u6301<\/h3>\n<p>Redis\u652f\u6301\u4e8b\u52d9\u64cd\u4f5c\uff0c\u5141\u8a31\u7528\u6236\u5c07\u591a\u500b\u547d\u4ee4\u6253\u5305\u5728\u4e00\u8d77\u57f7\u884c\uff0c\u78ba\u4fdd\u9019\u4e9b\u547d\u4ee4\u8981\u9ebc\u5168\u90e8\u6210\u529f\uff0c\u8981\u9ebc\u5168\u90e8\u5931\u6557\u3002\u9019\u5c0d\u65bc\u9700\u8981\u539f\u5b50\u6027\u64cd\u4f5c\u7684\u61c9\u7528\u5834\u666f\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<pre><code>MULTI\nSET key1 value1\nSET key2 value2\nEXEC<\/code><\/pre>\n<h3 id=\"3-lua%e8%85%b3%e6%9c%ac%e6%94%af%e6%8c%81-xHgqkvUjSh\">3. Lua\u8173\u672c\u652f\u6301<\/h3>\n<p>Redis\u5167\u5efaLua\u8173\u672c\u652f\u6301\uff0c\u5141\u8a31\u7528\u6236\u5728\u670d\u52d9\u5668\u7aef\u57f7\u884c\u8907\u96dc\u7684\u64cd\u4f5c\uff0c\u6e1b\u5c11\u7db2\u7d61\u5ef6\u9072\u3002\u9019\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u61c9\u7528\u5834\u666f\u5c24\u70ba\u91cd\u8981\u3002<\/p>\n<pre><code>eval \"return redis.call('set', KEYS[1], ARGV[1])\" 1 key1 value1<\/code><\/pre>\n<h2 id=\"redis%e5%9c%a8%e9%ab%98%e9%80%9f%e6%9c%8d%e5%8b%99%e4%b8%ad%e7%9a%84%e6%87%89%e7%94%a8-xHgqkvUjSh\">Redis\u5728\u9ad8\u901f\u670d\u52d9\u4e2d\u7684\u61c9\u7528<\/h2>\n<p>Redis\u7684\u9ad8\u6027\u80fd\u7279\u6027\u4f7f\u5176\u5728\u591a\u500b\u9818\u57df\u4e2d\u5f97\u5230\u4e86\u5ee3\u6cdb\u61c9\u7528\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u5373\u6642\u6578\u64da\u5206\u6790\uff1a<\/strong>\u8a31\u591a\u4f01\u696d\u4f7f\u7528Redis\u4f86\u9032\u884c\u5373\u6642\u6578\u64da\u5206\u6790\uff0c\u5feb\u901f\u7372\u53d6\u7528\u6236\u884c\u70ba\u6578\u64da\u3002<\/li>\n<li><strong>\u7de9\u5b58\u7cfb\u7d71\uff1a<\/strong>Redis\u5e38\u88ab\u7528\u4f5c\u7de9\u5b58\u7cfb\u7d71\uff0c\u6e1b\u5c11\u5f8c\u7aef\u6578\u64da\u5eab\u7684\u8ca0\u64d4\uff0c\u63d0\u9ad8\u61c9\u7528\u7684\u97ff\u61c9\u901f\u5ea6\u3002<\/li>\n<li><strong>\u6d88\u606f\u968a\u5217\uff1a<\/strong>\u5229\u7528Redis\u7684\u5217\u8868\u7d50\u69cb\uff0c\u53ef\u4ee5\u8f15\u9b06\u5be6\u73fe\u9ad8\u6548\u7684\u6d88\u606f\u968a\u5217\u7cfb\u7d71\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-xHgqkvUjSh\">\u7d50\u8ad6<\/h2>\n<p>Redis\u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6027\u80fd\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\uff0c\u6191\u85c9\u5176\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\u548c\u9ad8\u7d1a\u670d\u52d9\uff0c\u5df2\u7d93\u5728\u9ad8\u901f\u670d\u52d9\u7684\u9818\u57df\u4e2d\u5c55\u73fe\u51fa\u5f37\u5927\u7684\u6f5b\u529b\u3002\u7121\u8ad6\u662f\u96c6\u7fa4\u6a21\u5f0f\u3001\u4e8b\u52d9\u652f\u6301\u9084\u662fLua\u8173\u672c\uff0c\u9019\u4e9b\u529f\u80fd\u90fd\u4f7f\u5f97Redis\u80fd\u5920\u6eff\u8db3\u73fe\u4ee3\u4f01\u696d\u5c0d\u6578\u64da\u8655\u7406\u7684\u9700\u6c42\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\u7528Redis\u4f86\u63d0\u5347\u60a8\u7684\u61c9\u7528\u6027\u80fd\u3002\u4e86\u89e3\u66f4\u591a\u95dc\u65bc\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u670d\u52d9\uff0c\u8b93\u60a8\u7684\u696d\u52d9\u5728\u6578\u64da\u8655\u7406\u4e0a\u66f4\u5177\u7af6\u722d\u529b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22Redis\u9ad8\u7d1a\u670d\u52d9\uff0c\u63d0\u5347\u6578\u64da\u8655\u7406\u901f\u5ea6\uff0c\u5be6\u73fe\u9ad8\u6548\u80fd\u61c9\u7528\uff0c\u52a9\u529b\u4f01\u696d\u5feb\u901f\u767c\u5c55\u8207\u5275\u65b0\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-129571","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/129571","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=129571"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/129571\/revisions"}],"predecessor-version":[{"id":129572,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/129571\/revisions\/129572"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=129571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=129571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=129571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}