{"id":6374,"date":"2024-07-18T20:32:38","date_gmt":"2024-07-18T12:32:38","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6374"},"modified":"2024-07-18T20:32:38","modified_gmt":"2024-07-18T12:32:38","slug":"%e5%90%8e%e7%ab%af%e5%b7%a5%e7%a8%8b%e5%b8%88%e5%bf%85%e5%a4%87-redis-%e6%8a%80%e8%83%bd","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6374","title":{"rendered":"\u540e\u7aef\u5de5\u7a0b\u5e08\u5fc5\u5907 Redis \u6280\u80fd"},"content":{"rendered":"<p>Redis \u662f\u4e00\u79cd\u9ad8\u6027\u80fd\u7684\u952e\u503c\u5b58\u50a8\u6570\u636e\u5e93\uff0c\u5728\u540e\u7aef\u5f00\u53d1\u4e2d\u5e7f\u6cdb\u5e94\u7528\u3002\u4f5c\u4e3a\u540e\u7aef\u5de5\u7a0b\u5e08\uff0c\u638c\u63e1 Redis \u6280\u80fd\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4ee5\u4e0b\u662f\u540e\u7aef\u5de5\u7a0b\u5e08\u5fc5\u5907\u7684 Redis \u6280\u80fd\uff1a<\/p>\n<h3>1. \u57fa\u7840\u77e5\u8bc6<\/h3>\n<p><strong>\u6570\u636e\u7c7b\u578b<\/strong>\uff1a<\/p>\n<ul>\n<li><strong>\u5b57\u7b26\u4e32\uff08String\uff09<\/strong>\uff1a\u6700\u57fa\u672c\u7684\u6570\u636e\u7c7b\u578b\uff0c\u7528\u4e8e\u5b58\u50a8\u7b80\u5355\u7684\u952e\u503c\u5bf9\u3002<\/li>\n<li><strong>\u54c8\u5e0c\uff08Hash\uff09<\/strong>\uff1a\u7528\u4e8e\u5b58\u50a8\u952e\u503c\u5bf9\u7684\u96c6\u5408\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b58\u50a8\u5bf9\u8c61\u3002<\/li>\n<li><strong>\u5217\u8868\uff08List\uff09<\/strong>\uff1a\u7528\u4e8e\u5b58\u50a8\u6709\u5e8f\u7684\u5b57\u7b26\u4e32\u5217\u8868\uff0c\u53ef\u4ee5\u8fdb\u884c\u961f\u5217\u3001\u6808\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u96c6\u5408\uff08Set\uff09<\/strong>\uff1a\u7528\u4e8e\u5b58\u50a8\u4e0d\u91cd\u590d\u7684\u5b57\u7b26\u4e32\u96c6\u5408\uff0c\u652f\u6301\u96c6\u5408\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u6709\u5e8f\u96c6\u5408\uff08Sorted Set\uff09<\/strong>\uff1a\u7c7b\u4f3c\u96c6\u5408\uff0c\u4f46\u6bcf\u4e2a\u5143\u7d20\u5173\u8054\u4e00\u4e2a\u5206\u6570\uff0c\u7528\u4e8e\u6392\u5e8f\u3002<\/li>\n<li><strong>\u4f4d\u56fe\uff08Bitmaps\uff09<\/strong>\uff1a\u7528\u4e8e\u64cd\u4f5c\u4e8c\u8fdb\u5236\u4f4d\u3002<\/li>\n<li><strong>HyperLogLog<\/strong>\uff1a\u7528\u4e8e\u57fa\u6570\u7edf\u8ba1\u7684\u6982\u7387\u6027\u6570\u636e\u7ed3\u6784\u3002<\/li>\n<\/ul>\n<p><strong>\u57fa\u672c\u64cd\u4f5c<\/strong>\uff1a<\/p>\n<ul>\n<li><strong>\u5b57\u7b26\u4e32\u64cd\u4f5c<\/strong>\uff1a<code>SET<\/code>\u3001<code>GET<\/code>\u3001<code>INCR<\/code>\u3001<code>DECR<\/code>\u3002<\/li>\n<li><strong>\u54c8\u5e0c\u64cd\u4f5c<\/strong>\uff1a<code>HSET<\/code>\u3001<code>HGET<\/code>\u3001<code>HGETALL<\/code>\u3002<\/li>\n<li><strong>\u5217\u8868\u64cd\u4f5c<\/strong>\uff1a<code>LPUSH<\/code>\u3001<code>RPUSH<\/code>\u3001<code>LPOP<\/code>\u3001<code>RPOP<\/code>\u3002<\/li>\n<li><strong>\u96c6\u5408\u64cd\u4f5c<\/strong>\uff1a<code>SADD<\/code>\u3001<code>SREM<\/code>\u3001<code>SISMEMBER<\/code>\u3002<\/li>\n<li><strong>\u6709\u5e8f\u96c6\u5408\u64cd\u4f5c<\/strong>\uff1a<code>ZADD<\/code>\u3001<code>ZRANGE<\/code>\u3001<code>ZREM<\/code>\u3002<\/li>\n<\/ul>\n<h3>2. \u9ad8\u7ea7\u64cd\u4f5c<\/h3>\n<p><strong>\u4e8b\u52a1<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 <code>MULTI<\/code>\u3001<code>EXEC<\/code>\u3001<code>DISCARD<\/code>\u3001<code>WATCH<\/code> \u5b9e\u73b0\u4e8b\u52a1\u63a7\u5236\u3002<\/li>\n<\/ul>\n<p><strong>\u7ba1\u9053\uff08Pipelining\uff09<\/strong>\uff1a<\/p>\n<ul>\n<li>\u901a\u8fc7\u7ba1\u9053\u4e00\u6b21\u6027\u53d1\u9001\u591a\u4e2a\u547d\u4ee4\uff0c\u51cf\u5c11\u7f51\u7edc\u5ef6\u8fdf\uff0c\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p><strong>Lua \u811a\u672c<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 <code>EVAL<\/code>\u3001<code>EVALSHA<\/code> \u6267\u884c Lua \u811a\u672c\uff0c\u5b9e\u73b0\u590d\u6742\u7684\u539f\u5b50\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<p><strong>\u53d1\u5e03\/\u8ba2\u9605\uff08Pub\/Sub\uff09<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5b9e\u73b0\u6d88\u606f\u53d1\u5e03\u548c\u8ba2\u9605\u673a\u5236\uff0c\u7528\u4e8e\u5b9e\u65f6\u6d88\u606f\u4f20\u9012\u3002<\/li>\n<\/ul>\n<h3>3. \u6301\u4e45\u5316<\/h3>\n<p><strong>RDB\uff08\u5feb\u7167\uff09<\/strong>\uff1a<\/p>\n<ul>\n<li>\u901a\u8fc7\u5b9a\u671f\u5c06\u6570\u636e\u5feb\u7167\u5b58\u50a8\u5230\u78c1\u76d8\u5b9e\u73b0\u6301\u4e45\u5316\uff0c\u4f7f\u7528 <code>SAVE<\/code>\u3001<code>BGSAVE<\/code>\u3002<\/li>\n<\/ul>\n<p><strong>AOF\uff08\u8ffd\u52a0\u6587\u4ef6\uff09<\/strong>\uff1a<\/p>\n<ul>\n<li>\u901a\u8fc7\u8bb0\u5f55\u6bcf\u4e2a\u5199\u64cd\u4f5c\u65e5\u5fd7\u5b9e\u73b0\u6301\u4e45\u5316\uff0c\u4f7f\u7528 <code>BGREWRITEAOF<\/code>\u3001<code>AOF<\/code>\u3002<\/li>\n<\/ul>\n<p><strong>\u6301\u4e45\u5316\u7b56\u7565<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4e86\u89e3\u6301\u4e45\u5316\u7b56\u7565\u7684\u914d\u7f6e\u548c\u9009\u62e9\uff0c\u6743\u8861\u6027\u80fd\u548c\u6570\u636e\u5b89\u5168\u6027\u3002<\/li>\n<\/ul>\n<h3>4. \u5206\u5e03\u5f0f\u7279\u6027<\/h3>\n<p><strong>\u4e3b\u4ece\u590d\u5236\uff08Replication\uff09<\/strong>\uff1a<\/p>\n<ul>\n<li>\u914d\u7f6e\u4e3b\u4ece\u590d\u5236\uff0c\u63d0\u9ad8\u6570\u636e\u7684\u53ef\u7528\u6027\u548c\u8bfb\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p><strong>\u54e8\u5175\u6a21\u5f0f\uff08Sentinel\uff09<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 Redis Sentinel \u5b9e\u73b0\u9ad8\u53ef\u7528\u6027\uff0c\u81ea\u52a8\u6545\u969c\u8f6c\u79fb\u3002<\/li>\n<\/ul>\n<p><strong>\u96c6\u7fa4\u6a21\u5f0f\uff08Cluster\uff09<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 Redis Cluster \u5b9e\u73b0\u6570\u636e\u5206\u7247\u548c\u5206\u5e03\u5f0f\u5b58\u50a8\uff0c\u63d0\u9ad8\u7cfb\u7edf\u7684\u53ef\u6269\u5c55\u6027\u548c\u5bb9\u9519\u80fd\u529b\u3002<\/li>\n<\/ul>\n<h3>5. \u6027\u80fd\u4f18\u5316<\/h3>\n<p><strong>\u5185\u5b58\u4f18\u5316<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4e86\u89e3 Redis \u5185\u5b58\u7ba1\u7406\u673a\u5236\uff0c\u4f7f\u7528\u5408\u9002\u7684\u6570\u636e\u7ed3\u6784\u548c\u5185\u5b58\u4f18\u5316\u7b56\u7565\u3002<\/li>\n<\/ul>\n<p><strong>\u6700\u5927\u5185\u5b58\u9650\u5236<\/strong>\uff1a<\/p>\n<ul>\n<li>\u914d\u7f6e Redis \u7684\u6700\u5927\u5185\u5b58\u9650\u5236\uff08<code>maxmemory<\/code>\uff09\uff0c\u4f7f\u7528\u5185\u5b58\u6dd8\u6c70\u7b56\u7565\uff08\u5982 LRU\u3001LFU\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u6027\u80fd\u76d1\u63a7<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 Redis \u5185\u7f6e\u7684\u76d1\u63a7\u547d\u4ee4\uff08\u5982 <code>INFO<\/code>\u3001<code>MONITOR<\/code>\uff09\u548c\u5916\u90e8\u5de5\u5177\u76d1\u63a7 Redis \u6027\u80fd\u3002<\/li>\n<\/ul>\n<h3>6. \u5b89\u5168\u6027<\/h3>\n<p><strong>\u8ba4\u8bc1\u548c\u6388\u6743<\/strong>\uff1a<\/p>\n<ul>\n<li>\u914d\u7f6e Redis \u5bc6\u7801\uff08<code>requirepass<\/code>\uff09\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\u3002<\/li>\n<\/ul>\n<p><strong>\u7f51\u7edc\u5b89\u5168<\/strong>\uff1a<\/p>\n<ul>\n<li>\u901a\u8fc7\u914d\u7f6e\u9632\u706b\u5899\u3001\u542f\u7528 TLS \u52a0\u5bc6\u3001\u8bbe\u7f6e\u8bbf\u95ee\u63a7\u5236\u5217\u8868\uff08ACL\uff09\u7b49\u65b9\u5f0f\u4fdd\u62a4 Redis \u5b9e\u4f8b\u7684\u5b89\u5168\u3002<\/li>\n<\/ul>\n<p><strong>\u6570\u636e\u52a0\u5bc6<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528\u52a0\u5bc6\u4f20\u8f93\uff08\u5982 SSL\/TLS\uff09\u4fdd\u62a4\u6570\u636e\u5728\u7f51\u7edc\u4e2d\u7684\u4f20\u8f93\u5b89\u5168\u3002<\/li>\n<\/ul>\n<h3>7. \u5b9e\u8df5\u5e94\u7528<\/h3>\n<p><strong>\u7f13\u5b58<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 Redis \u5b9e\u73b0\u6570\u636e\u7f13\u5b58\uff0c\u63d0\u9ad8\u5e94\u7528\u7684\u6027\u80fd\u548c\u54cd\u5e94\u901f\u5ea6\u3002<\/li>\n<\/ul>\n<p><strong>\u4f1a\u8bdd\u7ba1\u7406<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 Redis \u5b58\u50a8\u7528\u6237\u4f1a\u8bdd\u6570\u636e\uff0c\u652f\u6301\u5206\u5e03\u5f0f\u4f1a\u8bdd\u7ba1\u7406\u3002<\/li>\n<\/ul>\n<p><strong>\u5206\u5e03\u5f0f\u9501<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 Redis \u5b9e\u73b0\u5206\u5e03\u5f0f\u9501\uff0c\u5982 Redlock \u7b97\u6cd5\uff0c\u786e\u4fdd\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d\u7684\u64cd\u4f5c\u539f\u5b50\u6027\u3002<\/li>\n<\/ul>\n<p><strong>\u4efb\u52a1\u961f\u5217<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 Redis \u5217\u8868\u6216\u6709\u5e8f\u96c6\u5408\u5b9e\u73b0\u4efb\u52a1\u961f\u5217\uff0c\u5904\u7406\u5f02\u6b65\u4efb\u52a1\u3002<\/li>\n<\/ul>\n<h3>8. \u5b66\u4e60\u8d44\u6e90\u548c\u5de5\u5177<\/h3>\n<p><strong>\u6587\u6863\u548c\u793e\u533a<\/strong>\uff1a<\/p>\n<ul>\n<li>\u53c2\u8003 Redis \u5b98\u65b9\u6587\u6863\u548c\u793e\u533a\u8d44\u6e90\uff0c\u4e86\u89e3\u6700\u65b0\u7684\u529f\u80fd\u548c\u6700\u4f73\u5b9e\u8df5\u3002<\/li>\n<\/ul>\n<p><strong>\u5ba2\u6237\u7aef\u5e93<\/strong>\uff1a<\/p>\n<ul>\n<li>\u638c\u63e1\u5e38\u7528\u7f16\u7a0b\u8bed\u8a00\u7684 Redis \u5ba2\u6237\u7aef\u5e93\uff0c\u5982 <code>redis-py<\/code>\uff08Python\uff09\u3001<code>Jedis<\/code>\uff08Java\uff09\u3001<code>node_redis<\/code>\uff08Node.js\uff09\u7b49\u3002<\/li>\n<\/ul>\n<p><strong>\u56fe\u5f62\u7ba1\u7406\u5de5\u5177<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 Redis Desktop Manager\u3001RedisInsight \u7b49\u56fe\u5f62\u5316\u5de5\u5177\u65b9\u4fbf\u5730\u7ba1\u7406\u548c\u76d1\u63a7 Redis \u5b9e\u4f8b\u3002<\/li>\n<\/ul>\n<h3>\u7ed3\u8bba<\/h3>\n<p>\u4f5c\u4e3a\u540e\u7aef\u5de5\u7a0b\u5e08\uff0c\u638c\u63e1 Redis \u7684\u57fa\u672c\u64cd\u4f5c\u3001\u9ad8\u7ea7\u529f\u80fd\u3001\u6027\u80fd\u4f18\u5316\u548c\u5b89\u5168\u6027\u914d\u7f6e\u7b49\u6280\u80fd\uff0c\u80fd\u591f\u5e2e\u52a9\u4f60\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u9ad8\u6548\u5730\u5229\u7528 Redis \u63d0\u9ad8\u7cfb\u7edf\u7684\u6027\u80fd\u548c\u53ef\u6269\u5c55\u6027\u3002\u540c\u65f6\uff0c\u4e86\u89e3 Redis \u7684\u5206\u5e03\u5f0f\u7279\u6027\u548c\u5e38\u89c1\u5e94\u7528\u573a\u666f\uff0c\u53ef\u4ee5\u4e3a\u4f60\u5728\u5206\u5e03\u5f0f\u7cfb\u7edf\u548c\u9ad8\u5e76\u53d1\u73af\u5883\u4e0b\u63d0\u4f9b\u66f4\u597d\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis \u662f\u4e00\u79cd\u9ad8\u6027\u80fd\u7684\u952e\u503c\u5b58\u50a8\u6570\u636e\u5e93\uff0c\u5728\u540e\u7aef\u5f00\u53d1\u4e2d\u5e7f\u6cdb\u5e94\u7528\u3002\u4f5c\u4e3a\u540e\u7aef\u5de5\u7a0b\u5e08\uff0c\u638c\u63e1 Redis \u6280\u80fd\u662f\u975e\u5e38\u91cd&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6374\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[123],"tags":[122],"class_list":["post-6374","post","type-post","status-publish","format-standard","hentry","category-123","tag-redis"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6374","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6374"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6374\/revisions"}],"predecessor-version":[{"id":6375,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6374\/revisions\/6375"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}