{"id":124977,"date":"2024-10-25T18:46:16","date_gmt":"2024-10-25T10:46:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/124977\/"},"modified":"2024-10-25T18:46:17","modified_gmt":"2024-10-25T10:46:17","slug":"redis-%e7%b0%a1%e5%96%ae%e6%93%8d%e4%bd%9c%e5%a2%9e%e5%8a%a0%e9%8d%b5%e5%80%bc%e5%b0%8d","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/124977\/","title":{"rendered":"Redis \u7c21\u55ae\u64cd\u4f5c\u589e\u52a0\u9375\u503c\u5c0d"},"content":{"rendered":"<h1 id=\"redis-%e7%b0%a1%e5%96%ae%e6%93%8d%e4%bd%9c%e5%a2%9e%e5%8a%a0%e9%8d%b5%e5%80%bc%e5%b0%8d-sfcBlNXaAx\">Redis \u7c21\u55ae\u64cd\u4f5c\u589e\u52a0\u9375\u503c\u5c0d<\/h1>\n<p>Redis \u662f\u4e00\u500b\u9ad8\u6548\u80fd\u7684\u9375\u503c\u5b58\u5132\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u6578\u64da\u7de9\u5b58\u3001\u6d88\u606f\u968a\u5217\u548c\u5be6\u6642\u6578\u64da\u5206\u6790\u7b49\u5834\u666f\u3002\u5b83\u7684\u7c21\u55ae\u6027\u548c\u9ad8\u6548\u6027\u4f7f\u5f97\u958b\u767c\u8005\u80fd\u5920\u5feb\u901f\u5730\u9032\u884c\u6578\u64da\u64cd\u4f5c\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Redis \u4e2d\u7c21\u55ae\u5730\u589e\u52a0\u9375\u503c\u5c0d\uff0c\u4e26\u63d0\u4f9b\u76f8\u95dc\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e9%8d%b5%e5%80%bc%e5%b0%8d%ef%bc%9f-sfcBlNXaAx\">\u4ec0\u9ebc\u662f\u9375\u503c\u5c0d\uff1f<\/h2>\n<p>\u5728 Redis \u4e2d\uff0c\u9375\u503c\u5c0d\u662f\u6578\u64da\u5b58\u5132\u7684\u57fa\u672c\u55ae\u4f4d\u3002\u6bcf\u500b\u9375\uff08key\uff09\u90fd\u662f\u552f\u4e00\u7684\uff0c\u4e26\u4e14\u53ef\u4ee5\u5c0d\u61c9\u5230\u4e00\u500b\u503c\uff08value\uff09\u3002\u503c\u53ef\u4ee5\u662f\u591a\u7a2e\u6578\u64da\u985e\u578b\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\u3001\u5217\u8868\u3001\u96c6\u5408\u3001\u54c8\u5e0c\u7b49\u3002\u9019\u7a2e\u7d50\u69cb\u4f7f\u5f97 Redis \u80fd\u5920\u9ad8\u6548\u5730\u5b58\u53d6\u548c\u7ba1\u7406\u6578\u64da\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-redis-sfcBlNXaAx\">\u5b89\u88dd Redis<\/h2>\n<p>\u5728\u958b\u59cb\u4f7f\u7528 Redis \u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u5b89\u88dd\u5b83\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\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<h2 id=\"%e9%80%a3%e6%8e%a5%e5%88%b0-redis-sfcBlNXaAx\">\u9023\u63a5\u5230 Redis<\/h2>\n<p>\u5b89\u88dd\u4e26\u555f\u52d5 Redis \u670d\u52d9\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528 Redis CLI \u4f86\u9023\u63a5\u5230 Redis \u4f3a\u670d\u5668\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u5165 Redis \u547d\u4ee4\u884c\u754c\u9762\uff1a<\/p>\n<pre><code>redis-cli\n<\/code><\/pre>\n<h2 id=\"%e5%a2%9e%e5%8a%a0%e9%8d%b5%e5%80%bc%e5%b0%8d-sfcBlNXaAx\">\u589e\u52a0\u9375\u503c\u5c0d<\/h2>\n<p>\u5728 Redis \u4e2d\u589e\u52a0\u9375\u503c\u5c0d\u975e\u5e38\u7c21\u55ae\u3002\u4f7f\u7528 <code>SET<\/code> \u547d\u4ee4\u53ef\u4ee5\u5c07\u4e00\u500b\u9375\u8207\u4e00\u500b\u503c\u9032\u884c\u95dc\u806f\u3002\u4ee5\u4e0b\u662f\u57fa\u672c\u7684\u8a9e\u6cd5\uff1a<\/p>\n<pre><code>SET key value\n<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u82e5\u8981\u5c07\u9375 <code>name<\/code> \u7684\u503c\u8a2d\u7f6e\u70ba <code>ServerHK<\/code>\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>SET name ServerHK\n<\/code><\/pre>\n<p>\u57f7\u884c\u5f8c\uff0cRedis \u5c07\u8fd4\u56de <code>OK<\/code>\uff0c\u8868\u793a\u64cd\u4f5c\u6210\u529f\u3002<\/p>\n<h2 id=\"%e6%aa%a2%e7%b4%a2%e9%8d%b5%e5%80%bc%e5%b0%8d-sfcBlNXaAx\">\u6aa2\u7d22\u9375\u503c\u5c0d<\/h2>\n<p>\u8981\u6aa2\u7d22\u5df2\u5b58\u5132\u7684\u9375\u503c\u5c0d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>GET<\/code> \u547d\u4ee4\u3002\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>GET key\n<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u82e5\u8981\u6aa2\u7d22\u9375 <code>name<\/code> \u7684\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>GET name\n<\/code><\/pre>\n<p>\u57f7\u884c\u5f8c\uff0cRedis \u5c07\u8fd4\u56de <code>ServerHK<\/code>\u3002<\/p>\n<h2 id=\"%e5%a2%9e%e5%8a%a0%e5%a4%9a%e5%80%8b%e9%8d%b5%e5%80%bc%e5%b0%8d-sfcBlNXaAx\">\u589e\u52a0\u591a\u500b\u9375\u503c\u5c0d<\/h2>\n<p>\u5982\u679c\u9700\u8981\u4e00\u6b21\u6027\u589e\u52a0\u591a\u500b\u9375\u503c\u5c0d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>MSET<\/code> \u547d\u4ee4\u3002\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>MSET key1 value1 key2 value2 ...\n<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u82e5\u8981\u540c\u6642\u8a2d\u7f6e <code>age<\/code> \u548c <code>location<\/code>\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>MSET age 5 location HongKong\n<\/code><\/pre>\n<p>\u9019\u6a23\u5c31\u53ef\u4ee5\u4e00\u6b21\u6027\u8a2d\u7f6e\u591a\u500b\u9375\u503c\u5c0d\uff0c\u64cd\u4f5c\u7c21\u4fbf\u4e14\u9ad8\u6548\u3002<\/p>\n<h2 id=\"%e5%b0%8f%e7%b5%90-sfcBlNXaAx\">\u5c0f\u7d50<\/h2>\n<p>Redis \u63d0\u4f9b\u4e86\u7c21\u55ae\u800c\u9ad8\u6548\u7684\u65b9\u5f0f\u4f86\u589e\u52a0\u548c\u7ba1\u7406\u9375\u503c\u5c0d\u3002\u901a\u904e\u4f7f\u7528 <code>SET<\/code> \u548c <code>MSET<\/code> \u547d\u4ee4\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u9032\u884c\u6578\u64da\u64cd\u4f5c\u3002\u7121\u8ad6\u662f\u55ae\u500b\u9375\u503c\u5c0d\u9084\u662f\u591a\u500b\u9375\u503c\u5c0d\u7684\u8a2d\u7f6e\uff0cRedis \u90fd\u80fd\u5920\u5feb\u901f\u97ff\u61c9\uff0c\u6eff\u8db3\u9ad8\u6027\u80fd\u7684\u9700\u6c42\u3002<\/p>\n<p>\u5982\u679c\u60a8\u5c0d\u65bc <a href=\"https:\/\/server.hk\">VPS<\/a> \u670d\u52d9\u6709\u8208\u8da3\uff0cServer.HK \u63d0\u4f9b\u7a69\u5b9a\u7684\u4f3a\u670d\u5668\u74b0\u5883\uff0c\u9069\u5408\u904b\u884c Redis \u7b49\u61c9\u7528\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u985e\u578b\u7684 <a href=\"https:\/\/server.hk\">\u4e91\u670d\u52a1\u5668<\/a>\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728Redis\u4e2d\u7c21\u55ae\u64cd\u4f5c\uff0c\u5feb\u901f\u589e\u52a0\u9375\u503c\u5c0d\uff0c\u63d0\u5347\u6578\u64da\u5b58\u53d6\u6548\u7387\uff0c\u8b93\u4f60\u7684\u61c9\u7528\u66f4\u5177\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-124977","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/124977","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=124977"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/124977\/revisions"}],"predecessor-version":[{"id":124978,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/124977\/revisions\/124978"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=124977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=124977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=124977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}