{"id":128207,"date":"2024-10-26T12:26:19","date_gmt":"2024-10-26T04:26:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/128207\/"},"modified":"2024-10-26T12:26:19","modified_gmt":"2024-10-26T04:26:19","slug":"redis-%e5%af%a6%e4%be%8b%e6%8f%92%e5%85%a5%e8%88%87%e7%8d%b2%e5%8f%96%e5%af%a6%e6%88%b0%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/128207\/","title":{"rendered":"Redis \u5be6\u4f8b\u63d2\u5165\u8207\u7372\u53d6\u5be6\u6230\u6559\u7a0b"},"content":{"rendered":"<h1 id=\"redis-%e5%af%a6%e4%be%8b%e6%8f%92%e5%85%a5%e8%88%87%e7%8d%b2%e5%8f%96%e5%af%a6%e6%88%b0%e6%95%99%e7%a8%8b-JDPRrIPHhC\">Redis \u5be6\u4f8b\u63d2\u5165\u8207\u7372\u53d6\u5be6\u6230\u6559\u7a0b<\/h1>\n<p>Redis \u662f\u4e00\u500b\u9ad8\u6548\u80fd\u7684\u9375\u503c\u6578\u64da\u5eab\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u7de9\u5b58\u3001\u6d88\u606f\u968a\u5217\u548c\u5be6\u6642\u6578\u64da\u8655\u7406\u7b49\u5834\u666f\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u5982\u4f55\u5728 Redis \u4e2d\u9032\u884c\u5be6\u4f8b\u7684\u63d2\u5165\u8207\u7372\u53d6\uff0c\u4e26\u63d0\u4f9b\u5be6\u7528\u7684\u4ee3\u78bc\u793a\u4f8b\uff0c\u5e6b\u52a9\u8b80\u8005\u66f4\u597d\u5730\u7406\u89e3 Redis \u7684\u57fa\u672c\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"redis-%e7%b0%a1%e4%bb%8b-JDPRrIPHhC\">Redis \u7c21\u4ecb<\/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\u3002\u7531\u65bc\u5176\u9ad8\u6548\u7684\u6027\u80fd\u548c\u9748\u6d3b\u7684\u6578\u64da\u7d50\u69cb\uff0cRedis \u6210\u70ba\u8a31\u591a\u61c9\u7528\u7a0b\u5e8f\u7684\u9996\u9078\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h2 id=\"%e7%92%b0%e5%a2%83%e6%ba%96%e5%82%99-JDPRrIPHhC\">\u74b0\u5883\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u5df2\u7d93\u5b89\u88dd\u4e86 Redis\u3002\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u5728 Linux \u7cfb\u7d71\u4e0a\u5b89\u88dd Redis\uff1a<\/p>\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 service redis-server start\n<\/code><\/pre>\n<h2 id=\"%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-JDPRrIPHhC\">\u63d2\u5165\u6578\u64da<\/h2>\n<p>\u5728 Redis \u4e2d\uff0c\u63d2\u5165\u6578\u64da\u4e3b\u8981\u4f7f\u7528 <code>SET<\/code> \u547d\u4ee4\u3002\u4ee5\u4e0b\u662f\u63d2\u5165\u5b57\u7b26\u4e32\u6578\u64da\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>redis-cli\nSET mykey \"Hello, Redis!\"\n<\/code><\/pre>\n<p>\u9019\u689d\u547d\u4ee4\u5c07\u5b57\u7b26\u4e32 &#8220;Hello, Redis!&#8221; \u5b58\u5132\u5728\u9375 <code>mykey<\/code> \u4e2d\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 <code>GET<\/code> \u547d\u4ee4\u4f86\u6aa2\u7d22\u8a72\u6578\u64da\uff1a<\/p>\n<pre><code>GET mykey\n<\/code><\/pre>\n<p>\u5982\u679c\u6210\u529f\uff0c\u60a8\u5c07\u770b\u5230\u8f38\u51fa\uff1a<\/p>\n<pre><code>\"Hello, Redis!\"\n<\/code><\/pre>\n<h3 id=\"%e6%8f%92%e5%85%a5%e5%93%88%e5%b8%8c%e6%95%b8%e6%93%9a-JDPRrIPHhC\">\u63d2\u5165\u54c8\u5e0c\u6578\u64da<\/h3>\n<p>\u9664\u4e86\u5b57\u7b26\u4e32\uff0cRedis \u9084\u652f\u6301\u54c8\u5e0c\u6578\u64da\u7d50\u69cb\u3002\u4ee5\u4e0b\u662f\u63d2\u5165\u54c8\u5e0c\u6578\u64da\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>HSET user:1000 username \"john_doe\" password \"securepassword\"\n<\/code><\/pre>\n<p>\u9019\u689d\u547d\u4ee4\u5c07\u7528\u6236\u540d\u548c\u5bc6\u78bc\u5b58\u5132\u5728\u9375 <code>user:1000<\/code> \u4e2d\u3002\u8981\u7372\u53d6\u54c8\u5e0c\u4e2d\u7684\u67d0\u500b\u5b57\u6bb5\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>HGET<\/code> \u547d\u4ee4\uff1a<\/p>\n<pre><code>HGET user:1000 username\n<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\uff1a<\/p>\n<pre><code>\"john_doe\"\n<\/code><\/pre>\n<h2 id=\"%e7%8d%b2%e5%8f%96%e6%95%b8%e6%93%9a-JDPRrIPHhC\">\u7372\u53d6\u6578\u64da<\/h2>\n<p>\u7372\u53d6\u6578\u64da\u7684\u904e\u7a0b\u8207\u63d2\u5165\u6578\u64da\u76f8\u4f3c\u3002\u4f7f\u7528 <code>GET<\/code> \u547d\u4ee4\u53ef\u4ee5\u7372\u53d6\u5b57\u7b26\u4e32\u6578\u64da\uff0c\u800c\u4f7f\u7528 <code>HGET<\/code> \u547d\u4ee4\u5247\u53ef\u4ee5\u7372\u53d6\u54c8\u5e0c\u6578\u64da\u3002\u4ee5\u4e0b\u662f\u7372\u53d6\u6240\u6709\u54c8\u5e0c\u5b57\u6bb5\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>HGETALL user:1000\n<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\u8a72\u7528\u6236\u7684\u6240\u6709\u4fe1\u606f\uff1a<\/p>\n<pre><code>1) \"username\"\n2) \"john_doe\"\n3) \"password\"\n4) \"securepassword\"\n<\/code><\/pre>\n<h3 id=\"%e4%bd%bf%e7%94%a8%e5%88%97%e8%a1%a8-JDPRrIPHhC\">\u4f7f\u7528\u5217\u8868<\/h3>\n<p>Redis \u9084\u652f\u6301\u5217\u8868\u6578\u64da\u7d50\u69cb\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 <code>LPUSH<\/code> \u547d\u4ee4\u5c07\u5143\u7d20\u63d2\u5165\u5217\u8868\uff1a<\/p>\n<pre><code>LPUSH mylist \"first\"\nLPUSH mylist \"second\"\n<\/code><\/pre>\n<p>\u8981\u7372\u53d6\u5217\u8868\u4e2d\u7684\u6240\u6709\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>LRANGE<\/code> \u547d\u4ee4\uff1a<\/p>\n<pre><code>LRANGE mylist 0 -1\n<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\uff1a<\/p>\n<pre><code>1) \"second\"\n2) \"first\"\n<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-JDPRrIPHhC\">\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 Redis \u4e2d\u9032\u884c\u5be6\u4f8b\u7684\u63d2\u5165\u8207\u7372\u53d6\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\u3001\u54c8\u5e0c\u548c\u5217\u8868\u7b49\u6578\u64da\u7d50\u69cb\u7684\u64cd\u4f5c\u3002Redis \u7684\u9ad8\u6548\u6027\u80fd\u548c\u9748\u6d3b\u6027\u4f7f\u5176\u6210\u70ba\u8a31\u591a\u61c9\u7528\u7684\u7406\u60f3\u9078\u64c7\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u904b\u884c Redis\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u985e\u578b\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a>\uff0c\u90fd\u80fd\u70ba\u60a8\u7684\u61c9\u7528\u63d0\u4f9b\u5f37\u5927\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728Redis\u4e2d\u5be6\u73fe\u5be6\u4f8b\u63d2\u5165\u8207\u7372\u53d6\uff0c\u638c\u63e1\u9ad8\u6548\u6578\u64da\u64cd\u4f5c\u6280\u5de7\uff0c\u63d0\u5347\u61c9\u7528\u6027\u80fd\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-128207","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/128207","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=128207"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/128207\/revisions"}],"predecessor-version":[{"id":128208,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/128207\/revisions\/128208"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=128207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=128207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=128207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}