{"id":128877,"date":"2024-10-26T17:25:21","date_gmt":"2024-10-26T09:25:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/128877\/"},"modified":"2024-10-26T17:25:22","modified_gmt":"2024-10-26T09:25:22","slug":"redis%e5%af%a6%e7%8f%be%e6%95%b8%e6%93%9a%e5%ad%98%e5%84%b2%e7%9a%84%e4%b8%8d%e5%90%8c%e9%a1%9e%e5%9e%8b%e8%88%87%e5%a4%a7%e5%b0%8f%ef%bc%88redis-%e9%a1%9e%e5%9e%8b%e5%a4%a7%e5%b0%8f%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/128877\/","title":{"rendered":"Redis\u5be6\u73fe\u6578\u64da\u5b58\u5132\u7684\u4e0d\u540c\u985e\u578b\u8207\u5927\u5c0f\uff08redis \u985e\u578b\u5927\u5c0f\uff09"},"content":{"rendered":"<h1 id=\"redis%e5%af%a6%e7%8f%be%e6%95%b8%e6%93%9a%e5%ad%98%e5%84%b2%e7%9a%84%e4%b8%8d%e5%90%8c%e9%a1%9e%e5%9e%8b%e8%88%87%e5%a4%a7%e5%b0%8f-mZWyZGkNJc\">Redis\u5be6\u73fe\u6578\u64da\u5b58\u5132\u7684\u4e0d\u540c\u985e\u578b\u8207\u5927\u5c0f<\/h1>\n<p>Redis\u662f\u4e00\u500b\u9ad8\u6548\u7684\u958b\u6e90\u5167\u5b58\u6578\u64da\u7d50\u69cb\u5b58\u5132\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u6578\u64da\u7de9\u5b58\u3001\u6d88\u606f\u4ee3\u7406\u548c\u5be6\u6642\u6578\u64da\u8655\u7406\u7b49\u5834\u666f\u3002\u5b83\u652f\u6301\u591a\u7a2e\u6578\u64da\u985e\u578b\uff0c\u4e26\u4e14\u6bcf\u7a2e\u6578\u64da\u985e\u578b\u90fd\u6709\u5176\u7279\u5b9a\u7684\u5927\u5c0f\u9650\u5236\u548c\u4f7f\u7528\u5834\u666f\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eRedis\u7684\u4e0d\u540c\u6578\u64da\u985e\u578b\u53ca\u5176\u5927\u5c0f\u9650\u5236\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u7d50\u69cb\u4f86\u6eff\u8db3\u61c9\u7528\u9700\u6c42\u3002<\/p>\n<h2 id=\"redis%e7%9a%84%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b-mZWyZGkNJc\">Redis\u7684\u6578\u64da\u985e\u578b<\/h2>\n<p>Redis\u652f\u6301\u591a\u7a2e\u6578\u64da\u985e\u578b\uff0c\u4e3b\u8981\u5305\u62ec\u4ee5\u4e0b\u5e7e\u7a2e\uff1a<\/p>\n<ul>\n<li><strong>\u5b57\u7b26\u4e32\uff08String\uff09<\/strong><\/li>\n<li><strong>\u54c8\u5e0c\uff08Hash\uff09<\/strong><\/li>\n<li><strong>\u5217\u8868\uff08List\uff09<\/strong><\/li>\n<li><strong>\u96c6\u5408\uff08Set\uff09<\/strong><\/li>\n<li><strong>\u6709\u5e8f\u96c6\u5408\uff08Sorted Set\uff09<\/strong><\/li>\n<li><strong>\u4f4d\u5716\uff08Bitmap\uff09<\/strong><\/li>\n<li><strong>\u8d85\u65e5\u5fd7\uff08HyperLogLog\uff09<\/strong><\/li>\n<li><strong>\u5730\u7406\u7a7a\u9593\uff08Geospatial\uff09<\/strong><\/li>\n<\/ul>\n<h3 id=\"1-%e5%ad%97%e7%ac%a6%e4%b8%b2%ef%bc%88string%ef%bc%89-mZWyZGkNJc\">1. \u5b57\u7b26\u4e32\uff08String\uff09<\/h3>\n<p>\u5b57\u7b26\u4e32\u662fRedis\u4e2d\u6700\u57fa\u672c\u7684\u6578\u64da\u985e\u578b\uff0c\u53ef\u4ee5\u5b58\u5132\u4efb\u4f55\u985e\u578b\u7684\u6578\u64da\uff0c\u5305\u62ec\u6587\u672c\u3001\u6578\u5b57\u548c\u4e8c\u9032\u5236\u6578\u64da\u3002\u6bcf\u500b\u5b57\u7b26\u4e32\u7684\u5927\u5c0f\u9650\u5236\u70ba512MB\u3002\u5b57\u7b26\u4e32\u7684\u64cd\u4f5c\u975e\u5e38\u9748\u6d3b\uff0c\u652f\u6301\u8a2d\u7f6e\u3001\u7372\u53d6\u3001\u589e\u6e1b\u7b49\u591a\u7a2e\u64cd\u4f5c\u3002<\/p>\n<pre><code>SET key \"value\"\nGET key\n<\/code><\/pre>\n<h3 id=\"2-%e5%93%88%e5%b8%8c%ef%bc%88hash%ef%bc%89-mZWyZGkNJc\">2. \u54c8\u5e0c\uff08Hash\uff09<\/h3>\n<p>\u54c8\u5e0c\u662f\u4e00\u7a2e\u9375\u503c\u5c0d\u96c6\u5408\uff0c\u9069\u5408\u7528\u65bc\u5b58\u5132\u5c0d\u8c61\u7684\u5c6c\u6027\u3002\u6bcf\u500b\u54c8\u5e0c\u6700\u591a\u53ef\u4ee5\u5305\u542b2^32 &#8211; 1\u500b\u9375\u503c\u5c0d\uff0c\u9019\u4f7f\u5f97\u54c8\u5e0c\u5728\u5b58\u5132\u7d50\u69cb\u5316\u6578\u64da\u6642\u975e\u5e38\u9ad8\u6548\u3002<\/p>\n<pre><code>HSET user:1000 name \"Alice\"\nHGET user:1000 name\n<\/code><\/pre>\n<h3 id=\"3-%e5%88%97%e8%a1%a8%ef%bc%88list%ef%bc%89-mZWyZGkNJc\">3. \u5217\u8868\uff08List\uff09<\/h3>\n<p>\u5217\u8868\u662f\u4e00\u500b\u6709\u5e8f\u7684\u5b57\u7b26\u4e32\u96c6\u5408\uff0c\u652f\u6301\u5f9e\u5169\u7aef\u63d2\u5165\u548c\u522a\u9664\u5143\u7d20\u3002\u5217\u8868\u7684\u5927\u5c0f\u9650\u5236\u70ba2^32 &#8211; 1\u500b\u5143\u7d20\uff0c\u9069\u5408\u7528\u65bc\u5be6\u73fe\u6d88\u606f\u968a\u5217\u7b49\u5834\u666f\u3002<\/p>\n<pre><code>LPUSH mylist \"item1\"\nRPUSH mylist \"item2\"\nLRANGE mylist 0 -1\n<\/code><\/pre>\n<h3 id=\"4-%e9%9b%86%e5%90%88%ef%bc%88set%ef%bc%89-mZWyZGkNJc\">4. \u96c6\u5408\uff08Set\uff09<\/h3>\n<p>\u96c6\u5408\u662f\u4e00\u500b\u7121\u5e8f\u7684\u5b57\u7b26\u4e32\u96c6\u5408\uff0c\u652f\u6301\u5feb\u901f\u7684\u6dfb\u52a0\u3001\u522a\u9664\u548c\u67e5\u8a62\u64cd\u4f5c\u3002\u6bcf\u500b\u96c6\u5408\u7684\u5927\u5c0f\u9650\u5236\u70ba2^32 &#8211; 1\u500b\u5143\u7d20\uff0c\u9069\u5408\u7528\u65bc\u53bb\u91cd\u548c\u7d71\u8a08\u7b49\u5834\u666f\u3002<\/p>\n<pre><code>SADD myset \"value1\"\nSISMEMBER myset \"value1\"\n<\/code><\/pre>\n<h3 id=\"5-%e6%9c%89%e5%ba%8f%e9%9b%86%e5%90%88%ef%bc%88sorted-set%ef%bc%89-mZWyZGkNJc\">5. \u6709\u5e8f\u96c6\u5408\uff08Sorted Set\uff09<\/h3>\n<p>\u6709\u5e8f\u96c6\u5408\u662f\u5e36\u6709\u5206\u6578\u7684\u5b57\u7b26\u4e32\u96c6\u5408\uff0c\u652f\u6301\u6839\u64da\u5206\u6578\u9032\u884c\u6392\u5e8f\u3002\u6bcf\u500b\u6709\u5e8f\u96c6\u5408\u7684\u5927\u5c0f\u9650\u5236\u70ba2^32 &#8211; 1\u500b\u5143\u7d20\uff0c\u9069\u5408\u7528\u65bc\u6392\u884c\u699c\u7b49\u61c9\u7528\u3002<\/p>\n<pre><code>ZADD myzset 1 \"value1\"\nZRANGE myzset 0 -1 WITHSCORES\n<\/code><\/pre>\n<h3 id=\"6-%e4%bd%8d%e5%9c%96%ef%bc%88bitmap%ef%bc%89-mZWyZGkNJc\">6. \u4f4d\u5716\uff08Bitmap\uff09<\/h3>\n<p>\u4f4d\u5716\u662f\u4e00\u7a2e\u7279\u6b8a\u7684\u6578\u64da\u7d50\u69cb\uff0c\u7528\u65bc\u9ad8\u6548\u5730\u5b58\u5132\u548c\u64cd\u4f5c\u4e8c\u9032\u5236\u6578\u64da\u3002\u4f4d\u5716\u7684\u5927\u5c0f\u9650\u5236\u70ba2^32\u4f4d\uff0c\u9069\u5408\u7528\u65bc\u7d71\u8a08\u548c\u8a08\u7b97\u7b49\u5834\u666f\u3002<\/p>\n<pre><code>SETBIT mybitmap 0 1\nGETBIT mybitmap 0\n<\/code><\/pre>\n<h3 id=\"7-%e8%b6%85%e6%97%a5%e5%bf%97%ef%bc%88hyperloglog%ef%bc%89-mZWyZGkNJc\">7. \u8d85\u65e5\u5fd7\uff08HyperLogLog\uff09<\/h3>\n<p>\u8d85\u65e5\u5fd7\u662f\u4e00\u7a2e\u6982\u7387\u6027\u6578\u64da\u7d50\u69cb\uff0c\u7528\u65bc\u8a08\u7b97\u552f\u4e00\u5143\u7d20\u7684\u57fa\u6578\u3002\u5b83\u7684\u5927\u5c0f\u56fa\u5b9a\u70ba12KB\uff0c\u9069\u5408\u7528\u65bc\u5927\u6578\u64da\u5834\u666f\u4e2d\u7684\u53bb\u91cd\u8a08\u7b97\u3002<\/p>\n<pre><code>PFADD myhyperloglog \"value1\"\nPFCOUNT myhyperloglog\n<\/code><\/pre>\n<h3 id=\"8-%e5%9c%b0%e7%90%86%e7%a9%ba%e9%96%93%ef%bc%88geospatial%ef%bc%89-mZWyZGkNJc\">8. \u5730\u7406\u7a7a\u9593\uff08Geospatial\uff09<\/h3>\n<p>\u5730\u7406\u7a7a\u9593\u6578\u64da\u985e\u578b\u7528\u65bc\u5b58\u5132\u5730\u7406\u4f4d\u7f6e\u6578\u64da\uff0c\u652f\u6301\u7bc4\u570d\u67e5\u8a62\u548c\u8ddd\u96e2\u8a08\u7b97\u3002\u6bcf\u500b\u5730\u7406\u7a7a\u9593\u96c6\u5408\u7684\u5927\u5c0f\u9650\u5236\u70ba2^32 &#8211; 1\u500b\u5143\u7d20\u3002<\/p>\n<pre><code>GEOADD mygeoset 13.361389 38.115556 \"Palermo\"\nGEODIST mygeoset \"Palermo\" \"Catania\"\n<\/code><\/pre>\n<h2 id=\"%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e7%9a%84%e9%81%b8%e6%93%87%e8%88%87%e6%87%89%e7%94%a8-mZWyZGkNJc\">\u6578\u64da\u985e\u578b\u7684\u9078\u64c7\u8207\u61c9\u7528<\/h2>\n<p>\u5728\u9078\u64c7Redis\u6578\u64da\u985e\u578b\u6642\uff0c\u958b\u767c\u8005\u61c9\u6839\u64da\u5177\u9ad4\u7684\u61c9\u7528\u9700\u6c42\u4f86\u6c7a\u5b9a\u3002\u4f8b\u5982\uff0c\u5982\u679c\u9700\u8981\u5b58\u5132\u7528\u6236\u4fe1\u606f\uff0c\u54c8\u5e0c\u985e\u578b\u53ef\u80fd\u662f\u6700\u4f73\u9078\u64c7\uff1b\u5982\u679c\u9700\u8981\u5be6\u73fe\u6d88\u606f\u968a\u5217\uff0c\u5247\u53ef\u4ee5\u9078\u64c7\u5217\u8868\u985e\u578b\u3002\u4e86\u89e3\u6bcf\u7a2e\u6578\u64da\u985e\u578b\u7684\u7279\u6027\u548c\u5927\u5c0f\u9650\u5236\uff0c\u6709\u52a9\u65bc\u63d0\u9ad8\u61c9\u7528\u7684\u6027\u80fd\u548c\u6548\u7387\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-mZWyZGkNJc\">\u7e3d\u7d50<\/h2>\n<p>Redis\u63d0\u4f9b\u4e86\u591a\u7a2e\u9748\u6d3b\u7684\u6578\u64da\u985e\u578b\uff0c\u6bcf\u7a2e\u6578\u64da\u985e\u578b\u90fd\u6709\u5176\u7279\u5b9a\u7684\u5927\u5c0f\u9650\u5236\u548c\u4f7f\u7528\u5834\u666f\u3002\u958b\u767c\u8005\u5728\u9078\u64c7\u6578\u64da\u985e\u578b\u6642\uff0c\u61c9\u6839\u64da\u5be6\u969b\u9700\u6c42\u9032\u884c\u5408\u7406\u9078\u64c7\uff0c\u4ee5\u9054\u5230\u6700\u4f73\u7684\u6027\u80fd\u548c\u6548\u7387\u3002\u82e5\u60a8\u9700\u8981\u9032\u4e00\u6b65\u4e86\u89e3\u5982\u4f55\u5728\u60a8\u7684\u9805\u76ee\u4e2d\u4f7f\u7528Redis\uff0c\u6216\u5c0b\u627e\u5408\u9069\u7684<a href=\"https:\/\/server.hk\">VPS<\/a>\u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22Redis\u4e2d\u4e0d\u540c\u6578\u64da\u985e\u578b\u53ca\u5176\u5927\u5c0f\uff0c\u4e86\u89e3\u5982\u4f55\u6709\u6548\u7ba1\u7406\u548c\u5b58\u5132\u6578\u64da\u4ee5\u63d0\u5347\u6027\u80fd\u548c\u6548\u7387\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-128877","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/128877","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=128877"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/128877\/revisions"}],"predecessor-version":[{"id":128878,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/128877\/revisions\/128878"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=128877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=128877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=128877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}