{"id":152571,"date":"2024-11-02T00:13:19","date_gmt":"2024-11-01T16:13:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/152571\/"},"modified":"2024-11-02T00:13:20","modified_gmt":"2024-11-01T16:13:20","slug":"%e6%9f%a5%e7%9c%8b-redis-%e7%89%b9%e5%ae%9a-key-%e7%9a%84%e5%80%bc%ef%bc%88redis-%e6%9f%a5%e7%9c%8b%e7%89%b9%e5%ae%9a-key%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/152571\/","title":{"rendered":"\u67e5\u770b Redis \u7279\u5b9a Key \u7684\u503c\uff08Redis \u67e5\u770b\u7279\u5b9a key\uff09"},"content":{"rendered":"<h1 id=\"%e6%9f%a5%e7%9c%8b-redis-%e7%89%b9%e5%ae%9a-key-%e7%9a%84%e5%80%bc%ef%bc%88redis-%e6%9f%a5%e7%9c%8b%e7%89%b9%e5%ae%9a-key%ef%bc%89-XkgkLWCUSF\">\u67e5\u770b Redis \u7279\u5b9a Key \u7684\u503c\uff08Redis \u67e5\u770b\u7279\u5b9a key\uff09<\/h1>\n<p>Redis \u662f\u4e00\u7a2e\u9ad8\u6548\u80fd\u7684\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\u4f5c\u70ba\u4e00\u500b\u958b\u6e90\u7684 NoSQL \u6578\u64da\u5eab\uff0cRedis \u63d0\u4f9b\u4e86\u591a\u7a2e\u6578\u64da\u7d50\u69cb\u548c\u64cd\u4f5c\uff0c\u8b93\u958b\u767c\u8005\u80fd\u5920\u9748\u6d3b\u5730\u7ba1\u7406\u6578\u64da\u3002\u5728\u65e5\u5e38\u4f7f\u7528\u4e2d\uff0c\u67e5\u770b\u7279\u5b9a Key \u7684\u503c\u662f\u975e\u5e38\u5e38\u898b\u7684\u9700\u6c42\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Redis \u4e2d\u67e5\u770b\u7279\u5b9a Key \u7684\u503c\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u6280\u5de7\u3002<\/p>\n<h2 id=\"%e5%9f%ba%e6%9c%ac%e5%91%bd%e4%bb%a4%ef%bc%9aget-XkgkLWCUSF\">\u57fa\u672c\u547d\u4ee4\uff1aGET<\/h2>\n<p>\u5728 Redis \u4e2d\uff0c\u6700\u57fa\u672c\u7684\u67e5\u770b Key \u503c\u7684\u547d\u4ee4\u662f <code>GET<\/code>\u3002\u9019\u500b\u547d\u4ee4\u7528\u65bc\u7372\u53d6\u6307\u5b9a Key \u7684\u503c\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 <code>GET<\/code> \u547d\u4ee4\u7684\u57fa\u672c\u8a9e\u6cd5\uff1a<\/p>\n<pre><code>GET key<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u6211\u5011\u6709\u4e00\u500b Key \u70ba <code>username<\/code> \u7684\u6578\u64da\uff0c\u4e26\u5e0c\u671b\u67e5\u770b\u5176\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>GET username<\/code><\/pre>\n<p>\u5982\u679c\u8a72 Key \u5b58\u5728\uff0cRedis \u5c07\u8fd4\u56de\u5176\u5c0d\u61c9\u7684\u503c\uff1b\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5247\u8fd4\u56de <code>(nil)<\/code>\u3002<\/p>\n<h2 id=\"%e6%9f%a5%e7%9c%8b%e5%a4%9a%e5%80%8b-key-%e7%9a%84%e5%80%bc%ef%bc%9amget-XkgkLWCUSF\">\u67e5\u770b\u591a\u500b Key \u7684\u503c\uff1aMGET<\/h2>\n<p>\u5982\u679c\u9700\u8981\u540c\u6642\u67e5\u770b\u591a\u500b Key \u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>MGET<\/code> \u547d\u4ee4\u3002\u9019\u500b\u547d\u4ee4\u5141\u8a31\u4e00\u6b21\u6027\u7372\u53d6\u591a\u500b Key \u7684\u503c\uff0c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>MGET key1 key2 key3 ...<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u82e5\u8981\u67e5\u770b <code>username<\/code> \u548c <code>email<\/code> \u5169\u500b Key \u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>MGET username email<\/code><\/pre>\n<p>\u9019\u6a23\uff0cRedis \u5c07\u8fd4\u56de\u4e00\u500b\u5305\u542b\u9019\u5169\u500b Key \u503c\u7684\u6578\u7d44\u3002<\/p>\n<h2 id=\"%e6%aa%a2%e6%9f%a5-key-%e6%98%af%e5%90%a6%e5%ad%98%e5%9c%a8%ef%bc%9aexists-XkgkLWCUSF\">\u6aa2\u67e5 Key \u662f\u5426\u5b58\u5728\uff1aEXISTS<\/h2>\n<p>\u5728\u67e5\u770b Key \u7684\u503c\u4e4b\u524d\uff0c\u6709\u6642\u9700\u8981\u5148\u78ba\u8a8d\u8a72 Key \u662f\u5426\u5b58\u5728\u3002\u53ef\u4ee5\u4f7f\u7528 <code>EXISTS<\/code> \u547d\u4ee4\u4f86\u6aa2\u67e5 Key \u7684\u5b58\u5728\u6027\uff0c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>EXISTS key<\/code><\/pre>\n<p>\u5982\u679c Key \u5b58\u5728\uff0c\u8a72\u547d\u4ee4\u5c07\u8fd4\u56de <code>1<\/code>\uff1b\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5247\u8fd4\u56de <code>0<\/code>\u3002<\/p>\n<h2 id=\"%e6%9f%a5%e7%9c%8b-key-%e7%9a%84%e9%a1%9e%e5%9e%8b%ef%bc%9atype-XkgkLWCUSF\">\u67e5\u770b Key \u7684\u985e\u578b\uff1aTYPE<\/h2>\n<p>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u4e86\u89e3 Key \u7684\u6578\u64da\u985e\u578b\u4e5f\u5f88\u91cd\u8981\u3002Redis \u63d0\u4f9b\u4e86 <code>TYPE<\/code> \u547d\u4ee4\u4f86\u67e5\u770b\u6307\u5b9a Key \u7684\u6578\u64da\u985e\u578b\uff0c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>TYPE key<\/code><\/pre>\n<p>\u9019\u500b\u547d\u4ee4\u5c07\u8fd4\u56de Key \u7684\u985e\u578b\uff0c\u4f8b\u5982 <code>string<\/code>\u3001<code>list<\/code>\u3001<code>set<\/code> \u7b49\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8-redis-cli-%e9%80%b2%e8%a1%8c%e6%93%8d%e4%bd%9c-XkgkLWCUSF\">\u4f7f\u7528 Redis CLI \u9032\u884c\u64cd\u4f5c<\/h2>\n<p>\u4ee5\u4e0a\u63d0\u5230\u7684\u6240\u6709\u547d\u4ee4\u90fd\u53ef\u4ee5\u901a\u904e Redis \u7684\u547d\u4ee4\u884c\u754c\u9762\uff08CLI\uff09\u9032\u884c\u64cd\u4f5c\u3002\u555f\u52d5 Redis CLI \u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre><code>redis-cli<\/code><\/pre>\n<p>\u9032\u5165 CLI \u5f8c\uff0c\u53ef\u4ee5\u76f4\u63a5\u8f38\u5165\u4e0a\u8ff0\u547d\u4ee4\u4f86\u67e5\u770b Key \u7684\u503c\u6216\u9032\u884c\u5176\u4ed6\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-XkgkLWCUSF\">\u7d50\u8ad6<\/h2>\n<p>\u5728 Redis \u4e2d\u67e5\u770b\u7279\u5b9a Key \u7684\u503c\u662f\u4e00\u500b\u57fa\u672c\u800c\u91cd\u8981\u7684\u64cd\u4f5c\u3002\u901a\u904e\u4f7f\u7528 <code>GET<\/code>\u3001<code>MGET<\/code>\u3001<code>EXISTS<\/code> \u548c <code>TYPE<\/code> \u7b49\u547d\u4ee4\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u548c\u6aa2\u7d22\u6578\u64da\u3002\u9019\u4e9b\u547d\u4ee4\u4e0d\u50c5\u7c21\u55ae\u6613\u7528\uff0c\u9084\u80fd\u5e6b\u52a9\u958b\u767c\u8005\u5feb\u901f\u5b9a\u4f4d\u554f\u984c\u548c\u512a\u5316\u6027\u80fd\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\u904b\u884c\u60a8\u7684 Redis \u6578\u64da\u5eab\uff0cServer.HK \u63d0\u4f9b\u4e86\u591a\u7a2e\u9078\u64c7\uff0c\u9069\u5408\u4e0d\u540c\u9700\u6c42\u7684\u7528\u6236\u3002\u7121\u8ad6\u662f\u9700\u8981\u9ad8\u6027\u80fd\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u9084\u662f\u9748\u6d3b\u7684 <a href=\"https:\/\/server.hk\">\u4e91\u4f3a\u670d\u5668<\/a>\uff0c\u6211\u5011\u90fd\u80fd\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u5728 Redis \u4e2d\u67e5\u770b\u7279\u5b9a Key \u7684\u503c\uff0c\u5feb\u901f\u83b7\u53d6\u6570\u636e\uff0c\u4f18\u5316\u6570\u636e\u5e93\u7ba1\u7406\uff0c\u63d0\u5347\u5e94\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-152571","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152571","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=152571"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152571\/revisions"}],"predecessor-version":[{"id":152572,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152571\/revisions\/152572"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=152571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=152571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=152571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}