{"id":97642,"date":"2024-10-20T19:43:18","date_gmt":"2024-10-20T11:43:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/97642\/"},"modified":"2024-10-20T19:43:19","modified_gmt":"2024-10-20T11:43:19","slug":"redis-%e5%bf%ab%e9%80%9f%e4%b8%8a%e6%89%8b%e4%bd%bf%e7%94%a8%e6%8c%87%e5%8d%97%ef%bc%88redis-%e4%bd%bf%e7%94%a8%e5%85%a5%e9%96%80%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/97642\/","title":{"rendered":"Redis: \u5feb\u901f\u4e0a\u624b\u4f7f\u7528\u6307\u5357\uff08redis \u4f7f\u7528\u5165\u9580\uff09"},"content":{"rendered":"<h1 id=\"redis-%e5%bf%ab%e9%80%9f%e4%b8%8a%e6%89%8b%e4%bd%bf%e7%94%a8%e6%8c%87%e5%8d%97%ef%bc%88redis-%e4%bd%bf%e7%94%a8%e5%85%a5%e9%96%80%ef%bc%89-OaJRQwylNK\">Redis: \u5feb\u901f\u4e0a\u624b\u4f7f\u7528\u6307\u5357\uff08Redis \u4f7f\u7528\u5165\u9580\uff09<\/h1>\n<p>Redis\uff08Remote Dictionary Server\uff09\u662f\u4e00\u500b\u958b\u6e90\u7684\u9ad8\u6027\u80fd\u9375\u503c\u6578\u64da\u5eab\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u7de9\u5b58\u3001\u6d88\u606f\u968a\u5217\u548c\u6578\u64da\u5b58\u5132\u7b49\u5834\u666f\u3002\u7531\u65bc\u5176\u5353\u8d8a\u7684\u6027\u80fd\u548c\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\uff0cRedis \u6210\u70ba\u4e86\u8a31\u591a\u958b\u767c\u8005\u7684\u9996\u9078\u3002\u672c\u6587\u5c07\u4ecb\u7d39 Redis \u7684\u57fa\u672c\u6982\u5ff5\u3001\u5b89\u88dd\u6b65\u9a5f\u53ca\u5e38\u7528\u547d\u4ee4\uff0c\u5e6b\u52a9\u60a8\u5feb\u901f\u4e0a\u624b\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-redis%ef%bc%9f-OaJRQwylNK\">\u4ec0\u9ebc\u662f Redis\uff1f<\/h2>\n<p>Redis \u662f\u4e00\u500b\u57fa\u65bc\u5167\u5b58\u7684\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\u5b83\u7684\u4e3b\u8981\u7279\u9ede\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u9ad8\u6027\u80fd\uff1a<\/strong>Redis \u53ef\u4ee5\u6bcf\u79d2\u8655\u7406\u6578\u5341\u842c\u6b21\u8b80\u5beb\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u6301\u4e45\u5316\uff1a<\/strong>\u652f\u6301 RDB \u548c AOF \u5169\u7a2e\u6301\u4e45\u5316\u65b9\u5f0f\uff0c\u80fd\u5920\u5728\u91cd\u555f\u5f8c\u6062\u5fa9\u6578\u64da\u3002<\/li>\n<li><strong>\u591a\u7a2e\u6578\u64da\u7d50\u69cb\uff1a<\/strong>\u652f\u6301\u591a\u7a2e\u6578\u64da\u985e\u578b\uff0c\u9748\u6d3b\u61c9\u5c0d\u4e0d\u540c\u7684\u61c9\u7528\u9700\u6c42\u3002<\/li>\n<li><strong>\u5206\u4f48\u5f0f\uff1a<\/strong>\u652f\u6301\u4e3b\u5f9e\u8907\u88fd\u548c\u5206\u7247\uff0c\u65b9\u4fbf\u64f4\u5c55\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%ae%89%e8%a3%9d-redis-OaJRQwylNK\">\u5b89\u88dd Redis<\/h2>\n<p>\u5728\u958b\u59cb\u4f7f\u7528 Redis \u4e4b\u524d\uff0c\u60a8\u9700\u8981\u5148\u5b89\u88dd\u5b83\u3002\u4ee5\u4e0b\u662f\u5b89\u88dd Redis \u7684\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"%e5%9c%a8-linux-%e4%b8%8a%e5%ae%89%e8%a3%9d-redis-OaJRQwylNK\">\u5728 Linux \u4e0a\u5b89\u88dd Redis<\/h3>\n<pre><code>sudo apt update\nsudo apt install redis-server\n<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5 Redis \u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl start redis\n<\/code><\/pre>\n<p>\u8981\u6aa2\u67e5 Redis \u662f\u5426\u6b63\u5728\u904b\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>sudo systemctl status redis\n<\/code><\/pre>\n<h3 id=\"%e5%9c%a8-windows-%e4%b8%8a%e5%ae%89%e8%a3%9d-redis-OaJRQwylNK\">\u5728 Windows \u4e0a\u5b89\u88dd Redis<\/h3>\n<p>\u5728 Windows \u4e0a\uff0c\u60a8\u53ef\u4ee5\u5f9e Redis \u7684 GitHub \u9801\u9762\u4e0b\u8f09\u9810\u7de8\u8b6f\u7684\u4e8c\u9032\u5236\u6587\u4ef6\uff0c\u7136\u5f8c\u89e3\u58d3\u4e26\u904b\u884c redis-server.exe\u3002<\/p>\n<h2 id=\"%e5%9f%ba%e6%9c%ac%e4%bd%bf%e7%94%a8%e5%91%bd%e4%bb%a4-OaJRQwylNK\">\u57fa\u672c\u4f7f\u7528\u547d\u4ee4<\/h2>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 Redis \u7684\u547d\u4ee4\u884c\u754c\u9762\u9032\u884c\u64cd\u4f5c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684 Redis \u547d\u4ee4\uff1a<\/p>\n<h3 id=\"%e9%80%a3%e6%8e%a5%e5%88%b0-redis-OaJRQwylNK\">\u9023\u63a5\u5230 Redis<\/h3>\n<pre><code>redis-cli\n<\/code><\/pre>\n<h3 id=\"%e8%a8%ad%e7%bd%ae%e5%92%8c%e7%8d%b2%e5%8f%96%e9%8d%b5%e5%80%bc-OaJRQwylNK\">\u8a2d\u7f6e\u548c\u7372\u53d6\u9375\u503c<\/h3>\n<p>\u4f7f\u7528 <code>SET<\/code> \u548c <code>GET<\/code> \u547d\u4ee4\u4f86\u8a2d\u7f6e\u548c\u7372\u53d6\u9375\u503c\uff1a<\/p>\n<pre><code>SET mykey \"Hello, Redis!\"\nGET mykey\n<\/code><\/pre>\n<h3 id=\"%e4%bd%bf%e7%94%a8%e5%93%88%e5%b8%8c-OaJRQwylNK\">\u4f7f\u7528\u54c8\u5e0c<\/h3>\n<p>\u54c8\u5e0c\u662f\u4e00\u7a2e\u9375\u503c\u5c0d\u7684\u96c6\u5408\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u64cd\u4f5c\u54c8\u5e0c\uff1a<\/p>\n<pre><code>HSET user:1000 name \"Alice\"\nHGET user:1000 name\n<\/code><\/pre>\n<h3 id=\"%e4%bd%bf%e7%94%a8%e5%88%97%e8%a1%a8-OaJRQwylNK\">\u4f7f\u7528\u5217\u8868<\/h3>\n<p>\u5217\u8868\u662f\u4e00\u500b\u6709\u5e8f\u7684\u5b57\u7b26\u4e32\u96c6\u5408\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u4f86\u64cd\u4f5c\u5217\u8868\uff1a<\/p>\n<pre><code>LPUSH mylist \"item1\"\nLPUSH mylist \"item2\"\nLRANGE mylist 0 -1\n<\/code><\/pre>\n<h2 id=\"%e6%8c%81%e4%b9%85%e5%8c%96%e9%85%8d%e7%bd%ae-OaJRQwylNK\">\u6301\u4e45\u5316\u914d\u7f6e<\/h2>\n<p>Redis \u63d0\u4f9b\u4e86\u5169\u7a2e\u6301\u4e45\u5316\u65b9\u5f0f\uff1aRDB \u548c AOF\u3002\u60a8\u53ef\u4ee5\u5728 <code>redis.conf<\/code> \u914d\u7f6e\u6587\u4ef6\u4e2d\u8a2d\u7f6e\u6301\u4e45\u5316\u9078\u9805\u3002<\/p>\n<h3 id=\"rdb-%e6%8c%81%e4%b9%85%e5%8c%96-OaJRQwylNK\">RDB \u6301\u4e45\u5316<\/h3>\n<p>RDB\uff08\u5feb\u7167\uff09\u6703\u5728\u6307\u5b9a\u7684\u6642\u9593\u9593\u9694\u5167\u81ea\u52d5\u4fdd\u5b58\u6578\u64da\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u914d\u7f6e\u4f86\u8a2d\u7f6e\uff1a<\/p>\n<pre><code>save 900 1\nsave 300 10\nsave 60 10000\n<\/code><\/pre>\n<h3 id=\"aof-%e6%8c%81%e4%b9%85%e5%8c%96-OaJRQwylNK\">AOF \u6301\u4e45\u5316<\/h3>\n<p>AOF\uff08\u8ffd\u52a0\u6587\u4ef6\uff09\u6703\u5c07\u6bcf\u500b\u5beb\u64cd\u4f5c\u8ffd\u52a0\u5230\u6587\u4ef6\u4e2d\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u914d\u7f6e\u4f86\u555f\u7528\uff1a<\/p>\n<pre><code>appendonly yes\n<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-OaJRQwylNK\">\u7e3d\u7d50<\/h2>\n<p>Redis \u662f\u4e00\u500b\u529f\u80fd\u5f37\u5927\u4e14\u9ad8\u6548\u7684\u6578\u64da\u5eab\uff0c\u9069\u5408\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u5834\u666f\u3002\u901a\u904e\u672c\u6587\u7684\u4ecb\u7d39\uff0c\u60a8\u61c9\u8a72\u80fd\u5920\u5feb\u901f\u4e0a\u624b Redis \u7684\u57fa\u672c\u4f7f\u7528\u3002\u7121\u8ad6\u662f\u7528\u65bc\u7de9\u5b58\u9084\u662f\u6578\u64da\u5b58\u5132\uff0cRedis \u90fd\u80fd\u63d0\u4f9b\u5353\u8d8a\u7684\u6027\u80fd\u548c\u9748\u6d3b\u6027\u3002\u5982\u679c\u60a8\u9700\u8981\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u4f86\u904b\u884c Redis\uff0c\u8acb\u8003\u616e\u9078\u64c7\u5408\u9069\u7684\u670d\u52d9\u5668\u914d\u7f6e\uff0c\u4ee5\u78ba\u4fdd\u6700\u4f73\u7684\u6027\u80fd\u548c\u53ef\u9760\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5feb\u901f\u4e0a\u624bRedis\u7684\u4f7f\u7528\u6307\u5357\uff0c\u6db5\u76d6\u57fa\u672c\u6982\u5ff5\u3001\u5b89\u88c5\u6b65\u9aa4\u53ca\u5e38\u7528\u547d\u4ee4\uff0c\u52a9\u4f60\u8f7b\u677e\u638c\u63e1Redis\u6570\u636e\u5e93\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-97642","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/97642","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=97642"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/97642\/revisions"}],"predecessor-version":[{"id":97643,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/97642\/revisions\/97643"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=97642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=97642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=97642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}