{"id":115128,"date":"2024-10-24T13:55:34","date_gmt":"2024-10-24T05:55:34","guid":{"rendered":"https:\/\/server.hk\/cnblog\/115128\/"},"modified":"2024-10-24T13:55:35","modified_gmt":"2024-10-24T05:55:35","slug":"redis-%e5%bf%ab%e5%8f%96%e9%96%8b%e7%99%bc%e8%80%85%e5%8f%83%e8%80%83%e6%89%8b%e5%86%8a","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/115128\/","title":{"rendered":"Redis \u5feb\u53d6\u958b\u767c\u8005\u53c3\u8003\u624b\u518a"},"content":{"rendered":"<h1 id=\"redis-%e5%bf%ab%e5%8f%96%e9%96%8b%e7%99%bc%e8%80%85%e5%8f%83%e8%80%83%e6%89%8b%e5%86%8a-AhGbGQCQhU\">Redis \u5feb\u53d6\u958b\u767c\u8005\u53c3\u8003\u624b\u518a<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u8def\u61c9\u7528\u7a0b\u5f0f\u4e2d\uff0c\u6548\u80fd\u548c\u901f\u5ea6\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002Redis \u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u7684\u5feb\u53d6\u89e3\u6c7a\u65b9\u6848\uff0c\u5df2\u7d93\u6210\u70ba\u8a31\u591a\u958b\u767c\u8005\u7684\u9996\u9078\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e Redis \u7684\u57fa\u672c\u6982\u5ff5\u3001\u4f7f\u7528\u5834\u666f\u3001\u5b89\u88dd\u6b65\u9a5f\u4ee5\u53ca\u4e00\u4e9b\u5be6\u7528\u7684\u7bc4\u4f8b\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u7406\u89e3\u548c\u4f7f\u7528 Redis\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-redis%ef%bc%9f-AhGbGQCQhU\">\u4ec0\u9ebc\u662f Redis\uff1f<\/h2>\n<p>Redis\uff08REmote DIctionary Server\uff09\u662f\u4e00\u500b\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\u548c\u6709\u5e8f\u96c6\u5408\u3002\u5b83\u901a\u5e38\u7528\u4f5c\u5feb\u53d6\u7cfb\u7d71\uff0c\u4ee5\u63d0\u9ad8\u61c9\u7528\u7a0b\u5f0f\u7684\u97ff\u61c9\u901f\u5ea6\u548c\u6548\u80fd\u3002<\/p>\n<h2 id=\"redis-%e7%9a%84%e7%89%b9%e9%bb%9e-AhGbGQCQhU\">Redis \u7684\u7279\u9ede<\/h2>\n<ul>\n<li><strong>\u9ad8\u6548\u80fd\uff1a<\/strong>Redis \u53ef\u4ee5\u6bcf\u79d2\u8655\u7406\u6578\u5341\u842c\u6b21\u8acb\u6c42\uff0c\u4e26\u4e14\u652f\u6301\u6301\u4e45\u5316\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\u6027\u9ad8\u3002<\/li>\n<li><strong>\u539f\u5b50\u64cd\u4f5c\uff1a<\/strong>\u63d0\u4f9b\u539f\u5b50\u64cd\u4f5c\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u4e00\u81f4\u6027\u3002<\/li>\n<li><strong>\u5206\u4f48\u5f0f\u652f\u6301\uff1a<\/strong>\u652f\u6301\u4e3b\u5f9e\u8907\u88fd\u548c\u5206\u7247\uff0c\u9069\u5408\u5927\u898f\u6a21\u61c9\u7528\u3002<\/li>\n<\/ul>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e5%a0%b4%e6%99%af-AhGbGQCQhU\">\u4f7f\u7528\u5834\u666f<\/h2>\n<p>Redis \u7684\u61c9\u7528\u5834\u666f\u975e\u5e38\u5ee3\u6cdb\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u4f7f\u7528\u60c5\u5883\uff1a<\/p>\n<ul>\n<li><strong>\u5feb\u53d6\uff1a<\/strong>\u5c07\u983b\u7e41\u8a2a\u554f\u7684\u6578\u64da\u5b58\u5132\u5728 Redis \u4e2d\uff0c\u4ee5\u6e1b\u5c11\u5c0d\u5f8c\u7aef\u6578\u64da\u5eab\u7684\u8acb\u6c42\u3002<\/li>\n<li><strong>\u6703\u8a71\u7ba1\u7406\uff1a<\/strong>\u4f7f\u7528 Redis \u5b58\u5132\u7528\u6236\u6703\u8a71\u4fe1\u606f\uff0c\u63d0\u9ad8\u61c9\u7528\u7684\u97ff\u61c9\u901f\u5ea6\u3002<\/li>\n<li><strong>\u6392\u884c\u699c\uff1a<\/strong>\u5229\u7528 Redis \u7684\u6709\u5e8f\u96c6\u5408\u529f\u80fd\uff0c\u5be6\u73fe\u5373\u6642\u7684\u6392\u884c\u699c\u7cfb\u7d71\u3002<\/li>\n<li><strong>\u6d88\u606f\u968a\u5217\uff1a<\/strong>\u4f7f\u7528 Redis \u7684\u5217\u8868\u7d50\u69cb\uff0c\u5be6\u73fe\u7c21\u55ae\u7684\u6d88\u606f\u968a\u5217\u529f\u80fd\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%ae%89%e8%a3%9d-redis-AhGbGQCQhU\">\u5b89\u88dd Redis<\/h2>\n<p>\u5728 Linux \u7cfb\u7d71\u4e0a\u5b89\u88dd Redis \u7684\u6b65\u9a5f\u5982\u4e0b\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install redis-server\n<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\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\u5e38\u904b\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>redis-cli ping\n<\/code><\/pre>\n<p>\u5982\u679c\u8fd4\u56de &#8220;PONG&#8221;\uff0c\u5247\u8868\u793a Redis \u6b63\u5728\u904b\u884c\u3002<\/p>\n<h2 id=\"%e5%9f%ba%e6%9c%ac%e6%93%8d%e4%bd%9c%e7%a4%ba%e4%be%8b-AhGbGQCQhU\">\u57fa\u672c\u64cd\u4f5c\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b Redis \u7684\u57fa\u672c\u64cd\u4f5c\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"%e8%a8%ad%e7%bd%ae%e5%92%8c%e7%8d%b2%e5%8f%96%e9%8d%b5%e5%80%bc-AhGbGQCQhU\">\u8a2d\u7f6e\u548c\u7372\u53d6\u9375\u503c<\/h3>\n<pre><code>redis-cli set mykey \"Hello, Redis!\"\nredis-cli get mykey\n<\/code><\/pre>\n<h3 id=\"%e4%bd%bf%e7%94%a8%e5%93%88%e5%b8%8c-AhGbGQCQhU\">\u4f7f\u7528\u54c8\u5e0c<\/h3>\n<pre><code>redis-cli hset user:1000 name \"Alice\"\nredis-cli hget user:1000 name\n<\/code><\/pre>\n<h3 id=\"%e4%bd%bf%e7%94%a8%e5%88%97%e8%a1%a8-AhGbGQCQhU\">\u4f7f\u7528\u5217\u8868<\/h3>\n<pre><code>redis-cli rpush mylist \"item1\"\nredis-cli rpush mylist \"item2\"\nredis-cli lrange mylist 0 -1\n<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-AhGbGQCQhU\">\u7e3d\u7d50<\/h2>\n<p>Redis \u662f\u4e00\u500b\u529f\u80fd\u5f37\u5927\u4e14\u9748\u6d3b\u7684\u5feb\u53d6\u89e3\u6c7a\u65b9\u6848\uff0c\u9069\u5408\u5404\u7a2e\u61c9\u7528\u5834\u666f\u3002\u7121\u8ad6\u662f\u7528\u65bc\u5feb\u53d6\u3001\u6703\u8a71\u7ba1\u7406\u9084\u662f\u6d88\u606f\u968a\u5217\uff0cRedis \u90fd\u80fd\u63d0\u4f9b\u5353\u8d8a\u7684\u6548\u80fd\u548c\u53ef\u9760\u6027\u3002\u5c0d\u65bc\u5e0c\u671b\u63d0\u5347\u61c9\u7528\u6548\u80fd\u7684\u958b\u767c\u8005\u4f86\u8aaa\uff0c\u638c\u63e1 Redis \u7684\u4f7f\u7528\u5c07\u662f\u975e\u5e38\u6709\u50f9\u503c\u7684\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\u7f72 Redis\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u9084\u662f\u5176\u4ed6\u5730\u5340\u7684\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis \u5feb\u53d6\u958b\u767c\u8005\u53c3\u8003\u624b\u518a\u63d0\u4f9b\u5168\u9762\u6307\u5357\uff0c\u52a9\u60a8\u9ad8\u6548\u4f7f\u7528 Redis \u5feb\u53d6\u6280\u8853\uff0c\u63d0\u5347\u61c9\u7528\u6027\u80fd\u8207\u97ff\u61c9\u901f\u5ea6\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-115128","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/115128","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=115128"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/115128\/revisions"}],"predecessor-version":[{"id":115129,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/115128\/revisions\/115129"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=115128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=115128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=115128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}