{"id":166007,"date":"2024-11-05T14:57:20","date_gmt":"2024-11-05T06:57:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/166007\/"},"modified":"2024-11-05T14:57:21","modified_gmt":"2024-11-05T06:57:21","slug":"%e5%bf%ab%e9%80%9f%e9%a7%95%e9%a6%adredis%e9%8d%b5%e5%80%bc%e5%91%bd%e4%bb%a4%e6%93%8d%e4%bd%9c%e6%8c%87%e5%8d%97%ef%bc%88redis-%e9%8d%b5%e5%80%bc%e5%91%bd%e4%bb%a4%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/166007\/","title":{"rendered":"\u5feb\u901f\u99d5\u99adRedis\u9375\u503c\u547d\u4ee4\u64cd\u4f5c\u6307\u5357\uff08redis \u9375\u503c\u547d\u4ee4\uff09"},"content":{"rendered":"<h1 id=\"%e5%bf%ab%e9%80%9f%e9%a7%95%e9%a6%adredis%e9%8d%b5%e5%80%bc%e5%91%bd%e4%bb%a4%e6%93%8d%e4%bd%9c%e6%8c%87%e5%8d%97%ef%bc%88redis-%e9%8d%b5%e5%80%bc%e5%91%bd%e4%bb%a4%ef%bc%89-vMgysGRWAh\">\u5feb\u901f\u99d5\u99adRedis\u9375\u503c\u547d\u4ee4\u64cd\u4f5c\u6307\u5357\uff08redis \u9375\u503c\u547d\u4ee4\uff09<\/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\u5373\u6642\u6578\u64da\u8655\u7406\u7b49\u5834\u666f\u3002\u5176\u7c21\u55ae\u7684\u9375\u503c\u5b58\u5132\u6a21\u578b\u4f7f\u5f97\u958b\u767c\u8005\u80fd\u5920\u5feb\u901f\u5730\u9032\u884c\u6578\u64da\u64cd\u4f5c\u3002\u672c\u6587\u5c07\u4ecb\u7d39Redis\u7684\u57fa\u672c\u9375\u503c\u547d\u4ee4\uff0c\u5e6b\u52a9\u60a8\u5feb\u901f\u4e0a\u624b\u3002<\/p>\n<h2 id=\"redis%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-vMgysGRWAh\">Redis\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>\u5728\u6df1\u5165\u9375\u503c\u547d\u4ee4\u4e4b\u524d\uff0c\u4e86\u89e3Redis\u7684\u57fa\u672c\u6982\u5ff5\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002Redis\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\u9019\u4e9b\u6578\u64da\u7d50\u69cb\u4f7f\u5f97Redis\u5728\u8655\u7406\u4e0d\u540c\u985e\u578b\u7684\u6578\u64da\u6642\u975e\u5e38\u9748\u6d3b\u3002<\/p>\n<h2 id=\"%e5%9f%ba%e6%9c%ac%e9%8d%b5%e5%80%bc%e5%91%bd%e4%bb%a4-vMgysGRWAh\">\u57fa\u672c\u9375\u503c\u547d\u4ee4<\/h2>\n<h3 id=\"1-%e8%a8%ad%e7%bd%ae%e5%92%8c%e7%8d%b2%e5%8f%96%e9%8d%b5%e5%80%bc-vMgysGRWAh\">1. \u8a2d\u7f6e\u548c\u7372\u53d6\u9375\u503c<\/h3>\n<p>\u6700\u57fa\u672c\u7684\u64cd\u4f5c\u662f\u8a2d\u7f6e\u548c\u7372\u53d6\u9375\u503c\u3002\u4f7f\u7528 <code>SET<\/code> \u547d\u4ee4\u53ef\u4ee5\u8a2d\u7f6e\u4e00\u500b\u9375\u7684\u503c\uff0c\u800c\u4f7f\u7528 <code>GET<\/code> \u547d\u4ee4\u53ef\u4ee5\u7372\u53d6\u8a72\u9375\u7684\u503c\u3002<\/p>\n<pre><code>SET mykey \"Hello, Redis!\"\nGET mykey\n<\/code><\/pre>\n<p>\u4e0a\u8ff0\u547d\u4ee4\u5c07\u9375 <code>mykey<\/code> \u7684\u503c\u8a2d\u7f6e\u70ba <code>\"Hello, Redis!\"<\/code>\uff0c\u4e26\u901a\u904e <code>GET<\/code> \u547d\u4ee4\u7372\u53d6\u8a72\u503c\u3002<\/p>\n<h3 id=\"2-%e9%8d%b5%e7%9a%84%e5%ad%98%e5%9c%a8%e6%80%a7%e6%aa%a2%e6%9f%a5-vMgysGRWAh\">2. \u9375\u7684\u5b58\u5728\u6027\u6aa2\u67e5<\/h3>\n<p>\u4f7f\u7528 <code>EXISTS<\/code> \u547d\u4ee4\u53ef\u4ee5\u6aa2\u67e5\u4e00\u500b\u9375\u662f\u5426\u5b58\u5728\u3002<\/p>\n<pre><code>EXISTS mykey\n<\/code><\/pre>\n<p>\u5982\u679c\u9375\u5b58\u5728\uff0c\u8fd4\u56de\u503c\u70ba <code>1<\/code>\uff0c\u5426\u5247\u8fd4\u56de <code>0<\/code>\u3002<\/p>\n<h3 id=\"3-%e5%88%aa%e9%99%a4%e9%8d%b5-vMgysGRWAh\">3. \u522a\u9664\u9375<\/h3>\n<p>\u8981\u522a\u9664\u4e00\u500b\u9375\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>DEL<\/code> \u547d\u4ee4\u3002<\/p>\n<pre><code>DEL mykey\n<\/code><\/pre>\n<p>\u9019\u5c07\u522a\u9664\u9375 <code>mykey<\/code> \u53ca\u5176\u5c0d\u61c9\u7684\u503c\u3002<\/p>\n<h3 id=\"4-%e9%8d%b5%e7%9a%84%e9%81%8e%e6%9c%9f%e6%99%82%e9%96%93-vMgysGRWAh\">4. \u9375\u7684\u904e\u671f\u6642\u9593<\/h3>\n<p>Redis\u652f\u6301\u8a2d\u7f6e\u9375\u7684\u904e\u671f\u6642\u9593\uff0c\u4f7f\u7528 <code>EXPIRE<\/code> \u547d\u4ee4\u53ef\u4ee5\u8a2d\u7f6e\u4e00\u500b\u9375\u7684\u904e\u671f\u6642\u9593\uff08\u4ee5\u79d2\u70ba\u55ae\u4f4d\uff09\u3002<\/p>\n<pre><code>SET mykey \"Hello, Redis!\"\nEXPIRE mykey 10\n<\/code><\/pre>\n<p>\u4e0a\u8ff0\u547d\u4ee4\u5c07 <code>mykey<\/code> \u7684\u904e\u671f\u6642\u9593\u8a2d\u7f6e\u70ba10\u79d2\uff0c10\u79d2\u5f8c\u8a72\u9375\u5c07\u81ea\u52d5\u522a\u9664\u3002<\/p>\n<h3 id=\"5-%e5%93%88%e5%b8%8c%e6%93%8d%e4%bd%9c-vMgysGRWAh\">5. \u54c8\u5e0c\u64cd\u4f5c<\/h3>\n<p>Redis\u9084\u652f\u6301\u54c8\u5e0c\u6578\u64da\u7d50\u69cb\uff0c\u4f7f\u7528 <code>HSET<\/code> \u548c <code>HGET<\/code> \u547d\u4ee4\u53ef\u4ee5\u64cd\u4f5c\u54c8\u5e0c\u4e2d\u7684\u5b57\u6bb5\u3002<\/p>\n<pre><code>HSET user:1000 name \"Alice\"\nHGET user:1000 name\n<\/code><\/pre>\n<p>\u9019\u5c07\u5728\u54c8\u5e0c <code>user:1000<\/code> \u4e2d\u8a2d\u7f6e\u5b57\u6bb5 <code>name<\/code> \u7684\u503c\u70ba <code>\"Alice\"<\/code>\uff0c\u4e26\u901a\u904e <code>HGET<\/code> \u7372\u53d6\u8a72\u503c\u3002<\/p>\n<h2 id=\"%e9%80%b2%e9%9a%8e%e5%91%bd%e4%bb%a4-vMgysGRWAh\">\u9032\u968e\u547d\u4ee4<\/h2>\n<h3 id=\"1-%e5%88%97%e8%a1%a8%e6%93%8d%e4%bd%9c-vMgysGRWAh\">1. \u5217\u8868\u64cd\u4f5c<\/h3>\n<p>Redis\u7684\u5217\u8868\u652f\u6301\u5728\u5169\u7aef\u9032\u884c\u63d2\u5165\u548c\u522a\u9664\uff0c\u4f7f\u7528 <code>LPUSH<\/code> \u548c <code>RPUSH<\/code> \u547d\u4ee4\u53ef\u4ee5\u5728\u5217\u8868\u7684\u5de6\u5074\u548c\u53f3\u5074\u63d2\u5165\u5143\u7d20\u3002<\/p>\n<pre><code>LPUSH mylist \"item1\"\nRPUSH mylist \"item2\"\nLRANGE mylist 0 -1\n<\/code><\/pre>\n<p>\u9019\u5c07\u5728\u5217\u8868 <code>mylist<\/code> \u4e2d\u63d2\u5165\u5169\u500b\u5143\u7d20\uff0c\u4e26\u4f7f\u7528 <code>LRANGE<\/code> \u7372\u53d6\u6574\u500b\u5217\u8868\u7684\u5167\u5bb9\u3002<\/p>\n<h3 id=\"2-%e9%9b%86%e5%90%88%e6%93%8d%e4%bd%9c-vMgysGRWAh\">2. \u96c6\u5408\u64cd\u4f5c<\/h3>\n<p>\u96c6\u5408\u662f\u4e00\u7a2e\u7121\u5e8f\u4e14\u552f\u4e00\u7684\u6578\u64da\u7d50\u69cb\uff0c\u4f7f\u7528 <code>SADD<\/code> \u547d\u4ee4\u53ef\u4ee5\u5411\u96c6\u5408\u4e2d\u6dfb\u52a0\u5143\u7d20\u3002<\/p>\n<pre><code>SADD myset \"member1\"\nSADD myset \"member2\"\nSMEMBERS myset\n<\/code><\/pre>\n<p>\u9019\u5c07\u5411\u96c6\u5408 <code>myset<\/code> \u4e2d\u6dfb\u52a0\u5169\u500b\u6210\u54e1\uff0c\u4e26\u4f7f\u7528 <code>SMEMBERS<\/code> \u7372\u53d6\u96c6\u5408\u4e2d\u7684\u6240\u6709\u6210\u54e1\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-vMgysGRWAh\">\u7e3d\u7d50<\/h2>\n<p>Redis\u7684\u9375\u503c\u547d\u4ee4\u7c21\u55ae\u6613\u7528\uff0c\u80fd\u5920\u5feb\u901f\u6eff\u8db3\u5404\u7a2e\u6578\u64da\u5b58\u5132\u9700\u6c42\u3002\u7121\u8ad6\u662f\u57fa\u672c\u7684\u9375\u503c\u64cd\u4f5c\uff0c\u9084\u662f\u9032\u968e\u7684\u6578\u64da\u7d50\u69cb\u64cd\u4f5c\uff0cRedis\u90fd\u63d0\u4f9b\u4e86\u9748\u6d3b\u7684\u89e3\u6c7a\u65b9\u6848\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u80fd\u6578\u64da\u5b58\u5132\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u65b9\u6848\u53ef\u4ee5\u9032\u4e00\u6b65\u63d0\u5347\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002\u4e86\u89e3\u66f4\u591a\u95dc\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u638c\u63e1Redis\u9375\u503c\u547d\u4ee4\u7684\u5feb\u901f\u64cd\u4f5c\u6307\u5357\uff0c\u63d0\u5347\u6578\u64da\u8655\u7406\u6548\u7387\uff0c\u7c21\u5316\u958b\u767c\u6d41\u7a0b\uff0c\u52a9\u4f60\u8f15\u9b06\u7ba1\u7406\u6578\u64da\u5eab\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-166007","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/166007","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=166007"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/166007\/revisions"}],"predecessor-version":[{"id":166008,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/166007\/revisions\/166008"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=166007"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=166007"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=166007"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}