{"id":126571,"date":"2024-10-26T05:50:19","date_gmt":"2024-10-25T21:50:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/126571\/"},"modified":"2024-10-26T05:50:19","modified_gmt":"2024-10-25T21:50:19","slug":"redis-%e8%83%bd%e5%a6%82%e4%bd%95%e5%ad%98%e5%84%b2%e6%95%b8%e5%ad%97","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/126571\/","title":{"rendered":"Redis \u80fd\u5982\u4f55\u5b58\u5132\u6578\u5b57"},"content":{"rendered":"<h1 id=\"redis-%e8%83%bd%e5%a6%82%e4%bd%95%e5%ad%98%e5%84%b2%e6%95%b8%e5%ad%97-ovdtcbnkyU\">Redis \u80fd\u5982\u4f55\u5b58\u5132\u6578\u5b57<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u4e16\u754c\u4e2d\uff0c\u5feb\u901f\u4e14\u9ad8\u6548\u7684\u6578\u64da\u5b58\u5132\u89e3\u6c7a\u65b9\u6848\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002Redis \u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6027\u80fd\u7684\u9375\u503c\u6578\u64da\u5eab\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u5834\u666f\u4e2d\uff0c\u7279\u5225\u662f\u5728\u9700\u8981\u5feb\u901f\u8b80\u53d6\u548c\u5beb\u5165\u7684\u61c9\u7528\u4e2d\u3002\u672c\u6587\u5c07\u63a2\u8a0e Redis \u5982\u4f55\u5b58\u5132\u6578\u5b57\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\u3002<\/p>\n<h2 id=\"redis-%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e6%a6%82%e8%bf%b0-ovdtcbnkyU\">Redis \u6578\u64da\u985e\u578b\u6982\u8ff0<\/h2>\n<p>Redis \u652f\u6301\u591a\u7a2e\u6578\u64da\u985e\u578b\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\u3001\u54c8\u5e0c\u3001\u5217\u8868\u3001\u96c6\u5408\u548c\u6709\u5e8f\u96c6\u5408\u3002\u5c0d\u65bc\u6578\u5b57\u7684\u5b58\u5132\uff0c\u6700\u5e38\u7528\u7684\u6578\u64da\u985e\u578b\u662f\u5b57\u7b26\u4e32\u548c\u54c8\u5e0c\u3002<\/p>\n<h3 id=\"1-%e5%ad%97%e7%ac%a6%e4%b8%b2-ovdtcbnkyU\">1. \u5b57\u7b26\u4e32<\/h3>\n<p>\u5728 Redis \u4e2d\uff0c\u5b57\u7b26\u4e32\u662f\u6700\u57fa\u672c\u7684\u6578\u64da\u985e\u578b\uff0c\u53ef\u4ee5\u5b58\u5132\u4efb\u4f55\u985e\u578b\u7684\u6578\u64da\uff0c\u5305\u62ec\u6578\u5b57\u3002\u5b57\u7b26\u4e32\u7684\u6700\u5927\u9577\u5ea6\u70ba 512MB\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528 Redis \u5b58\u5132\u548c\u64cd\u4f5c\u6578\u5b57\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>SET mynumber 100\nGET mynumber\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u4f7f\u7528 <code>SET<\/code> \u547d\u4ee4\u5c07\u6578\u5b57 100 \u5b58\u5132\u5728\u9375 <code>mynumber<\/code> \u4e2d\uff0c\u7136\u5f8c\u4f7f\u7528 <code>GET<\/code> \u547d\u4ee4\u4f86\u6aa2\u7d22\u5b83\u3002<\/p>\n<h3 id=\"2-%e5%93%88%e5%b8%8c-ovdtcbnkyU\">2. \u54c8\u5e0c<\/h3>\n<p>\u54c8\u5e0c\u662f\u4e00\u7a2e\u9375\u503c\u5c0d\u7684\u96c6\u5408\uff0c\u9069\u5408\u7528\u4f86\u5b58\u5132\u591a\u500b\u76f8\u95dc\u7684\u6578\u5b57\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u54c8\u5e0c\u4f86\u5b58\u5132\u7528\u6236\u7684\u591a\u500b\u5c6c\u6027\uff0c\u5982\u5e74\u9f61\u3001\u5206\u6578\u7b49\uff1a<\/p>\n<pre><code>HSET user:1000 age 30\nHSET user:1000 score 95\nHGET user:1000 age\nHGET user:1000 score\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u4f7f\u7528 <code>HSET<\/code> \u547d\u4ee4\u5c07\u7528\u6236\u7684\u5e74\u9f61\u548c\u5206\u6578\u5b58\u5132\u5728\u54c8\u5e0c\u4e2d\uff0c\u7136\u5f8c\u4f7f\u7528 <code>HGET<\/code> \u547d\u4ee4\u4f86\u6aa2\u7d22\u9019\u4e9b\u6578\u5b57\u3002<\/p>\n<h2 id=\"%e6%95%b8%e5%ad%97%e6%93%8d%e4%bd%9c-ovdtcbnkyU\">\u6578\u5b57\u64cd\u4f5c<\/h2>\n<p>Redis \u63d0\u4f9b\u4e86\u591a\u7a2e\u547d\u4ee4\u4f86\u64cd\u4f5c\u6578\u5b57\uff0c\u9019\u4f7f\u5f97\u5b83\u5728\u9700\u8981\u9032\u884c\u8a08\u7b97\u7684\u61c9\u7528\u4e2d\u975e\u5e38\u6709\u7528\u3002<\/p>\n<h3 id=\"1-%e5%a2%9e%e5%8a%a0%e5%92%8c%e6%b8%9b%e5%b0%91-ovdtcbnkyU\">1. \u589e\u52a0\u548c\u6e1b\u5c11<\/h3>\n<p>\u4f7f\u7528 <code>INCR<\/code> \u548c <code>DECR<\/code> \u547d\u4ee4\u53ef\u4ee5\u8f15\u9b06\u5730\u589e\u52a0\u6216\u6e1b\u5c11\u5b58\u5132\u5728\u5b57\u7b26\u4e32\u4e2d\u7684\u6578\u5b57\uff1a<\/p>\n<pre><code>INCR mynumber\nDECR mynumber\n<\/code><\/pre>\n<p>\u9019\u4e9b\u547d\u4ee4\u6703\u81ea\u52d5\u5c07 <code>mynumber<\/code> \u7684\u503c\u589e\u52a0\u6216\u6e1b\u5c11 1\u3002<\/p>\n<h3 id=\"2-%e5%8e%9f%e5%ad%90%e6%80%a7%e6%93%8d%e4%bd%9c-ovdtcbnkyU\">2. \u539f\u5b50\u6027\u64cd\u4f5c<\/h3>\n<p>Redis \u7684\u6578\u5b57\u64cd\u4f5c\u662f\u539f\u5b50\u6027\u7684\uff0c\u9019\u610f\u5473\u8457\u5728\u591a\u500b\u5ba2\u6236\u7aef\u540c\u6642\u8a2a\u554f\u6642\uff0c\u4e0d\u6703\u51fa\u73fe\u6578\u64da\u7af6\u722d\u7684\u554f\u984c\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>INCR user:1000:score\n<\/code><\/pre>\n<p>\u9019\u6a23\u53ef\u4ee5\u78ba\u4fdd\u5373\u4f7f\u591a\u500b\u8acb\u6c42\u540c\u6642\u589e\u52a0\u7528\u6236\u7684\u5206\u6578\uff0c\u6700\u7d42\u7684\u7d50\u679c\u4ecd\u7136\u662f\u6b63\u78ba\u7684\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e5%a0%b4%e6%99%af-ovdtcbnkyU\">\u4f7f\u7528\u5834\u666f<\/h2>\n<p>Redis \u5b58\u5132\u6578\u5b57\u7684\u80fd\u529b\u4f7f\u5176\u5728\u8a31\u591a\u5834\u666f\u4e2d\u975e\u5e38\u6709\u7528\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u8a08\u6578\u5668\uff1a\u53ef\u4ee5\u7528\u65bc\u7db2\u7ad9\u8a2a\u554f\u91cf\u3001\u9ede\u64ca\u91cf\u7b49\u7684\u8a08\u6578\u3002<\/li>\n<li>\u6392\u884c\u699c\uff1a\u4f7f\u7528\u6709\u5e8f\u96c6\u5408\u4f86\u5b58\u5132\u7528\u6236\u5206\u6578\uff0c\u4e26\u5feb\u901f\u6aa2\u7d22\u6392\u540d\u3002<\/li>\n<li>\u5be6\u6642\u7d71\u8a08\uff1a\u5728\u904a\u6232\u6216\u61c9\u7528\u4e2d\u5be6\u6642\u66f4\u65b0\u7528\u6236\u7684\u5206\u6578\u6216\u5176\u4ed6\u6578\u5b57\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-ovdtcbnkyU\">\u7e3d\u7d50<\/h2>\n<p>Redis \u63d0\u4f9b\u4e86\u9748\u6d3b\u4e14\u9ad8\u6548\u7684\u65b9\u5f0f\u4f86\u5b58\u5132\u548c\u64cd\u4f5c\u6578\u5b57\uff0c\u7121\u8ad6\u662f\u901a\u904e\u5b57\u7b26\u4e32\u9084\u662f\u54c8\u5e0c\uff0c\u5747\u80fd\u6eff\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002\u5176\u539f\u5b50\u6027\u64cd\u4f5c\u548c\u591a\u7a2e\u6578\u5b57\u64cd\u4f5c\u547d\u4ee4\u4f7f\u5f97 Redis \u6210\u70ba\u8655\u7406\u6578\u5b57\u7684\u7406\u60f3\u9078\u64c7\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6027\u80fd\u6578\u64da\u5b58\u5132\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u53ef\u4ee5\u9032\u4e00\u6b65\u63d0\u5347\u7cfb\u7d71\u7684\u6574\u9ad4\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis \u53ef\u9ad8\u6548\u5b58\u5132\u6578\u5b57\uff0c\u652f\u6301\u6574\u6578\u3001\u6d6e\u9ede\u6578\u53ca\u8a08\u6578\u5668\uff0c\u4e26\u63d0\u4f9b\u5feb\u901f\u67e5\u8a62\u548c\u64cd\u4f5c\uff0c\u9069\u5408\u9ad8\u6027\u80fd\u61c9\u7528\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-126571","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/126571","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=126571"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/126571\/revisions"}],"predecessor-version":[{"id":126572,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/126571\/revisions\/126572"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=126571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=126571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=126571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}