{"id":3681,"date":"2022-08-15T09:16:39","date_gmt":"2022-08-15T01:16:39","guid":{"rendered":"https:\/\/www.zeroheart.xyz\/wordpress\/?p=3681"},"modified":"2022-08-15T09:17:38","modified_gmt":"2022-08-15T01:17:38","slug":"%e9%98%bf%e9%87%8c%e5%ae%98%e6%96%b9-redis-%e5%bc%80%e5%8f%91%e8%a7%84%e8%8c%83%ef%bc%8c%e4%bc%98%e9%9b%85%e9%81%bf%e5%9d%91%ef%bc%81%ef%bc%88%e8%bd%ac%e5%8f%91%e5%a4%87%e5%bf%98%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.zeroheart.xyz\/wordpress\/?p=3681","title":{"rendered":"\u963f\u91cc\u5b98\u65b9 Redis \u5f00\u53d1\u89c4\u8303\uff0c\u4f18\u96c5\u907f\u5751\uff01\uff08\u8f6c\u53d1\u5907\u5fd8\uff09"},"content":{"rendered":"\n<p>\u8f6c\u53d1\u81ea\uff1a<a href=\"https:\/\/mp.weixin.qq.com\/s\/KAtzbhLA1jjZV-ZuNIPNWw\">\u963f\u91cc\u5b98\u65b9 Redis \u5f00\u53d1\u89c4\u8303\uff0c\u4f18\u96c5\u907f\u5751\uff01 (qq.com)<\/a><\/p>\n\n\n\n<p>\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u5728\u4f7f\u7528\u963f\u91cc\u4e91Redis\u7684\u5f00\u53d1\u89c4\u8303\uff0c\u4ece\u4e0b\u9762\u51e0\u4e2a\u65b9\u9762\u8fdb\u884c\u8bf4\u660e\u3002<\/p>\n\n\n\n<ul><li>\u952e\u503c\u8bbe\u8ba1<\/li><li>\u547d\u4ee4\u4f7f\u7528<\/li><li>\u5ba2\u6237\u7aef\u4f7f\u7528<\/li><li>\u76f8\u5173\u5de5\u5177<\/li><li>\u5220\u9664bigkey<\/li><\/ul>\n\n\n\n<p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\u53ef\u4ee5\u51cf\u5c11\u4f7f\u7528Redis\u8fc7\u7a0b\u5e26\u6765\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e00\u3001\u952e\u503c\u8bbe\u8ba1<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1\u3001key\u540d\u8bbe\u8ba1<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u53ef\u8bfb\u6027\u548c\u53ef\u7ba1\u7406\u6027<\/h4>\n\n\n\n<p>\u4ee5\u4e1a\u52a1\u540d(\u6216\u6570\u636e\u5e93\u540d)\u4e3a\u524d\u7f00(\u9632\u6b62key\u51b2\u7a81)\uff0c\u7528\u5192\u53f7\u5206\u9694\uff0c\u6bd4\u5982\u4e1a\u52a1\u540d:\u8868\u540d:id<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ugc:video:1<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u7b80\u6d01\u6027<\/h4>\n\n\n\n<p>\u4fdd\u8bc1\u8bed\u4e49\u7684\u524d\u63d0\u4e0b\uff0c\u63a7\u5236key\u7684\u957f\u5ea6\uff0c\u5f53key\u8f83\u591a\u65f6\uff0c\u5185\u5b58\u5360\u7528\u4e5f\u4e0d\u5bb9\u5ffd\u89c6\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>user:{uid}:friends:messages:{mid}\u7b80\u5316\u4e3au:{uid}:fr:m:{mid}\u3002<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u4e0d\u8981\u5305\u542b\u7279\u6b8a\u5b57\u7b26<\/h4>\n\n\n\n<p>\u53cd\u4f8b\uff1a\u5305\u542b\u7a7a\u683c\u3001\u6362\u884c\u3001\u5355\u53cc\u5f15\u53f7\u4ee5\u53ca\u5176\u4ed6\u8f6c\u4e49\u5b57\u7b26<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2\u3001value\u8bbe\u8ba1<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u62d2\u7eddbigkey<\/h4>\n\n\n\n<p>\u9632\u6b62\u7f51\u5361\u6d41\u91cf\u3001\u6162\u67e5\u8be2\uff0cstring\u7c7b\u578b\u63a7\u5236\u572810KB\u4ee5\u5185\uff0chash\u3001list\u3001set\u3001zset\u5143\u7d20\u4e2a\u6570\u4e0d\u8981\u8d85\u8fc75000\u3002<\/p>\n\n\n\n<p>\u53cd\u4f8b\uff1a\u4e00\u4e2a\u5305\u542b200\u4e07\u4e2a\u5143\u7d20\u7684list\u3002<\/p>\n\n\n\n<p>\u975e\u5b57\u7b26\u4e32\u7684bigkey\uff0c\u4e0d\u8981\u4f7f\u7528del\u5220\u9664\uff0c\u4f7f\u7528hscan\u3001sscan\u3001zscan\u65b9\u5f0f\u6e10\u8fdb\u5f0f\u5220\u9664\uff0c\u540c\u65f6\u8981\u6ce8\u610f\u9632\u6b62bigkey\u8fc7\u671f\u65f6\u95f4\u81ea\u52a8\u5220\u9664\u95ee\u9898(\u4f8b\u5982\u4e00\u4e2a200\u4e07\u7684zset\u8bbe\u7f6e1\u5c0f\u65f6\u8fc7\u671f\uff0c\u4f1a\u89e6\u53d1del\u64cd\u4f5c\uff0c\u9020\u6210\u963b\u585e\uff0c\u800c\u4e14\u8be5\u64cd\u4f5c\u4e0d\u4f1a\u4e0d\u51fa\u73b0\u5728\u6162\u67e5\u8be2\u4e2d(latency\u53ef\u67e5))\uff0c\u67e5\u627e\u65b9\u6cd5\u548c\u5220\u9664\u65b9\u6cd5<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u9009\u62e9\u9002\u5408\u7684\u6570\u636e\u7c7b\u578b<\/h4>\n\n\n\n<p>\u4f8b\u5982\uff1a\u5b9e\u4f53\u7c7b\u578b(\u8981\u5408\u7406\u63a7\u5236\u548c\u4f7f\u7528\u6570\u636e\u7ed3\u6784\u5185\u5b58\u7f16\u7801\u4f18\u5316\u914d\u7f6e,\u4f8b\u5982ziplist\uff0c\u4f46\u4e5f\u8981\u6ce8\u610f\u8282\u7701\u5185\u5b58\u548c\u6027\u80fd\u4e4b\u95f4\u7684\u5e73\u8861)<\/p>\n\n\n\n<p>\u53cd\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>set&nbsp;user:1:name&nbsp;tomset&nbsp;user:1:age&nbsp;19set&nbsp;user:1:favor&nbsp;football<\/code><\/pre>\n\n\n\n<p>\u6b63\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hmset&nbsp;user:1&nbsp;name&nbsp;tom&nbsp;age&nbsp;19&nbsp;favor&nbsp;football<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u63a7\u5236key\u7684\u751f\u547d\u5468\u671f<\/h4>\n\n\n\n<p>redis\u4e0d\u662f\u5783\u573e\u6876\uff0c\u5efa\u8bae\u4f7f\u7528expire\u8bbe\u7f6e\u8fc7\u671f\u65f6\u95f4(\u6761\u4ef6\u5141\u8bb8\u53ef\u4ee5\u6253\u6563\u8fc7\u671f\u65f6\u95f4\uff0c\u9632\u6b62\u96c6\u4e2d\u8fc7\u671f)\uff0c\u4e0d\u8fc7\u671f\u7684\u6570\u636e\u91cd\u70b9\u5173\u6ce8idletime\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e8c\u3001\u547d\u4ee4\u4f7f\u7528<\/strong><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">1\u3001O(N)\u547d\u4ee4\u5173\u6ce8N\u7684\u6570\u91cf<\/h4>\n\n\n\n<p>\u4f8b\u5982hgetall\u3001lrange\u3001smembers\u3001zrange\u3001sinter\u7b49\u5e76\u975e\u4e0d\u80fd\u4f7f\u7528\uff0c\u4f46\u662f\u9700\u8981\u660e\u786eN\u7684\u503c\u3002\u6709\u904d\u5386\u7684\u9700\u6c42\u53ef\u4ee5\u4f7f\u7528hscan\u3001sscan\u3001zscan\u4ee3\u66ff\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2\u3001\u7981\u7528\u547d\u4ee4<\/h4>\n\n\n\n<p>\u7981\u6b62\u7ebf\u4e0a\u4f7f\u7528keys\u3001flushall\u3001flushdb\u7b49\uff0c\u901a\u8fc7redis\u7684rename\u673a\u5236\u7981\u6389\u547d\u4ee4\uff0c\u6216\u8005\u4f7f\u7528scan\u7684\u65b9\u5f0f\u6e10\u8fdb\u5f0f\u5904\u7406\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3\u3001\u5408\u7406\u4f7f\u7528select<\/h4>\n\n\n\n<p>redis\u7684\u591a\u6570\u636e\u5e93\u8f83\u5f31\uff0c\u4f7f\u7528\u6570\u5b57\u8fdb\u884c\u533a\u5206\uff0c\u5f88\u591a\u5ba2\u6237\u7aef\u652f\u6301\u8f83\u5dee\uff0c\u540c\u65f6\u591a\u4e1a\u52a1\u7528\u591a\u6570\u636e\u5e93\u5b9e\u9645\u8fd8\u662f\u5355\u7ebf\u7a0b\u5904\u7406\uff0c\u4f1a\u6709\u5e72\u6270\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4\u3001\u4f7f\u7528\u6279\u91cf\u64cd\u4f5c\u63d0\u9ad8\u6548\u7387<\/h4>\n\n\n\n<ul><li>\u539f\u751f\u547d\u4ee4\uff1a\u4f8b\u5982mget\u3001mset\u3002<\/li><li>\u975e\u539f\u751f\u547d\u4ee4\uff1a\u53ef\u4ee5\u4f7f\u7528pipeline\u63d0\u9ad8\u6548\u7387\u3002<\/li><\/ul>\n\n\n\n<p>\u4f46\u8981\u6ce8\u610f\u63a7\u5236\u4e00\u6b21\u6279\u91cf\u64cd\u4f5c\u7684<strong>\u5143\u7d20\u4e2a\u6570<\/strong>&nbsp;(\u4f8b\u5982500\u4ee5\u5185\uff0c\u5b9e\u9645\u4e5f\u548c\u5143\u7d20\u5b57\u8282\u6570\u6709\u5173)\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f\u4e24\u8005\u4e0d\u540c\uff1a<\/p>\n\n\n\n<ul><li>\u539f\u751f\u662f\u539f\u5b50\u64cd\u4f5c\uff0cpipeline\u662f\u975e\u539f\u5b50\u64cd\u4f5c\u3002<\/li><li>pipeline\u53ef\u4ee5\u6253\u5305\u4e0d\u540c\u7684\u547d\u4ee4\uff0c\u539f\u751f\u505a\u4e0d\u5230<\/li><li>pipeline\u9700\u8981\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u7aef\u540c\u65f6\u652f\u6301\u3002<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">5\u3001\u4e0d\u5efa\u8bae\u8fc7\u591a\u4f7f\u7528Redis\u4e8b\u52a1\u529f\u80fd<\/h4>\n\n\n\n<p>Redis\u7684\u4e8b\u52a1\u529f\u80fd\u8f83\u5f31(\u4e0d\u652f\u6301\u56de\u6eda)\uff0c\u800c\u4e14\u96c6\u7fa4\u7248\u672c(\u81ea\u7814\u548c\u5b98\u65b9)\u8981\u6c42\u4e00\u6b21\u4e8b\u52a1\u64cd\u4f5c\u7684key\u5fc5\u987b\u5728\u4e00\u4e2aslot\u4e0a(\u53ef\u4ee5\u4f7f\u7528hashtag\u529f\u80fd\u89e3\u51b3)<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">6\u3001Redis\u96c6\u7fa4\u7248\u672c\u5728\u4f7f\u7528Lua\u4e0a\u6709\u7279\u6b8a\u8981\u6c42<\/h4>\n\n\n\n<p>1\u3001\u6240\u6709key\u90fd\u5e94\u8be5\u7531 KEYS \u6570\u7ec4\u6765\u4f20\u9012\uff0credis.call\/pcall \u91cc\u9762\u8c03\u7528\u7684redis\u547d\u4ee4\uff0ckey\u7684\u4f4d\u7f6e\uff0c\u5fc5\u987b\u662fKEYS array, \u5426\u5219\u76f4\u63a5\u8fd4\u56deerror\uff0c&#8221;-ERR bad lua script for redis cluster, all the keys that the script uses should be passed using the KEYS arrayrn&#8221;<\/p>\n\n\n\n<p>2\u3001\u6240\u6709key\uff0c\u5fc5\u987b\u57281\u4e2aslot\u4e0a\uff0c\u5426\u5219\u76f4\u63a5\u8fd4\u56deerror, &#8220;-ERR eval\/evalsha command keys must in same slotrn&#8221;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">7\u3001monitor\u547d\u4ee4<\/h4>\n\n\n\n<p>\u5fc5\u8981\u60c5\u51b5\u4e0b\u4f7f\u7528monitor\u547d\u4ee4\u65f6\uff0c\u8981\u6ce8\u610f\u4e0d\u8981\u957f\u65f6\u95f4\u4f7f\u7528\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e09\u3001\u5ba2\u6237\u7aef\u4f7f\u7528<\/strong><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">1\u3001\u907f\u514d\u591a\u4e2a\u5e94\u7528\u4f7f\u7528\u4e00\u4e2aRedis\u5b9e\u4f8b<\/h4>\n\n\n\n<p>\u4e0d\u76f8\u5e72\u7684\u4e1a\u52a1\u62c6\u5206\uff0c\u516c\u5171\u6570\u636e\u505a\u670d\u52a1\u5316\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2\u3001\u4f7f\u7528\u8fde\u63a5\u6c60<\/h4>\n\n\n\n<p>\u53ef\u4ee5\u6709\u6548\u63a7\u5236\u8fde\u63a5\uff0c\u540c\u65f6\u63d0\u9ad8\u6548\u7387\uff0c\u6807\u51c6\u4f7f\u7528\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6267\u884c\u547d\u4ee4\u5982\u4e0b\uff1a<br>Jedis&nbsp;jedis&nbsp;=&nbsp;null;<br>try&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;jedis&nbsp;=&nbsp;jedisPool.getResource();<br>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u5177\u4f53\u7684\u547d\u4ee4<br>&nbsp;&nbsp;&nbsp;&nbsp;jedis.executeCommand()<br>}&nbsp;catch&nbsp;(Exception&nbsp;e)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;logger.error(\"op&nbsp;key&nbsp;{}&nbsp;error:&nbsp;\"&nbsp;+&nbsp;e.getMessage(),&nbsp;key,&nbsp;e);<br>}&nbsp;finally&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u6ce8\u610f\u8fd9\u91cc\u4e0d\u662f\u5173\u95ed\u8fde\u63a5\uff0c\u5728JedisPool\u6a21\u5f0f\u4e0b\uff0cJedis\u4f1a\u88ab\u5f52\u8fd8\u7ed9\u8d44\u6e90\u6c60\u3002<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(jedis&nbsp;!=&nbsp;null)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.close();<br>}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3\u3001\u7194\u65ad\u529f\u80fd<\/h4>\n\n\n\n<p>\u9ad8\u5e76\u53d1\u4e0b\u5efa\u8bae\u5ba2\u6237\u7aef\u6dfb\u52a0\u7194\u65ad\u529f\u80fd(\u4f8b\u5982netflix hystrix)<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4\u3001\u5408\u7406\u7684\u52a0\u5bc6<\/h4>\n\n\n\n<p>\u8bbe\u7f6e\u5408\u7406\u7684\u5bc6\u7801\uff0c\u5982\u6709\u5fc5\u8981\u53ef\u4ee5\u4f7f\u7528SSL\u52a0\u5bc6\u8bbf\u95ee\uff08\u963f\u91cc\u4e91Redis\u652f\u6301\uff09<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">5\u3001\u6dd8\u6c70\u7b56\u7565<\/h4>\n\n\n\n<p>\u6839\u636e\u81ea\u8eab\u4e1a\u52a1\u7c7b\u578b\uff0c\u9009\u597dmaxmemory-policy(\u6700\u5927\u5185\u5b58\u6dd8\u6c70\u7b56\u7565)\uff0c\u8bbe\u7f6e\u597d\u8fc7\u671f\u65f6\u95f4\u3002<\/p>\n\n\n\n<p>\u9ed8\u8ba4\u7b56\u7565\u662fvolatile-lru\uff0c\u5373\u8d85\u8fc7\u6700\u5927\u5185\u5b58\u540e\uff0c\u5728\u8fc7\u671f\u952e\u4e2d\u4f7f\u7528lru\u7b97\u6cd5\u8fdb\u884ckey\u7684\u5254\u9664\uff0c\u4fdd\u8bc1\u4e0d\u8fc7\u671f\u6570\u636e\u4e0d\u88ab\u5220\u9664\uff0c\u4f46\u662f\u53ef\u80fd\u4f1a\u51fa\u73b0OOM\u95ee\u9898\u3002<\/p>\n\n\n\n<p><strong>\u5176\u4ed6\u7b56\u7565\u5982\u4e0b\uff1a<\/strong><\/p>\n\n\n\n<ul><li>allkeys-lru\uff1a\u6839\u636eLRU\u7b97\u6cd5\u5220\u9664\u952e\uff0c\u4e0d\u7ba1\u6570\u636e\u6709\u6ca1\u6709\u8bbe\u7f6e\u8d85\u65f6\u5c5e\u6027\uff0c\u76f4\u5230\u817e\u51fa\u8db3\u591f\u7a7a\u95f4\u4e3a\u6b62\u3002<\/li><li>allkeys-random\uff1a\u968f\u673a\u5220\u9664\u6240\u6709\u952e\uff0c\u76f4\u5230\u817e\u51fa\u8db3\u591f\u7a7a\u95f4\u4e3a\u6b62\u3002<\/li><li>volatile-random:\u968f\u673a\u5220\u9664\u8fc7\u671f\u952e\uff0c\u76f4\u5230\u817e\u51fa\u8db3\u591f\u7a7a\u95f4\u4e3a\u6b62\u3002<\/li><li>volatile-ttl\uff1a\u6839\u636e\u952e\u503c\u5bf9\u8c61\u7684ttl\u5c5e\u6027\uff0c\u5220\u9664\u6700\u8fd1\u5c06\u8981\u8fc7\u671f\u6570\u636e\u3002\u5982\u679c\u6ca1\u6709\uff0c\u56de\u9000\u5230noeviction\u7b56\u7565\u3002<\/li><li>noeviction\uff1a\u4e0d\u4f1a\u5254\u9664\u4efb\u4f55\u6570\u636e\uff0c\u62d2\u7edd\u6240\u6709\u5199\u5165\u64cd\u4f5c\u5e76\u8fd4\u56de\u5ba2\u6237\u7aef\u9519\u8bef\u4fe1\u606f&#8221;(error) OOM command not allowed when used memory&#8221;\uff0c\u6b64\u65f6Redis\u53ea\u54cd\u5e94\u8bfb\u64cd\u4f5c\u3002<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u56db\u3001\u76f8\u5173\u5de5\u5177<\/strong><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">1\u3001\u6570\u636e\u540c\u6b65<\/h4>\n\n\n\n<p>redis\u95f4\u6570\u636e\u540c\u6b65\u53ef\u4ee5\u4f7f\u7528\uff1aredis-port<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2\u3001big key\u641c\u7d22<\/h4>\n\n\n\n<p>redis\u5927key\u641c\u7d22\u5de5\u5177<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3\u3001\u70ed\u70b9key\u5bfb\u627e<\/h4>\n\n\n\n<p>\u5185\u90e8\u5b9e\u73b0\u4f7f\u7528monitor\uff0c\u6240\u4ee5\u5efa\u8bae\u77ed\u65f6\u95f4\u4f7f\u7528facebook\u7684redis-faina \u963f\u91cc\u4e91Redis\u5df2\u7ecf\u5728\u5185\u6838\u5c42\u9762\u89e3\u51b3\u70ed\u70b9key\u95ee\u9898<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4e94\u3001\u5220\u9664bigkey<\/strong><\/h2>\n\n\n\n<ul><li>\u4e0b\u9762\u64cd\u4f5c\u53ef\u4ee5\u4f7f\u7528pipeline\u52a0\u901f\u3002<\/li><li>redis 4.0\u5df2\u7ecf\u652f\u6301key\u7684\u5f02\u6b65\u5220\u9664\uff0c\u6b22\u8fce\u4f7f\u7528\u3002<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">1\u3001Hash\u5220\u9664: hscan + hdel<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>public&nbsp;void&nbsp;delBigHash(String&nbsp;host,&nbsp;int&nbsp;port,&nbsp;String&nbsp;password,&nbsp;String&nbsp;bigHashKey)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;Jedis&nbsp;jedis&nbsp;=&nbsp;new&nbsp;Jedis(host,&nbsp;port);<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(password&nbsp;!=&nbsp;null&nbsp;&amp;&amp;&nbsp;!\"\".equals(password))&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.auth(password);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;ScanParams&nbsp;scanParams&nbsp;=&nbsp;new&nbsp;ScanParams().count(100);<br>&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;cursor&nbsp;=&nbsp;\"0\";<br>&nbsp;&nbsp;&nbsp;&nbsp;do&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ScanResult&lt;Entry&lt;String,&nbsp;String&gt;&gt;&nbsp;scanResult&nbsp;=&nbsp;jedis.hscan(bigHashKey,&nbsp;cursor,&nbsp;scanParams);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&lt;Entry&lt;String,&nbsp;String&gt;&gt;&nbsp;entryList&nbsp;=&nbsp;scanResult.getResult();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(entryList&nbsp;!=&nbsp;null&nbsp;&amp;&amp;&nbsp;!entryList.isEmpty())&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(Entry&lt;String,&nbsp;String&gt;&nbsp;entry&nbsp;:&nbsp;entryList)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.hdel(bigHashKey,&nbsp;entry.getKey());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cursor&nbsp;=&nbsp;scanResult.getStringCursor();<br>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;while&nbsp;(!\"0\".equals(cursor));<br><br>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u5220\u9664bigkey<br>&nbsp;&nbsp;&nbsp;&nbsp;jedis.del(bigHashKey);<br>}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2\u3001List\u5220\u9664: ltrim<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>public&nbsp;void&nbsp;delBigList(String&nbsp;host,&nbsp;int&nbsp;port,&nbsp;String&nbsp;password,&nbsp;String&nbsp;bigListKey)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;Jedis&nbsp;jedis&nbsp;=&nbsp;new&nbsp;Jedis(host,&nbsp;port);<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(password&nbsp;!=&nbsp;null&nbsp;&amp;&amp;&nbsp;!\"\".equals(password))&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.auth(password);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;long&nbsp;llen&nbsp;=&nbsp;jedis.llen(bigListKey);<br>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;counter&nbsp;=&nbsp;0;<br>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;left&nbsp;=&nbsp;100;<br>&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(counter&nbsp;&lt;&nbsp;llen)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u6bcf\u6b21\u4ece\u5de6\u4fa7\u622a\u6389100\u4e2a<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.ltrim(bigListKey,&nbsp;left,&nbsp;llen);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;counter&nbsp;+=&nbsp;left;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u6700\u7ec8\u5220\u9664key<br>&nbsp;&nbsp;&nbsp;&nbsp;jedis.del(bigListKey);<br>}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3\u3001Set\u5220\u9664: sscan + srem<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>public&nbsp;void&nbsp;delBigSet(String&nbsp;host,&nbsp;int&nbsp;port,&nbsp;String&nbsp;password,&nbsp;String&nbsp;bigSetKey)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;Jedis&nbsp;jedis&nbsp;=&nbsp;new&nbsp;Jedis(host,&nbsp;port);<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(password&nbsp;!=&nbsp;null&nbsp;&amp;&amp;&nbsp;!\"\".equals(password))&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.auth(password);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;ScanParams&nbsp;scanParams&nbsp;=&nbsp;new&nbsp;ScanParams().count(100);<br>&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;cursor&nbsp;=&nbsp;\"0\";<br>&nbsp;&nbsp;&nbsp;&nbsp;do&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ScanResult&lt;String&gt;&nbsp;scanResult&nbsp;=&nbsp;jedis.sscan(bigSetKey,&nbsp;cursor,&nbsp;scanParams);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&lt;String&gt;&nbsp;memberList&nbsp;=&nbsp;scanResult.getResult();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(memberList&nbsp;!=&nbsp;null&nbsp;&amp;&amp;&nbsp;!memberList.isEmpty())&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(String&nbsp;member&nbsp;:&nbsp;memberList)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.srem(bigSetKey,&nbsp;member);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cursor&nbsp;=&nbsp;scanResult.getStringCursor();<br>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;while&nbsp;(!\"0\".equals(cursor));<br><br>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u5220\u9664bigkey<br>&nbsp;&nbsp;&nbsp;&nbsp;jedis.del(bigSetKey);<br>}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">4\u3001SortedSet\u5220\u9664: zscan + zrem<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>public&nbsp;void&nbsp;delBigZset(String&nbsp;host,&nbsp;int&nbsp;port,&nbsp;String&nbsp;password,&nbsp;String&nbsp;bigZsetKey)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;Jedis&nbsp;jedis&nbsp;=&nbsp;new&nbsp;Jedis(host,&nbsp;port);<br>&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(password&nbsp;!=&nbsp;null&nbsp;&amp;&amp;&nbsp;!\"\".equals(password))&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.auth(password);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;ScanParams&nbsp;scanParams&nbsp;=&nbsp;new&nbsp;ScanParams().count(100);<br>&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;cursor&nbsp;=&nbsp;\"0\";<br>&nbsp;&nbsp;&nbsp;&nbsp;do&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ScanResult&lt;Tuple&gt;&nbsp;scanResult&nbsp;=&nbsp;jedis.zscan(bigZsetKey,&nbsp;cursor,&nbsp;scanParams);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&lt;Tuple&gt;&nbsp;tupleList&nbsp;=&nbsp;scanResult.getResult();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(tupleList&nbsp;!=&nbsp;null&nbsp;&amp;&amp;&nbsp;!tupleList.isEmpty())&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(Tuple&nbsp;tuple&nbsp;:&nbsp;tupleList)&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jedis.zrem(bigZsetKey,&nbsp;tuple.getElement());<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cursor&nbsp;=&nbsp;scanResult.getStringCursor();<br>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;while&nbsp;(!\"0\".equals(cursor));<br><br>&nbsp;&nbsp;&nbsp;&nbsp;\/\/\u5220\u9664bigkey<br>&nbsp;&nbsp;&nbsp;&nbsp;jedis.del(bigZsetKey);<br>}<br><\/code><\/pre>\n\n\n\n<p>\u6765\u6e90\uff1ayq.aliyun.com\/articles\/531067<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u53d1\u81ea\uff1a\u963f\u91cc\u5b98\u65b9 Redis \u5f00\u53d1\u89c4\u8303\uff0c\u4f18\u96c5\u907f\u5751\uff01 (qq.com) \u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u5728\u4f7f\u7528\u963f\u91cc\u4e91Redis\u7684\u5f00\u53d1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[119],"tags":[51],"_links":{"self":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3681"}],"collection":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3681"}],"version-history":[{"count":2,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3681\/revisions"}],"predecessor-version":[{"id":3684,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3681\/revisions\/3684"}],"wp:attachment":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}