{"id":6279,"date":"2024-11-14T12:03:07","date_gmt":"2024-11-14T04:03:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6279\/"},"modified":"2024-11-14T12:03:07","modified_gmt":"2024-11-14T04:03:07","slug":"redis%e6%80%8e%e4%b9%88%e5%bf%ab%e9%80%9f%e5%88%a0%e9%99%a4key","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6279\/","title":{"rendered":"redis\u600e\u4e48\u5feb\u901f\u5220\u9664key"},"content":{"rendered":"<blockquote><p>\n  redis \u63d0\u4f9b\u591a\u79cd\u5feb\u901f\u5220\u9664 key \u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 del \u547d\u4ee4\u5220\u9664\u5355\u4e2a key\u3002\u4f7f\u7528 unlink \u547d\u4ee4\u5220\u9664\u591a\u4e2a key\u3002\u4f7f\u7528 keys \u547d\u4ee4\u548c eval \u547d\u4ee4\u6839\u636e\u6a21\u5f0f\u5220\u9664 key\u3002\u4f7f\u7528 lua \u811a\u672c\u63d0\u9ad8\u5220\u9664\u5927\u91cf key \u7684\u6027\u80fd\u3002\u4f7f\u7528 redis streams \u6839\u636e\u65f6\u95f4\u5220\u9664\u6570\u636e\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/25\/2024062515072846061.jpg\" class=\"aligncenter\" title=\"redis\u600e\u4e48\u5feb\u901f\u5220\u9664key\u63d2\u56fe\" alt=\"redis\u600e\u4e48\u5feb\u901f\u5220\u9664key\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5feb\u901f\u5220\u9664 Redis \u4e2d\u7684 Key<\/strong><\/p>\n<p>Redis \u63d0\u4f9b\u4e86\u591a\u79cd\u5feb\u901f\u5220\u9664 Key \u7684\u65b9\u6cd5\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u6570\u636e\u7684\u7ed3\u6784\u548c\u5e94\u7528\u573a\u666f\u3002<\/p>\n<p><strong>\u4f7f\u7528 DEL \u547d\u4ee4<\/strong><\/p>\n<p>\u8fd9\u662f\u5220\u9664\u5355\u4e2a Key \u7684\u6700\u7b80\u5355\u65b9\u6cd5\uff1a<\/p>\n<pre>DEL key1 key2 ...<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 UNLINK \u547d\u4ee4<\/strong><\/p>\n<p>UNLINK \u547d\u4ee4\u53ef\u4ee5\u5220\u9664\u591a\u4e2a Key\uff0c\u540c\u65f6\u4e0d\u4f1a\u963b\u585e\u5176\u4ed6\u64cd\u4f5c\uff1a<\/p>\n<pre>UNLINK key1 key2 ...<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 KEYS \u547d\u4ee4\u548c EVAL \u547d\u4ee4<\/strong><\/p>\n<p>\u5bf9\u4e8e\u9700\u8981\u6839\u636e\u6a21\u5f0f\u5220\u9664\u591a\u4e2a Key \u7684\u573a\u666f\uff0c\u53ef\u4ee5\u7ed3\u5408 KEYS \u548c EVAL \u547d\u4ee4\uff1a<\/p>\n<pre>KEYS pattern | EVAL 'local keys = redis.call(\"keys\", ARGV[1]); for i, key in ipairs(keys) do redis.call(\"DEL\", key) end' 0 pattern<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 Lua \u811a\u672c<\/strong><\/p>\n<p>Lua \u811a\u672c\u53ef\u4ee5\u63d0\u4f9b\u66f4\u9ad8\u7684\u6027\u80fd\uff0c\u5c24\u5176\u662f\u5728\u9700\u8981\u5220\u9664\u5927\u91cf Key \u65f6\uff1a<\/p>\n<pre>local keys = redis.call('keys', pattern)\nfor i, key in ipairs(keys) do\n    redis.call('del', key)\nend<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 Redis Streams<\/strong><\/p>\n<p>\u5bf9\u4e8e\u9700\u8981\u6839\u636e\u65f6\u95f4\u5220\u9664\u6570\u636e\u7684\u573a\u666f\uff0cRedis Streams \u63d0\u4f9b\u4e86 XTRIM \u548c XREADGROUP \u9009\u9879\u3002\u8fd9\u5141\u8bb8\u5728\u4e0d\u963b\u585e\u5176\u4ed6\u64cd\u4f5c\u7684\u60c5\u51b5\u4e0b\u5220\u9664\u8fc7\u671f\u6216\u8fc7\u65f6\u7684\u6d88\u606f\u3002<\/p>\n<p><strong>\u4f55\u65f6\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5\uff1f<\/strong><\/p>\n<ul>\n<li> <strong>DEL \u547d\u4ee4:<\/strong> \u5220\u9664\u5355\u4e2a Key \u65f6\u662f\u6700\u5feb\u7684\u9009\u62e9\u3002<\/li>\n<li> <strong>UNLINK \u547d\u4ee4:<\/strong> \u5220\u9664\u591a\u4e2a Key \u4e14\u4e0d\u9700\u8981\u7acb\u5373\u8fd4\u56de\u7ed3\u679c\u65f6\u3002<\/li>\n<li> <strong>KEYS \u548c EVAL \u547d\u4ee4:<\/strong> \u6839\u636e\u6a21\u5f0f\u5220\u9664\u5927\u91cf Key \u65f6\u3002<\/li>\n<li> <strong>Lua \u811a\u672c:<\/strong> \u6027\u80fd\u66f4\u9ad8\uff0c\u9002\u7528\u4e8e\u5220\u9664\u5927\u91cf Key \u65f6\u3002<\/li>\n<li> <strong>Redis Streams:<\/strong> \u6839\u636e\u65f6\u95f4\u5220\u9664\u6570\u636e\u65f6\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u5feb\u901f\u5220\u9664key\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>redis \u63d0\u4f9b\u591a\u79cd\u5feb\u901f\u5220\u9664 key \u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 del \u547d\u4ee4\u5220\u9664\u5355\u4e2a key\u3002\u4f7f\u7528 unlink \u547d\u4ee4\u5220\u9664\u591a\u4e2a key\u3002\u4f7f\u7528 keys \u547d\u4ee4\u548c eval \u547d\u4ee4\u6839\u636e\u6a21\u5f0f\u5220\u9664 key\u3002\u4f7f\u7528 lua \u811a\u672c\u63d0\u9ad8\u5220\u9664\u5927\u91cf key \u7684\u6027\u80fd\u3002\u4f7f\u7528 redis streams \u6839\u636e\u65f6\u95f4\u5220\u9664\u6570\u636e\u3002 \u5982\u4f55\u5feb\u901f\u5220\u9664 Redis \u4e2d\u7684 Key Redis \u63d0\u4f9b\u4e86\u591a\u79cd\u5feb\u901f\u5220\u9664 Key \u7684\u65b9\u6cd5\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u6570\u636e\u7684\u7ed3\u6784\u548c\u5e94\u7528\u573a\u666f\u3002 \u4f7f\u7528 DEL \u547d\u4ee4 \u8fd9\u662f\u5220\u9664\u5355\u4e2a Key \u7684\u6700\u7b80\u5355\u65b9\u6cd5\uff1a DEL key1 key2 &#8230; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 UNLINK \u547d\u4ee4 UNLINK \u547d\u4ee4\u53ef\u4ee5\u5220\u9664\u591a\u4e2a Key\uff0c\u540c\u65f6\u4e0d\u4f1a\u963b\u585e\u5176\u4ed6\u64cd\u4f5c\uff1a UNLINK key1 key2 &#8230; \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 KEYS \u547d\u4ee4\u548c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6279","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6279"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6279\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}