{"id":40528,"date":"2025-05-29T09:38:10","date_gmt":"2025-05-29T01:38:10","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/40528.html"},"modified":"2025-05-29T09:38:10","modified_gmt":"2025-05-29T01:38:10","slug":"%e3%80%90redis%e5%8e%9f%e7%90%86%e7%af%87%e3%80%91%e5%ba%95%e5%b1%82%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/40528.html","title":{"rendered":"\u3010redis\u539f\u7406\u7bc7\u3011\u5e95\u5c42\u6570\u636e\u7ed3\u6784"},"content":{"rendered":"<h3>SDS<\/h3>\n<p>Redis\u662f\u57fa\u4e8eC\u8bed\u8a00\u5b9e\u73b0\u7684&#xff0c;\u4f46\u662fRedis\u4e2d\u5927\u91cf\u4f7f\u7528\u7684\u5b57\u7b26\u4e32\u5e76\u6ca1\u6709\u76f4\u63a5\u4f7f\u7528C\u8bed\u8a00\u5b57\u7b26\u4e32\u3002<\/p>\n<h4>\u4e00\u3001SDS \u7684\u8bbe\u8ba1\u52a8\u673a<\/h4>\n<p>\u4f20\u7edf C \u5b57\u7b26\u4e32\u4ee5 \\\\0 \u7ed3\u5c3e&#xff0c;\u5b58\u5728\u4ee5\u4e0b\u95ee\u9898&#xff1a;<\/p>\n<li>\u6027\u80fd\u74f6\u9888&#xff1a;\u83b7\u53d6\u957f\u5ea6\u9700\u904d\u5386\u5b57\u7b26\u6570\u7ec4&#xff0c;\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\u3002<\/li>\n<li>\u7f13\u51b2\u533a\u6ea2\u51fa&#xff1a;\u62fc\u63a5\u64cd\u4f5c\u53ef\u80fd\u8986\u76d6\u76f8\u90bb\u5185\u5b58\u3002<\/li>\n<li>\u4e8c\u8fdb\u5236\u4e0d\u5b89\u5168&#xff1a;\u65e0\u6cd5\u5b58\u50a8\u542b \\\\0 \u7684\u6570\u636e&#xff08;\u5982\u56fe\u7247\u3001\u97f3\u9891&#xff09;\u3002<\/li>\n<li>\u5185\u5b58\u91cd\u5206\u914d\u9891\u7e41&#xff1a;\u6bcf\u6b21\u4fee\u6539\u53ef\u80fd\u89e6\u53d1 realloc&#xff0c;\u5f71\u54cd\u6027\u80fd\u3002<\/li>\n<p>SDS \u901a\u8fc7 \u7ed3\u6784\u4f53\u5c01\u88c5\u5143\u6570\u636e \u548c \u5185\u5b58\u9884\u5206\u914d\u7b56\u7565 \u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u3002<\/p>\n<h4>\u4e8c\u3001SDS \u7684\u7ed3\u6784\u8bbe\u8ba1<\/h4>\n<p>SDS \u7684\u5e95\u5c42\u7ed3\u6784\u7531 Header&#xff08;\u5143\u6570\u636e&#xff09; \u548c \u5b57\u7b26\u6570\u7ec4&#xff08;\u5b9e\u9645\u6570\u636e&#xff09; \u7ec4\u6210\u3002\u4ee5 Redis 5.0 \u4e3a\u4f8b&#xff0c;\u5176\u7ed3\u6784\u5b9a\u4e49\u5982\u4e0b&#xff1a;<\/p>\n<p><span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">sdshdr<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token class-name\">uint8_t<\/span> len<span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ \u5df2\u4f7f\u7528\u7684\u5b57\u8282\u6570&#xff08;\u5b57\u7b26\u4e32\u771f\u5b9e\u957f\u5ea6&#xff09;<\/span><br \/>\n    <span class=\"token class-name\">uint8_t<\/span> alloc<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u5206\u914d\u7684\u603b\u5b57\u8282\u6570&#xff08;\u4e0d\u542b Header&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">unsigned<\/span> <span class=\"token keyword\">char<\/span> flags<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ SDS \u7c7b\u578b\u6807\u8bb0&#xff08;\u5982 sdshdr5\u3001sdshdr8&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">char<\/span> buf<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ \u67d4\u6027\u6570\u7ec4&#xff0c;\u5b58\u50a8\u5b9e\u9645\u5b57\u7b26&#xff08;\u4ee5 &#039;\\\\0&#039; \u7ed3\u5c3e&#xff09;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h5>\u5185\u5b58\u5e03\u5c40<\/h5>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250529013808-6837ba8011140.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>\u4e09\u3001SDS \u7684\u6838\u5fc3\u539f\u7406<\/h4>\n<h5>1. O(1) \u65f6\u95f4\u590d\u6742\u5ea6\u83b7\u53d6\u957f\u5ea6<\/h5>\n<ul>\n<li>\u4f20\u7edf C \u5b57\u7b26\u4e32&#xff1a;\u9700\u904d\u5386\u76f4\u5230 \\\\0&#xff0c;\u65f6\u95f4\u590d\u6742\u5ea6 O(n)\u3002<\/li>\n<li>SDS&#xff1a;\u76f4\u63a5\u8bfb\u53d6 len \u5c5e\u6027&#xff0c;\u65f6\u95f4\u590d\u6742\u5ea6 O(1)\u3002<\/li>\n<\/ul>\n<h5>2. \u675c\u7edd\u7f13\u51b2\u533a\u6ea2\u51fa<\/h5>\n<ul>\n<li>\u81ea\u52a8\u6269\u5bb9\u68c0\u67e5&#xff1a;\u4fee\u6539\u5b57\u7b26\u4e32\u524d&#xff0c;\u68c0\u67e5 alloc &#8211; len \u7684\u5269\u4f59\u7a7a\u95f4\u3002\n<ul>\n<li>\u7a7a\u95f4\u4e0d\u8db3\u65f6&#xff1a;\u89e6\u53d1\u6269\u5bb9\u673a\u5236&#xff0c;\u6269\u5c55\u81f3 \u65b0\u957f\u5ea6 * 2&#xff08;\u5c0f\u4e8e 1MB&#xff09;\u6216 \u65b0\u957f\u5ea6 <\/li>\n<li>&#043; 1MB&#xff08;\u5927\u4e8e 1MB&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u793a\u4f8b&#xff1a; \u539f\u5b57\u7b26\u4e32\u957f\u5ea6 5MB&#xff0c;\u8ffd\u52a0 2MB \u6570\u636e&#xff0c;\u65b0\u5206\u914d\u7a7a\u95f4\u4e3a 5MB &#043; 2MB &#043; 1MB &#061; 8MB\u3002<\/li>\n<\/ul>\n<h5>3. \u4e8c\u8fdb\u5236\u5b89\u5168<\/h5>\n<ul>\n<li>\u4e0d\u4f9d\u8d56 \\\\0 \u7ec8\u6b62\u7b26&#xff1a;\u901a\u8fc7 len \u8bb0\u5f55\u771f\u5b9e\u957f\u5ea6&#xff0c;\u5141\u8bb8\u5b58\u50a8\u4efb\u610f\u4e8c\u8fdb\u5236\u6570\u636e&#xff08;\u5305\u62ec \\\\0&#xff09;\u3002<\/li>\n<li>\u793a\u4f8b&#xff1a; \u5b58\u50a8 JPEG \u56fe\u7247\u6570\u636e\u65f6&#xff0c;\u5373\u4f7f\u5185\u5bb9\u542b\u591a\u4e2a \\\\0&#xff0c;SDS \u4e5f\u80fd\u5b8c\u6574\u4fdd\u5b58\u3002<\/li>\n<\/ul>\n<h5>4. \u5185\u5b58\u4f18\u5316\u7b56\u7565<\/h5>\n<ul>\n<li>\u9884\u5206\u914d&#xff08;Pre-allocation&#xff09;&#xff1a; \u6269\u5bb9\u65f6\u9884\u7559\u989d\u5916\u7a7a\u95f4&#xff0c;\u51cf\u5c11\u540e\u7eed\u4fee\u6539\u65f6\u7684\u5185\u5b58\u5206\u914d\u6b21\u6570\u3002<\/li>\n<li>\u60f0\u6027\u91ca\u653e&#xff08;Lazy Free&#xff09;&#xff1a; \u7f29\u77ed\u5b57\u7b26\u4e32\u65f6\u4e0d\u7acb\u5373\u91ca\u653e\u5185\u5b58&#xff0c;\u4ec5\u51cf\u5c11 len&#xff0c;\u4fdd\u7559 alloc \u4f9b\u540e\u7eed\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<h3>Intset<\/h3>\n<p>Redis \u7684 intset&#xff08;\u6574\u6570\u96c6\u5408&#xff09; \u662f\u4e00\u79cd\u9ad8\u6548\u7684\u6709\u5e8f\u6574\u6570\u5b58\u50a8\u7ed3\u6784&#xff0c;\u4e13\u95e8\u7528\u4e8e\u4f18\u5316\u5c0f\u89c4\u6a21\u6574\u6570\u96c6\u5408\u7684\u5185\u5b58\u5360\u7528\u548c\u67e5\u8be2\u6027\u80fd\u3002<\/p>\n<h4>\u4e00\u3001intset \u7684\u7ed3\u6784\u8bbe\u8ba1<\/h4>\n<h5>1. \u5185\u5b58\u5e03\u5c40<\/h5>\n<p>intset \u7531\u4e09\u90e8\u5206\u7ec4\u6210&#xff1a;<\/p>\n<p><span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">intset<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token class-name\">uint32_t<\/span> encoding<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u7f16\u7801\u65b9\u5f0f&#xff08;\u51b3\u5b9a\u6bcf\u4e2a\u6574\u6570\u5360\u7528\u7684\u5b57\u8282\u6570&#xff09;<\/span><br \/>\n    <span class=\"token class-name\">uint32_t<\/span> length<span class=\"token punctuation\">;<\/span>    <span class=\"token comment\">\/\/ \u5143\u7d20\u6570\u91cf<\/span><br \/>\n    <span class=\"token class-name\">int8_t<\/span> contents<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u67d4\u6027\u6570\u7ec4&#xff0c;\u5b9e\u9645\u5b58\u50a8\u6574\u6570<\/span><br \/>\n<span class=\"token punctuation\">}<\/span> intset<span class=\"token punctuation\">;<\/span><\/p>\n<ul>\n<li>encoding&#xff1a;\u7f16\u7801\u7c7b\u578b&#xff0c;\u53ef\u9009\u503c&#xff1a;\n<ul>\n<li>INTSET_ENC_INT16&#xff08;2 \u5b57\u8282&#xff0c;\u8303\u56f4 -32768~32767&#xff09;<\/li>\n<li>INTSET_ENC_INT32&#xff08;4 \u5b57\u8282&#xff0c;\u8303\u56f4 -2<sup>31~2<\/sup>31-1&#xff09;<\/li>\n<li>INTSET_ENC_INT64&#xff08;8 \u5b57\u8282&#xff0c;\u8303\u56f4 -2<sup>63~2<\/sup>63-1&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>contents&#xff1a;\u5143\u7d20\u6309\u5347\u5e8f\u6392\u5217&#xff0c;\u4fbf\u4e8e\u4e8c\u5206\u67e5\u627e\u3002<\/li>\n<\/ul>\n<h4>\u4e8c\u3001intset \u7684\u6838\u5fc3\u7279\u6027<\/h4>\n<h5>1. \u52a8\u6001\u7f16\u7801\u5347\u7ea7<\/h5>\n<ul>\n<li>\u89e6\u53d1\u6761\u4ef6&#xff1a;\u63d2\u5165\u7684\u6574\u6570\u8d85\u51fa\u5f53\u524d\u7f16\u7801\u8303\u56f4\u65f6&#xff0c;\u81ea\u52a8\u5347\u7ea7\u7f16\u7801&#xff08;\u5982\u4ece INT16 \u5347\u7ea7\u5230 INT32&#xff09;\u3002<\/li>\n<li>\u5347\u7ea7\u8fc7\u7a0b&#xff1a;\n<li>\u8ba1\u7b97\u65b0\u7f16\u7801\u6240\u9700\u7a7a\u95f4\u3002<\/li>\n<li>\u6309\u65b0\u7f16\u7801\u91cd\u65b0\u5206\u914d\u5185\u5b58&#xff0c;\u5e76\u5c06\u65e7\u6570\u636e\u8f6c\u6362\u4e3a\u65b0\u683c\u5f0f\u3002<\/li>\n<li>\u63d2\u5165\u65b0\u5143\u7d20\u5e76\u4fdd\u6301\u6709\u5e8f\u3002<\/li>\n<\/li>\n<li>\u793a\u4f8b&#xff1a; \u539f\u7f16\u7801\u4e3a INT16&#xff0c;\u63d2\u5165 40000&#xff08;\u8d85\u51fa INT16 \u8303\u56f4&#xff09; \u2192 \u5347\u7ea7\u4e3a INT32\u3002<\/li>\n<\/ul>\n<h5>2. \u6709\u5e8f\u5b58\u50a8<\/h5>\n<ul>\n<li>\u5143\u7d20\u6392\u5e8f&#xff1a;\u6240\u6709\u6574\u6570\u6309\u5347\u5e8f\u6392\u5217&#xff0c;\u652f\u6301 O(log n) \u65f6\u95f4\u590d\u6742\u5ea6\u7684\u4e8c\u5206\u67e5\u627e\u3002<\/li>\n<li>\u63d2\u5165\u590d\u6742\u5ea6&#xff1a;\n<ul>\n<li>\u67e5\u627e\u4f4d\u7f6e O(log n) &#043; \u79fb\u52a8\u5143\u7d20 O(n)&#xff08;\u9700\u4fdd\u6301\u6709\u5e8f\u6027&#xff09;\u3002<\/li>\n<li>\u7f16\u7801\u5347\u7ea7\u65f6\u8fd8\u9700 O(n) \u65f6\u95f4\u8f6c\u6362\u6570\u636e\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>3.\u6848\u4f8b\u5206\u6790<\/h5>\n<p>\u6570\u7ec4\u4e2d\u5148\u63d2\u51655,10,20<\/p>\n<p>\u4e3a\u4e86\u65b9\u4fbf\u67e5\u627e&#xff0c;Redis\u4f1a\u5c06intset\u4e2d\u6240\u6709\u7684\u6574\u6570\u6309\u7167\u5347\u5e8f\u4f9d\u6b21\u4fdd\u5b58\u5728contents\u6570\u7ec4\u4e2d&#xff0c;\u7ed3\u6784\u5982\u56fe&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250529013808-6837ba8022b82.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u73b0\u5728&#xff0c;\u6570\u7ec4\u4e2d\u6bcf\u4e2a\u6570\u5b57\u90fd\u5728int16_t\u7684\u8303\u56f4\u5185&#xff0c;\u56e0\u6b64\u91c7\u7528\u7684\u7f16\u7801\u65b9\u5f0f\u662fINTSET_ENC_INT16&#xff0c;\u6bcf\u90e8\u5206\u5360\u7528\u7684\u5b57\u8282\u5927\u5c0f\u4e3a&#xff1a; encoding&#xff1a;4\u5b57\u8282 length&#xff1a;4\u5b57\u8282 contents&#xff1a;2\u5b57\u8282 * 3 &#061; 6\u5b57\u8282 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250529013808-6837ba804cdb4.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u6211\u4eec\u5411\u8be5\u5176\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u6570\u5b57&#xff1a;50000&#xff0c;\u8fd9\u4e2a\u6570\u5b57\u8d85\u51fa\u4e86int16_t\u7684\u8303\u56f4&#xff0c;intset\u4f1a\u81ea\u52a8\u5347\u7ea7\u7f16\u7801\u65b9\u5f0f\u5230\u5408\u9002\u7684\u5927\u5c0f\u3002 \u4ee5\u5f53\u524d\u6848\u4f8b\u6765\u8bf4\u6d41\u7a0b\u5982\u4e0b&#xff1a;<\/p>\n<ul>\n<li>\u5347\u7ea7\u7f16\u7801\u4e3aINTSET_ENC_INT32, \u6bcf\u4e2a\u6574\u6570\u53604\u5b57\u8282&#xff0c;\u5e76\u6309\u7167\u65b0\u7684\u7f16\u7801\u65b9\u5f0f\u53ca\u5143\u7d20\u4e2a\u6570\u6269\u5bb9\u6570\u7ec4<\/li>\n<li>\u5012\u5e8f\u4f9d\u6b21\u5c06\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u62f7\u8d1d\u5230\u6269\u5bb9\u540e\u7684\u6b63\u786e\u4f4d\u7f6e&#xff08;\u9632\u6b62\u8986\u76d6\u540e\u7eed\u5143\u7d20&#xff09;<\/li>\n<li>\u5c06\u5f85\u6dfb\u52a0\u7684\u5143\u7d20\u653e\u5165\u6570\u7ec4\u672b\u5c3e<\/li>\n<li>\u6700\u540e&#xff0c;\u5c06inset\u7684encoding\u5c5e\u6027\u6539\u4e3aINTSET_ENC_INT32&#xff0c;\u5c06length\u5c5e\u6027\u6539\u4e3a4<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250529013808-6837ba8067e02.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h5>4.\u63d2\u5165\u5143\u7d20\u4ee5\u53ca\u6269\u5bb9\u6e90\u7801<\/h5>\n<p><span class=\"token comment\">\/* Upgrades the intset to a larger encoding and inserts the given integer. *\/<\/span><br \/>\n<span class=\"token keyword\">static<\/span> intset <span class=\"token operator\">*<\/span><span class=\"token function\">intsetUpgradeAndAdd<\/span><span class=\"token punctuation\">(<\/span>intset <span class=\"token operator\">*<\/span>is<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">int64_t<\/span> value<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token class-name\">uint8_t<\/span> curenc <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">intrev32ifbe<\/span><span class=\"token punctuation\">(<\/span>is<span class=\"token operator\">-&gt;<\/span>encoding<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token class-name\">uint8_t<\/span> newenc <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">_intsetValueEncoding<\/span><span class=\"token punctuation\">(<\/span>value<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> length <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">intrev32ifbe<\/span><span class=\"token punctuation\">(<\/span>is<span class=\"token operator\">-&gt;<\/span>length<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> prepend <span class=\"token operator\">&#061;<\/span> value <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">0<\/span> <span class=\"token operator\">?<\/span> <span class=\"token number\">1<\/span> <span class=\"token operator\">:<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/* First set new encoding and resize *\/<\/span><br \/>\n    is<span class=\"token operator\">-&gt;<\/span>encoding <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">intrev32ifbe<\/span><span class=\"token punctuation\">(<\/span>newenc<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    is <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">intsetResize<\/span><span class=\"token punctuation\">(<\/span>is<span class=\"token punctuation\">,<\/span><span class=\"token function\">intrev32ifbe<\/span><span class=\"token punctuation\">(<\/span>is<span class=\"token operator\">-&gt;<\/span>length<span class=\"token punctuation\">)<\/span><span class=\"token operator\">&#043;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/* Upgrade back-to-front so we don&#039;t overwrite values.<br \/>\n     * Note that the &#034;prepend&#034; variable is used to make sure we have an empty<br \/>\n     * space at either the beginning or the end of the intset. *\/<\/span><br \/>\n    <span class=\"token keyword\">while<\/span><span class=\"token punctuation\">(<\/span>length<span class=\"token operator\">&#8212;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token function\">_intsetSet<\/span><span class=\"token punctuation\">(<\/span>is<span class=\"token punctuation\">,<\/span>length<span class=\"token operator\">&#043;<\/span>prepend<span class=\"token punctuation\">,<\/span><span class=\"token function\">_intsetGetEncoded<\/span><span class=\"token punctuation\">(<\/span>is<span class=\"token punctuation\">,<\/span>length<span class=\"token punctuation\">,<\/span>curenc<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/* Set the value at the beginning or the end. *\/<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>prepend<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token function\">_intsetSet<\/span><span class=\"token punctuation\">(<\/span>is<span class=\"token punctuation\">,<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span>value<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">else<\/span><br \/>\n        <span class=\"token function\">_intsetSet<\/span><span class=\"token punctuation\">(<\/span>is<span class=\"token punctuation\">,<\/span><span class=\"token function\">intrev32ifbe<\/span><span class=\"token punctuation\">(<\/span>is<span class=\"token operator\">-&gt;<\/span>length<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span>value<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    is<span class=\"token operator\">-&gt;<\/span>length <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">intrev32ifbe<\/span><span class=\"token punctuation\">(<\/span><span class=\"token function\">intrev32ifbe<\/span><span class=\"token punctuation\">(<\/span>is<span class=\"token operator\">-&gt;<\/span>length<span class=\"token punctuation\">)<\/span><span class=\"token operator\">&#043;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> is<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h3>Dict<\/h3>\n<p>Redis \u4e2d\u7684 dict&#xff08;\u5b57\u5178&#xff09; \u662f\u6838\u5fc3\u6570\u636e\u7ed3\u6784\u4e4b\u4e00&#xff0c;\u7528\u4e8e\u5b9e\u73b0\u952e\u503c\u5b58\u50a8&#xff08;Key-Value&#xff09;\u3001\u54c8\u5e0c\u7c7b\u578b&#xff08;Hash&#xff09;\u53ca\u6570\u636e\u5e93\u952e\u7a7a\u95f4&#xff08;Keyspace&#xff09;\u7b49\u6838\u5fc3\u529f\u80fd\u3002<\/p>\n<h4>\u4e00\u3001dict \u7684\u7ed3\u6784\u8bbe\u8ba1<\/h4>\n<h5>1. \u6838\u5fc3\u7ed3\u6784\u4f53\u5b9a\u4e49<\/h5>\n<p>\u6211\u4eec\u77e5\u9053Redis\u662f\u4e00\u4e2a\u952e\u503c\u578b&#xff08;Key-Value Pair&#xff09;\u7684\u6570\u636e\u5e93&#xff0c;\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u952e\u5b9e\u73b0\u5feb\u901f\u7684\u589e\u5220\u6539\u67e5\u3002\u800c\u952e\u4e0e\u503c\u7684\u6620\u5c04\u5173\u7cfb\u6b63\u662f\u901a\u8fc7Dict\u6765\u5b9e\u73b0\u7684\u3002 Dict\u7531\u4e09\u90e8\u5206\u7ec4\u6210&#xff0c;\u5206\u522b\u662f&#xff1a;\u54c8\u5e0c\u8868&#xff08;DictHashTable&#xff09;\u3001\u54c8\u5e0c\u8282\u70b9&#xff08;DictEntry&#xff09;\u548c\u5b57\u5178&#xff08;Dict&#xff09;<\/p>\n<p><span class=\"token comment\">\/\/ \u54c8\u5e0c\u8868\u7ed3\u6784<\/span><br \/>\n<span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">dictht<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    dictEntry <span class=\"token operator\">*<\/span><span class=\"token operator\">*<\/span>table<span class=\"token punctuation\">;<\/span>      <span class=\"token comment\">\/\/ \u54c8\u5e0c\u6876\u6570\u7ec4&#xff08;\u94fe\u5f0f\u5b58\u50a8&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">unsigned<\/span> <span class=\"token keyword\">long<\/span> size<span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ \u54c8\u5e0c\u8868\u5927\u5c0f&#xff08;\u6876\u6570\u91cf&#xff0c;2^n&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">unsigned<\/span> <span class=\"token keyword\">long<\/span> sizemask<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u54c8\u5e0c\u63a9\u7801&#xff08;size-1&#xff0c;\u7528\u4e8e\u8ba1\u7b97\u7d22\u5f15&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">unsigned<\/span> <span class=\"token keyword\">long<\/span> used<span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ \u5df2\u4f7f\u7528\u7684\u6876\u6570\u91cf&#xff08;\u542b\u94fe\u8868\u8282\u70b9&#xff09;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span> dictht<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u5b57\u5178\u7ed3\u6784<\/span><br \/>\n<span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">dict<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    dictType <span class=\"token operator\">*<\/span>type<span class=\"token punctuation\">;<\/span>         <span class=\"token comment\">\/\/ \u7c7b\u578b\u7279\u5b9a\u51fd\u6570&#xff08;\u5982\u54c8\u5e0c\u51fd\u6570\u3001\u952e\u6bd4\u8f83\u51fd\u6570&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token operator\">*<\/span>privdata<span class=\"token punctuation\">;<\/span>         <span class=\"token comment\">\/\/ \u79c1\u6709\u6570\u636e&#xff08;\u7528\u4e8e\u6269\u5c55&#xff09;<\/span><br \/>\n    dictht ht<span class=\"token punctuation\">[<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span>           <span class=\"token comment\">\/\/ \u4e24\u4e2a\u54c8\u5e0c\u8868&#xff08;\u7528\u4e8e\u6e10\u8fdb\u5f0f rehash&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">long<\/span> rehashidx<span class=\"token punctuation\">;<\/span>         <span class=\"token comment\">\/\/ rehash \u8fdb\u5ea6&#xff08;-1 \u8868\u793a\u672a\u8fdb\u884c&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> iterators<span class=\"token punctuation\">;<\/span>          <span class=\"token comment\">\/\/ \u5f53\u524d\u8fd0\u884c\u7684\u8fed\u4ee3\u5668\u6570\u91cf<\/span><br \/>\n<span class=\"token punctuation\">}<\/span> dict<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u54c8\u5e0c\u8868\u8282\u70b9&#xff08;\u94fe\u8868\u7ed3\u6784&#xff09;<\/span><br \/>\n<span class=\"token keyword\">typedef<\/span> <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">dictEntry<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token operator\">*<\/span>key<span class=\"token punctuation\">;<\/span>              <span class=\"token comment\">\/\/ \u952e<\/span><br \/>\n    <span class=\"token keyword\">union<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">void<\/span> <span class=\"token operator\">*<\/span>val<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">uint64_t<\/span> u64<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">int64_t<\/span> s64<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">double<\/span> d<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span> v<span class=\"token punctuation\">;<\/span>                    <span class=\"token comment\">\/\/ \u503c&#xff08;\u652f\u6301\u591a\u79cd\u7c7b\u578b&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">dictEntry<\/span> <span class=\"token operator\">*<\/span>next<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u6307\u5411\u4e0b\u4e00\u4e2a\u8282\u70b9&#xff08;\u89e3\u51b3\u54c8\u5e0c\u51b2\u7a81&#xff09;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span> dictEntry<span class=\"token punctuation\">;<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250529013808-6837ba808027c.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>\u4e8c\u3001dict \u7684\u6838\u5fc3\u673a\u5236<\/h4>\n<h5>1. \u54c8\u5e0c\u51fd\u6570\u4e0e\u51b2\u7a81\u89e3\u51b3<\/h5>\n<ul>\n<li>\u54c8\u5e0c\u51fd\u6570&#xff1a;Redis \u9ed8\u8ba4\u4f7f\u7528 MurmurHash2 \u7b97\u6cd5&#xff08;\u975e\u52a0\u5bc6\u578b&#xff0c;\u9ad8\u6027\u80fd&#xff0c;\u5206\u5e03\u5747\u5300&#xff09;\u3002<\/li>\n<li>\u51b2\u7a81\u89e3\u51b3&#xff1a;\u91c7\u7528 \u94fe\u5730\u5740\u6cd5&#xff08;Separate Chaining&#xff09;&#xff0c;\u540c\u4e00\u6876\u5185\u7684\u8282\u70b9\u4ee5\u94fe\u8868\u8fde\u63a5\u3002<\/li>\n<\/ul>\n<h5>2.\u6269\u5bb9<\/h5>\n<h6>\u89e6\u53d1\u6761\u4ef6<\/h6>\n<ul>\n<li>\u8d1f\u8f7d\u56e0\u5b50&#xff08;Load Factor&#xff09;&#xff1a;\n<ul>\n<li>\u5e38\u89c4\u6269\u5bb9&#xff1a;load_factor &#061; used \/ size \u2265 1&#xff0c;\u4e14\u5f53\u524d\u672a\u5728\u540e\u53f0\u6267\u884c BGSAVE \u6216 BGREWRITEAOF\u3002<\/li>\n<li>\u5f3a\u5236\u6269\u5bb9&#xff1a;load_factor \u2265 5&#xff08;\u65e0\u8bba\u662f\u5426\u5728\u6267\u884c\u6301\u4e45\u5316\u64cd\u4f5c&#xff0c;\u907f\u514d\u54c8\u5e0c\u51b2\u7a81\u4e25\u91cd\u5bfc\u81f4\u6027\u80fd\u9aa4\u964d&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u6269\u5bb9\u6d41\u7a0b<\/p>\n<li>\n<p>\u8ba1\u7b97\u65b0\u8868\u5927\u5c0f&#xff1a;<\/p>\n<ul>\n<li>\u65b0\u54c8\u5e0c\u8868\u7684\u5927\u5c0f\u4e3a \u7b2c\u4e00\u4e2a \u2265 used \\\\* 2 \u7684 2^n&#xff08;\u5982 used&#061;3 \u2192 size&#061;8&#xff09;\u3002<\/li>\n<li>\u82e5\u5f53\u524d\u6b63\u5728\u6267\u884c BGSAVE \u6216 BGREWRITEAOF&#xff0c;Redis \u4f1a \u5ef6\u8fdf\u6269\u5bb9&#xff08;\u907f\u514d\u8d44\u6e90\u8fc7\u5ea6\u6d88\u8017&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u521d\u59cb\u5316\u65b0\u54c8\u5e0c\u8868&#xff08;ht[1]&#xff09;&#xff1a;<\/p>\n<p> <span class=\"token comment\">\/\/ \u5206\u914d\u65b0\u54c8\u5e0c\u8868\u5185\u5b58<\/span><br \/>\ndictht <span class=\"token operator\">*<\/span>new_ht <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>d<span class=\"token operator\">-&gt;<\/span>ht<span class=\"token punctuation\">[<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\nnew_ht<span class=\"token operator\">-&gt;<\/span>size <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">next_power<\/span><span class=\"token punctuation\">(<\/span>used <span class=\"token operator\">*<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nnew_ht<span class=\"token operator\">-&gt;<\/span>table <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">zcalloc<\/span><span class=\"token punctuation\">(<\/span>new_ht<span class=\"token operator\">-&gt;<\/span>size <span class=\"token operator\">*<\/span> <span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>dictEntry<span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nnew_ht<span class=\"token operator\">-&gt;<\/span>sizemask <span class=\"token operator\">&#061;<\/span> new_ht<span class=\"token operator\">-&gt;<\/span>size <span class=\"token operator\">&#8211;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span>\n <\/li>\n<li>\n<p>\u542f\u52a8\u6e10\u8fdb\u5f0f Rehash&#xff1a;<\/p>\n<ul>\n<li>\u8bbe\u7f6e rehashidx &#061; 0&#xff0c;\u8868\u793a\u5f00\u59cb\u4ece\u65e7\u8868 ht[0] \u7684\u7b2c 0 \u53f7\u6876\u8fc1\u79fb\u6570\u636e\u5230 ht[1]\u3002<\/li>\n<li>\u540e\u7eed\u6bcf\u6b21\u5bf9\u5b57\u5178\u7684\u589e\u5220\u6539\u67e5\u64cd\u4f5c&#xff0c;\u5747\u8fc1\u79fb\u4e00\u4e2a\u6876\u7684\u6570\u636e&#xff0c;\u76f4\u5230\u5b8c\u6210\u6240\u6709\u8fc1\u79fb\u3002<\/li>\n<\/ul>\n<\/li>\n<p>\u6269\u5bb9\u8bbe\u8ba1\u601d\u60f3<\/p>\n<ul>\n<li>2^n \u5927\u5c0f&#xff1a;\u901a\u8fc7\u4f4d\u8fd0\u7b97&#xff08;hash &amp; sizemask&#xff09;\u5feb\u901f\u8ba1\u7b97\u7d22\u5f15\u3002<\/li>\n<li>\u6e10\u8fdb\u5f0f\u8fc1\u79fb&#xff1a;\u907f\u514d\u4e00\u6b21\u6027\u8fc1\u79fb\u5927\u91cf\u6570\u636e\u5bfc\u81f4\u670d\u52a1\u963b\u585e\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>\u4e09\u3001\u7f29\u5bb9<\/h4>\n<h5>1. \u89e6\u53d1\u6761\u4ef6<\/h5>\n<ul>\n<li>\u8d1f\u8f7d\u56e0\u5b50&#xff08;Load Factor&#xff09;&#xff1a;load_factor &#061; used \/ size &lt; 0.1&#xff08;\u9ed8\u8ba4\u9608\u503c&#xff09;\u3002<\/li>\n<\/ul>\n<h5>2. \u7f29\u5bb9\u6d41\u7a0b<\/h5>\n<li>\n<p>\u8ba1\u7b97\u65b0\u8868\u5927\u5c0f&#xff1a;<\/p>\n<ul>\n<li>\u65b0\u54c8\u5e0c\u8868\u7684\u5927\u5c0f\u4e3a \u7b2c\u4e00\u4e2a \u2265 used \u7684 2^n&#xff08;\u5982 used&#061;3 \u2192 size&#061;4&#xff09;\u3002<\/li>\n<li>\u82e5 used&#061;0&#xff0c;\u5219\u76f4\u63a5\u91ca\u653e\u65e7\u8868&#xff0c;\u91cd\u7f6e\u4e3a\u521d\u59cb\u72b6\u6001\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u521d\u59cb\u5316\u65b0\u54c8\u5e0c\u8868&#xff08;ht[1]&#xff09;&#xff1a;<\/p>\n<p> dictht <span class=\"token operator\">*<\/span>new_ht <span class=\"token operator\">&#061;<\/span> <span class=\"token operator\">&amp;<\/span>d<span class=\"token operator\">-&gt;<\/span>ht<span class=\"token punctuation\">[<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\nnew_ht<span class=\"token operator\">-&gt;<\/span>size <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">next_power<\/span><span class=\"token punctuation\">(<\/span>used<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nnew_ht<span class=\"token operator\">-&gt;<\/span>table <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">zcalloc<\/span><span class=\"token punctuation\">(<\/span>new_ht<span class=\"token operator\">-&gt;<\/span>size <span class=\"token operator\">*<\/span> <span class=\"token keyword\">sizeof<\/span><span class=\"token punctuation\">(<\/span>dictEntry<span class=\"token operator\">*<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\nnew_ht<span class=\"token operator\">-&gt;<\/span>sizemask <span class=\"token operator\">&#061;<\/span> new_ht<span class=\"token operator\">-&gt;<\/span>size <span class=\"token operator\">&#8211;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span>\n <\/li>\n<li>\n<p>\u542f\u52a8\u6e10\u8fdb\u5f0f Rehash&#xff1a;<\/p>\n<ul>\n<li>\u4e0e\u6269\u5bb9\u76f8\u540c&#xff0c;\u9010\u6b65\u8fc1\u79fb\u6570\u636e\u5230\u65b0\u8868 ht[1]\u3002<\/li>\n<li>\u8fc1\u79fb\u5b8c\u6210\u540e&#xff0c;\u91ca\u653e\u65e7\u8868 ht[0]&#xff0c;\u5c06 ht[1] \u8bbe\u4e3a ht[0]\u3002<\/li>\n<\/ul>\n<\/li>\n<h5>3. \u7f29\u5bb9\u8bbe\u8ba1\u601d\u60f3<\/h5>\n<ul>\n<li>\u8282\u7701\u5185\u5b58&#xff1a;\u907f\u514d\u56e0\u6570\u636e\u5220\u9664\u540e\u54c8\u5e0c\u8868\u8fc7\u5927\u5bfc\u81f4\u5185\u5b58\u6d6a\u8d39\u3002<\/li>\n<li>\u5ef6\u8fdf\u7f29\u5bb9&#xff1a;\u9632\u6b62\u9891\u7e41\u7f29\u5bb9\u89e6\u53d1\u6027\u80fd\u6296\u52a8\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>\u56db\u3001\u6e10\u8fdb\u5f0f Rehash \u7684\u901a\u7528\u6d41\u7a0b<\/h4>\n<p>\u65e0\u8bba\u662f\u6269\u5bb9\u8fd8\u662f\u7f29\u5bb9&#xff0c;\u5fc5\u5b9a\u4f1a\u521b\u5efa\u65b0\u7684\u54c8\u5e0c\u8868&#xff0c;\u5bfc\u81f4\u54c8\u5e0c\u8868\u7684size\u548csizemask\u53d8\u5316&#xff0c;\u800ckey\u7684\u67e5\u8be2\u4e0esizemask\u6709\u5173\u3002\u540c\u65f6\u4e3a\u4e86\u9632\u6b62\u4e00\u6b21\u8f6c\u79fb\u5bfc\u81f4\u7684\u6027\u80fd\u6296\u52a8&#xff0c;\u91c7\u7528\u6e10\u8fdb\u5f0f Rehash \u5b8c\u6210\u6570\u636e\u8fc1\u79fb&#xff1a;<\/p>\n<li>\n<p>\u6bcf\u6b21\u64cd\u4f5c\u89e6\u53d1\u8fc1\u79fb&#xff1a;<\/p>\n<ul>\n<li>\u5bf9\u5b57\u5178\u7684 \u589e\u3001\u5220\u3001\u6539\u3001\u67e5 \u64cd\u4f5c\u5747\u53ef\u80fd\u89e6\u53d1\u8fc1\u79fb\u4e00\u4e2a\u6876\u7684\u6570\u636e\u3002<\/li>\n<li>\u8fc1\u79fb\u7684\u6876\u53f7\u4e3a rehashidx&#xff0c;\u5b8c\u6210\u540e rehashidx&#043;&#043;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u8fc1\u79fb\u5355\u4e2a\u6876\u7684\u6b65\u9aa4&#xff1a; a. \u904d\u5386\u65e7\u6876\u94fe\u8868&#xff1a;\u5904\u7406 ht[0].table[rehashidx] \u7684\u6240\u6709\u8282\u70b9\u3002 b. \u91cd\u65b0\u54c8\u5e0c\u8ba1\u7b97\u7d22\u5f15&#xff1a;\u5bf9\u65b0\u8868 ht[1] \u8ba1\u7b97\u6bcf\u4e2a\u8282\u70b9\u7684\u54c8\u5e0c\u503c\u548c\u7d22\u5f15\u3002<\/p>\n<p> <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span>entry <span class=\"token operator\">&#061;<\/span> old_table<span class=\"token punctuation\">[<\/span>rehashidx<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span> entry <span class=\"token operator\">!&#061;<\/span> <span class=\"token constant\">NULL<\/span><span class=\"token punctuation\">;<\/span> entry <span class=\"token operator\">&#061;<\/span> next_entry<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    next_entry <span class=\"token operator\">&#061;<\/span> entry<span class=\"token operator\">-&gt;<\/span>next<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u8ba1\u7b97\u65b0\u7d22\u5f15<\/span><br \/>\n    <span class=\"token class-name\">uint64_t<\/span> hash <span class=\"token operator\">&#061;<\/span> dict<span class=\"token operator\">-&gt;<\/span>type<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">hashFunction<\/span><span class=\"token punctuation\">(<\/span>entry<span class=\"token operator\">-&gt;<\/span>key<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token class-name\">uint64_t<\/span> new_index <span class=\"token operator\">&#061;<\/span> hash <span class=\"token operator\">&amp;<\/span> new_sizemask<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u63d2\u5165\u65b0\u8868<\/span><br \/>\n    entry<span class=\"token operator\">-&gt;<\/span>next <span class=\"token operator\">&#061;<\/span> new_table<span class=\"token punctuation\">[<\/span>new_index<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    new_table<span class=\"token punctuation\">[<\/span>new_index<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> entry<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>c. \u6e05\u7a7a\u65e7\u6876&#xff1a;\u5c06 ht[0].table[rehashidx] \u8bbe\u4e3a NULL\u3002 d. \u66f4\u65b0\u8ba1\u6570\u5668&#xff1a;\u9012\u51cf ht[0].used&#xff0c;\u9012\u589e ht[1].used\u3002<\/p>\n<\/li>\n<li>\n<p>\u68c0\u67e5\u8fc1\u79fb\u5b8c\u6210&#xff1a;<\/p>\n<ul>\n<li>\u5f53 rehashidx &gt;&#061; ht[0].size \u65f6&#xff0c;\u6240\u6709\u6876\u8fc1\u79fb\u5b8c\u6210\u3002<\/li>\n<li>\u91ca\u653e\u65e7\u8868&#xff1a;\u9500\u6bc1 ht[0].table&#xff0c;\u5c06 ht[1] \u8bbe\u4e3a ht[0]&#xff0c;\u91cd\u7f6e ht[1] \u4e3a\u7a7a\u3002<\/li>\n<li>\u7ed3\u675f Rehash&#xff1a;\u8bbe\u7f6e rehashidx &#061; -1\u3002<\/li>\n<\/ul>\n<\/li>\n<h4>\u4e09\u3001\u6dfb\u52a0\u952e\u503c\u5bf9\u7684\u6838\u5fc3\u6d41\u7a0b<\/h4>\n<h5>1. \u68c0\u67e5 Rehash \u72b6\u6001<\/h5>\n<ul>\n<li>\u5224\u65ad\u662f\u5426\u5904\u4e8e Rehash&#xff1a;\n<ul>\n<li>\u82e5\u5b57\u5178\u7684 rehashidx !&#061; -1&#xff0c;\u8868\u793a\u6b63\u5728\u8fdb\u884c \u6e10\u8fdb\u5f0f Rehash&#xff08;\u6570\u636e\u4ece\u65e7\u8868 ht[0] \u8fc1\u79fb\u5230\u65b0\u8868 ht[1]&#xff09;\u3002<\/li>\n<li>\u76f4\u63a5\u64cd\u4f5c\u65b0\u8868&#xff1a;\u6240\u6709\u65b0\u63d2\u5165\u7684\u952e\u503c\u5bf9\u4f1a\u5199\u5165 ht[1]&#xff0c;\u907f\u514d\u65e7\u8868 ht[0] \u7ee7\u7eed\u79ef\u7d2f\u6570\u636e\u3002<\/li>\n<li>\u89e6\u53d1\u8fc1\u79fb&#xff1a;\u6bcf\u6b21\u63d2\u5165\u64cd\u4f5c\u540e&#xff0c;\u987a\u5e26\u8fc1\u79fb ht[0] \u4e2d\u7684\u4e00\u4e2a\u6876&#xff08;Bucket&#xff09;\u5230 ht[1]&#xff0c;\u9010\u6b65\u5b8c\u6210\u6570\u636e\u8fc1\u79fb\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>2. \u8ba1\u7b97\u54c8\u5e0c\u503c\u4e0e\u7d22\u5f15<\/h5>\n<ul>\n<li>\n<p>\u54c8\u5e0c\u51fd\u6570&#xff1a;\u4f7f\u7528\u9884\u8bbe\u7684\u54c8\u5e0c\u7b97\u6cd5&#xff08;\u5982 MurmurHash2&#xff09;\u8ba1\u7b97\u952e\u7684\u54c8\u5e0c\u503c\u3002<\/p>\n<p> hash <span class=\"token operator\">&#061;<\/span> dict<span class=\"token operator\">-&gt;<\/span>type<span class=\"token operator\">-&gt;<\/span><span class=\"token function\">hashFunction<\/span><span class=\"token punctuation\">(<\/span>key<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u4f8b\u5982&#xff0c;MurmurHash2<\/span>\n <\/li>\n<li>\n<p>\u786e\u5b9a\u6876\u7d22\u5f15&#xff1a;\u901a\u8fc7\u54c8\u5e0c\u503c\u4e0e\u5f53\u524d\u54c8\u5e0c\u8868\u7684\u5927\u5c0f\u63a9\u7801&#xff08;sizemask &#061; size &#8211; 1&#xff09;\u8ba1\u7b97\u7d22\u5f15\u3002<\/p>\n<p> index <span class=\"token operator\">&#061;<\/span> hash <span class=\"token operator\">&amp;<\/span> dict<span class=\"token operator\">-&gt;<\/span>ht<span class=\"token punctuation\">[<\/span>table<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span>sizemask<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ table&#061;0 \u6216 1&#xff08;\u53d6\u51b3\u4e8e\u662f\u5426\u5728 Rehash&#xff09;<\/span>\n <\/li>\n<\/ul>\n<h5>3. \u5904\u7406\u952e\u7684\u5b58\u5728\u6027<\/h5>\n<ul>\n<li>\n<p>\u904d\u5386\u94fe\u8868&#xff1a;\u5728\u76ee\u6807\u6876\u7684\u94fe\u8868\u4e2d\u987a\u5e8f\u67e5\u627e\u952e\u662f\u5426\u5b58\u5728\u3002<\/p>\n<ul>\n<li>\n<p>\u952e\u5df2\u5b58\u5728&#xff1a;<\/p>\n<ul>\n<li>\u66ff\u6362\u65e7\u503c&#xff0c;\u91ca\u653e\u65e7\u503c\u5185\u5b58&#xff08;\u82e5\u914d\u7f6e\u4e86\u503c\u91ca\u653e\u51fd\u6570&#xff09;\u3002<\/li>\n<li>\u8fd4\u56de DICT_OK \u8868\u793a\u66f4\u65b0\u6210\u529f\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u952e\u4e0d\u5b58\u5728&#xff1a;<\/p>\n<ul>\n<li>\u521b\u5efa\u65b0\u8282\u70b9 dictEntry&#xff0c;\u5c06\u952e\u503c\u5bf9\u5b58\u5165\u3002<\/li>\n<li>\u5934\u63d2\u6cd5\u63d2\u5165\u94fe\u8868&#xff1a;\u5c06\u65b0\u8282\u70b9\u63d2\u5165\u94fe\u8868\u5934\u90e8&#xff08;\u65f6\u95f4\u590d\u6742\u5ea6 O(1)&#xff09;\u3002<\/li>\n<\/ul>\n<p> entry<span class=\"token operator\">-&gt;<\/span>next <span class=\"token operator\">&#061;<\/span> ht<span class=\"token operator\">-&gt;<\/span>table<span class=\"token punctuation\">[<\/span>index<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\nht<span class=\"token operator\">-&gt;<\/span>table<span class=\"token punctuation\">[<\/span>index<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> entry<span class=\"token punctuation\">;<\/span>\n <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>4. \u66f4\u65b0\u8ba1\u6570\u5668\u4e0e\u89e6\u53d1\u6269\u5bb9<\/h5>\n<ul>\n<li>\n<p>\u66f4\u65b0\u8ba1\u6570\u5668&#xff1a;\u9012\u589e\u54c8\u5e0c\u8868\u7684 used \u8ba1\u6570\u5668&#xff0c;\u8868\u793a\u5df2\u7528\u6876\u6570\u91cf\u589e\u52a0\u3002<\/p>\n<p> ht<span class=\"token operator\">-&gt;<\/span>used<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">;<\/span>\n <\/li>\n<li>\n<p>\u68c0\u67e5\u6269\u5bb9\u6761\u4ef6&#xff1a;<\/p>\n<ul>\n<li>\u8d1f\u8f7d\u56e0\u5b50&#xff1a;\u8ba1\u7b97 load_factor &#061; used \/ size\u3002<\/li>\n<li>\u89e6\u53d1\u6269\u5bb9&#xff1a;\n<ul>\n<li>\u5e38\u89c4\u6269\u5bb9&#xff1a;\u82e5 load_factor \u2265 1 \u4e14\u5141\u8bb8\u6269\u5bb9\u3002<\/li>\n<li>\u5f3a\u5236\u6269\u5bb9&#xff1a;\u82e5 load_factor \u2265 5&#xff08;\u907f\u514d\u54c8\u5e0c\u51b2\u7a81\u4e25\u91cd\u5bfc\u81f4\u6027\u80fd\u9aa4\u964d&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u6269\u5bb9\u64cd\u4f5c&#xff1a;\n<li>\u521b\u5efa\u65b0\u54c8\u5e0c\u8868 ht[1]&#xff0c;\u5927\u5c0f\u4e3a\u7b2c\u4e00\u4e2a \u2265 used * 2 \u7684 2 \u7684\u5e42\u6b21&#xff08;\u5982 used&#061;4 \u2192 size&#061;8&#xff09;\u3002<\/li>\n<li>\u8bbe\u7f6e rehashidx&#061;0&#xff0c;\u542f\u52a8\u6e10\u8fdb\u5f0f Rehash\u3002<\/li>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>5. \u8fd4\u56de\u7ed3\u679c<\/h5>\n<ul>\n<li>\u6210\u529f&#xff1a;\u8fd4\u56de DICT_OK\u3002<\/li>\n<li>\u5931\u8d25&#xff1a;\u82e5\u5185\u5b58\u5206\u914d\u5931\u8d25&#xff08;\u5982\u65e0\u6cd5\u521b\u5efa\u65b0\u8282\u70b9&#xff09;&#xff0c;\u8fd4\u56de DICT_ERR\u3002<\/li>\n<\/ul>\n<p>graph TD<br \/>\n    subgraph \u6dfb\u52a0\u952e\u503c\u5bf9\u6838\u5fc3\u6d41\u7a0b<br \/>\n    start([\u5f00\u59cb]) &#8211;&gt; check_rehash{\u68c0\u67e5Rehash\u72b6\u6001}<\/p>\n<p>    check_rehash &#8211;&gt; |rehashidx !&#061; -1| new_table[\u64cd\u4f5c\u65b0\u8868ht&lt;x-preset class&#061;&#034;no-tts reference-tag disable-to-doc&#034; data-index&#061;&#034;1&#034;&gt;1&lt;\/x-preset&gt;]<br \/>\n    new_table &#8211;&gt; migrate[\u8fc1\u79fbht&lt;x-preset class&#061;&#034;no-tts reference-tag disable-to-doc&#034; data-index&#061;&#034;0&#034;&gt;0&lt;\/x-preset&gt;\u7684\u4e00\u4e2a\u6876\u5230ht&lt;x-preset class&#061;&#034;no-tts reference-tag disable-to-doc&#034; data-index&#061;&#034;1&#034;&gt;1&lt;\/x-preset&gt;]<\/p>\n<p>    check_rehash &#8211;&gt; |rehashidx &#061; -1| compute_hash[\u8ba1\u7b97\u54c8\u5e0c\u503c]<br \/>\n    migrate &#8211;&gt; compute_hash<\/p>\n<p>    compute_hash &#8211;&gt; get_index[\u8ba1\u7b97\u6876\u7d22\u5f15: hash &amp; sizemask]<\/p>\n<p>    get_index &#8211;&gt; key_check{\u952e\u662f\u5426\u5b58\u5728?}<\/p>\n<p>    key_check &#8211;&gt; |\u5b58\u5728| replace[\u66ff\u6362\u65e7\u503c\u5e76\u91ca\u653e\u5185\u5b58]<br \/>\n    replace &#8211;&gt; return_ok[\u8fd4\u56deDICT_OK]<\/p>\n<p>    key_check &#8211;&gt; |\u4e0d\u5b58\u5728| create_entry[\u521b\u5efa\u65b0dictEntry]<br \/>\n    create_entry &#8211;&gt; insert[\u5934\u63d2\u6cd5\u63d2\u5165\u94fe\u8868]<br \/>\n    insert &#8211;&gt; update_counter[\u66f4\u65b0used\u8ba1\u6570\u5668]<\/p>\n<p>    update_counter &#8211;&gt; check_expand{\u68c0\u67e5\u6269\u5bb9\u6761\u4ef6}<\/p>\n<p>    check_expand &#8211;&gt; |load_factor \u22651| normal_expand[\u5e38\u89c4\u6269\u5bb9]<br \/>\n    check_expand &#8211;&gt; |load_factor \u22655| force_expand[\u5f3a\u5236\u6269\u5bb9]<\/p>\n<p>    normal_expand &#8211;&gt; create_ht1[\u521b\u5efaht&lt;x-preset class&#061;&#034;no-tts reference-tag disable-to-doc&#034; data-index&#061;&#034;1&#034;&gt;1&lt;\/x-preset&gt;\\\\n\u5927\u5c0f\u4e3aused*2\u76842^n]<br \/>\n    force_expand &#8211;&gt; create_ht1<br \/>\n    create_ht1 &#8211;&gt; start_rehash[\u8bbe\u7f6erehashidx&#061;0]<\/p>\n<p>    start_rehash &#8211;&gt; return_ok<br \/>\n    return_ok &#8211;&gt; end_process([\u7ed3\u675f])<\/p>\n<p>    check_expand &#8211;&gt; |\u65e0\u9700\u6269\u5bb9| return_ok<br \/>\n    end_process<br \/>\n    end<\/p>\n<h3>Ziplist<\/h3>\n<h4>\u4e00\u3001ziplist\u7684\u7ed3\u6784\u8bbe\u8ba1<\/h4>\n<h5>1.\u6574\u4f53\u5e03\u5c40<\/h5>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250529013808-6837ba80b6c38.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>**zlbytes&#xff08;4\u5b57\u8282&#xff09;&#x1f617;*\u603b\u5b57\u8282\u6570&#xff0c;\u7528\u4e8e\u5feb\u901f\u83b7\u53d6\u5217\u8868\u5927\u5c0f\u3002<\/li>\n<li>**zltail&#xff08;4\u5b57\u8282&#xff09;&#x1f617;*\u5c3e\u8282\u70b9\u504f\u79fb\u91cf&#xff0c;\u7528\u4e8e\u5b9a\u4f4d\u5c3e\u8282\u70b9\u3002<\/li>\n<li>**zllen&#xff08;2\u5b57\u8282&#xff09;&#x1f617;*\u8282\u70b9\u957f\u5ea6&#xff08;\u6570\u91cf&#xff09;&#xff08;\u82e5\u8d85\u8fc765535&#xff0c;\u9700\u904d\u5386\u8ba1\u7b97&#xff09;\u3002<\/li>\n<li>**entry:**\u8282\u70b9\u5355\u5143&#xff0c;\u5b58\u50a8\u6570\u636e\u3002<\/li>\n<li>**zlend&#xff08;1\u5b57\u8282&#xff09;&#x1f617;*\u7ed3\u675f\u6807\u8bc6&#xff08;0xFF&#xff09;\u3002<\/li>\n<\/ul>\n<h5>2.Entry\u7ed3\u6784<\/h5>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250529013808-6837ba80c722d.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>**previous_entry_length&#xff08;1\u62165\u5b57\u8282&#xff09;&#x1f617;*\u524d\u4e00\u8282\u70b9\u5355\u5143\u5927\u5c0f\u3002\n<ul>\n<li>\u524d\u9a71\u957f\u5ea6\u2264 253:prelen\u5360\u4e00\u5b57\u8282\u3002<\/li>\n<li>\u524d\u9a71\u957f\u5ea6 &gt; 253&#xff1a;prevlen \u9996\u5b57\u8282\u56fa\u5b9a\u4e3a 0xFE&#xff0c;\u540e4\u5b57\u8282\u5b58\u50a8\u5b9e\u9645\u957f\u5ea6\u3002<\/li>\n<\/ul>\n<\/li>\n<li>**encoding&#xff08;1\u30012\u30015\u5b57\u8282&#xff09;&#x1f617;*\u7f16\u7801\u5c5e\u6027&#xff0c;\u7528\u4e8e\u6807\u8bc6content\u7684\u7c7b\u578b&#xff08;\u5b57\u7b26\u4e32\u6216\u6574\u6570&#xff09;\u548c\u957f\u5ea6\u3002<\/li>\n<li>**content:**\u4fdd\u5b58\u6570\u636e&#xff08;\u5b57\u7b26\u4e32\u6216\u6574\u6570&#xff09;\u3002<\/li>\n<\/ul>\n<h5>3.Encoding\u7f16\u7801<\/h5>\n<p>\u5206\u4e3a\u5b57\u7b26\u4e32\u548c\u6574\u6570\u4e24\u79cd<\/p>\n<h6>\u5b57\u7b26\u4e32\u7c7b\u578b\u7f16\u7801<\/h6>\n<p>\u5b57\u7b26\u4e32\u7c7b\u578b\u4ee500&#xff08;1\u5b57\u8282&#xff09;\u300101&#xff08;2\u5b57\u8282&#xff09;\u300110&#xff08;5\u5b57\u8282&#xff09;\u5f00\u5934&#xff0c;\u9664\u524d\u4e24\u4f4d\u5916\u5176\u4f59\u4f4d\u5747\u8bb0\u5f55\u5b57\u7b26\u4e32\u5927\u5c0f\u3002<\/p>\n<table>\n<tr>\u7f16\u7801\u7f16\u7801\u957f\u5ea6\u5b57\u7b26\u4e32\u5927\u5c0f<\/tr>\n<tbody>\n<tr>\n<td>|00pppppp|<\/td>\n<td>1 bytes<\/td>\n<td>&lt;&#061; 63 bytes<\/td>\n<\/tr>\n<tr>\n<td>|01pppppp|qqqqqqqq|<\/td>\n<td>2 bytes<\/td>\n<td>&lt;&#061; 16383 bytes<\/td>\n<\/tr>\n<tr>\n<td>|10000000|qqqqqqqq|rrrrrrrr|ssssssss|tttttttt|<\/td>\n<td>5 bytes<\/td>\n<td>&lt;&#061; 4294967295 bytes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h6>\u6574\u6570\u7c7b\u578b\u7f16\u7801<\/h6>\n<p>\u6574\u6570\u7c7b\u578b\u4ee511\u5f00\u5934&#xff0c;\u56fa\u5b9a\u4e3a1\u5b57\u8282&#xff0c;\u5176\u4f59\u516d\u4f4d\u6807\u8bc6\u4e94\u79cd\u6574\u6570\u7c7b\u578b\u5206\u522b\u5360\u636e\u4e8600|0000\u300101|0000\u300110|0000\u3002\u8fd9\u6837\u6211\u4eec\u5c31\u80fd\u752811|xxxx\u76f4\u63a5\u4fdd\u5b58\u6570\u636e\u5728\u540e\u56db\u4f4d&#xff0c;\u800c11|0000\u548c11|1110\u30010xff&#xff08;\u7ed3\u675f\u6807\u8bc6&#xff09;\u88ab\u5360\u636e\u6240\u4ee5\u5177\u4f53\u53ef\u5b58\u50a8\u503c\u670913\u4e2a\u3002<\/p>\n<table>\n<tr>\u7f16\u7801\u7f16\u7801\u957f\u5ea6\u6574\u6570\u7c7b\u578b<\/tr>\n<tbody>\n<tr>\n<td>11000000<\/td>\n<td>1<\/td>\n<td>int16_t&#xff08;2 bytes&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>11010000<\/td>\n<td>1<\/td>\n<td>int32_t&#xff08;4 bytes&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>11100000<\/td>\n<td>1<\/td>\n<td>int64_t&#xff08;8 bytes&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>11110000<\/td>\n<td>1<\/td>\n<td>24\u4f4d\u6709\u7b26\u6574\u6570(3 bytes)<\/td>\n<\/tr>\n<tr>\n<td>11111110<\/td>\n<td>1<\/td>\n<td>8\u4f4d\u6709\u7b26\u6574\u6570(1 bytes)<\/td>\n<\/tr>\n<tr>\n<td>1111xxxx<\/td>\n<td>1<\/td>\n<td>\u76f4\u63a5\u5728xxxx\u4f4d\u7f6e\u4fdd\u5b58\u6570\u503c&#xff0c;\u8303\u56f4\u4ece0001~1101&#xff0c;\u51cf1\u540e\u7ed3\u679c\u4e3a\u5b9e\u9645\u503c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u4e8c\u3001ziplist \u7684\u6838\u5fc3\u7279\u6027<\/h4>\n<h5>1. \u5185\u5b58\u7d27\u51d1<\/h5>\n<ul>\n<li>\u8fde\u7eed\u5b58\u50a8&#xff1a;\u6d88\u9664\u6307\u9488\u5f00\u9500&#xff0c;\u5185\u5b58\u5229\u7528\u7387\u9ad8\u3002<\/li>\n<li>\u53d8\u957f\u7f16\u7801&#xff1a;\u6839\u636e\u6570\u636e\u52a8\u6001\u8c03\u6574\u5b58\u50a8\u7a7a\u95f4&#xff08;\u5982\u5c0f\u6574\u6570\u75281\u5b57\u8282&#xff09;\u3002<\/li>\n<\/ul>\n<h5>2. \u53cc\u5411\u904d\u5386<\/h5>\n<ul>\n<li>\u524d\u9a71\u6307\u9488\u6a21\u62df&#xff1a;\u901a\u8fc7 prevlen \u5b57\u6bb5\u53cd\u5411\u8ba1\u7b97\u524d\u9a71 entry \u8d77\u59cb\u4f4d\u7f6e\u3002<\/li>\n<li>\u6b63\u5411\u904d\u5386&#xff1a;\u5229\u7528 encoding \u89e3\u6790\u5f53\u524d entry \u957f\u5ea6&#xff0c;\u8df3\u81f3\u4e0b\u4e00 entry\u3002<\/li>\n<\/ul>\n<h5>3. \u81ea\u52a8\u7f16\u7801\u8f6c\u6362<\/h5>\n<ul>\n<li>\u9608\u503c\u63a7\u5236&#xff1a;\u5f53\u5143\u7d20\u6570\u91cf\u6216\u5927\u5c0f\u8d85\u8fc7\u914d\u7f6e&#xff08;\u5982 hash-max-ziplist-entries&#xff09;&#xff0c;\u8f6c\u4e3a\u6807\u51c6\u7ed3\u6784&#xff08;\u5982\u54c8\u5e0c\u8868&#xff09;\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>\u4e09\u3001ziplist \u7684\u64cd\u4f5c\u673a\u5236<\/h4>\n<h5>1. \u63d2\u5165\u64cd\u4f5c<\/h5>\n<ul>\n<li>\u5b9a\u4f4d\u63d2\u5165\u70b9&#xff1a;\u904d\u5386\u627e\u5230\u4f4d\u7f6e&#xff0c;\u8ba1\u7b97\u6240\u9700\u7a7a\u95f4\u3002<\/li>\n<li>\u5185\u5b58\u91cd\u5206\u914d&#xff1a;\u6269\u5c55 ziplist \u5185\u5b58&#xff0c;\u79fb\u52a8\u540e\u7eed entry\u3002<\/li>\n<li>\u66f4\u65b0\u524d\u540e entry&#xff1a;\n<ul>\n<li>\u4fee\u6539\u540e\u7ee7 entry \u7684 prevlen\u3002<\/li>\n<li>\u53ef\u80fd\u89e6\u53d1 \u7ea7\u8054\u66f4\u65b0&#xff08;Cascade Update&#xff09;&#xff1a;\u82e5\u65b0 entry \u5bfc\u81f4\u540e\u7ee7 entry \u7684 prevlen \u6269\u5bb9&#xff08;1\u21925\u5b57\u8282&#xff09;&#xff0c;\u9700\u9012\u5f52\u5904\u7406\u540e\u7eed entry\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>2. \u5220\u9664\u64cd\u4f5c<\/h5>\n<ul>\n<li>\u5185\u5b58\u7f29\u5bb9&#xff1a;\u79fb\u9664 entry \u540e&#xff0c;\u524d\u79fb\u540e\u7eed\u6570\u636e\u3002<\/li>\n<li>\u7ea7\u8054\u66f4\u65b0\u98ce\u9669&#xff1a;\u7c7b\u4f3c\u63d2\u5165&#xff0c;\u53ef\u80fd\u89e6\u53d1\u540e\u7ee7 entry \u7684 prevlen \u8c03\u6574\u3002<\/li>\n<\/ul>\n<h5>3. \u67e5\u8be2\u64cd\u4f5c<\/h5>\n<ul>\n<li>\u987a\u5e8f\u904d\u5386&#xff1a;\u4ece\u5934\u6216\u5c3e&#xff08;\u5229\u7528 zltail&#xff09;\u5f00\u59cb&#xff0c;\u89e3\u6790\u6bcf\u4e2a entry \u7684 encoding \u548c prevlen\u3002<\/li>\n<\/ul>\n<hr \/>\n<h4>\u56db\u3001\u7ea7\u8054\u66f4\u65b0&#xff08;Cascade Update&#xff09;<\/h4>\n<h5>1. \u89e6\u53d1\u6761\u4ef6<\/h5>\n<p>\u63d2\u5165\u6216\u5220\u9664 entry \u5bfc\u81f4\u540e\u7ee7 entry \u7684 prevlen \u4ece1\u5b57\u8282\u6269\u5c55\u4e3a5\u5b57\u8282&#xff08;\u6216\u53cd\u5411\u6536\u7f29&#xff09;<\/p>\n<p>\u4f8b\u5982\u8fde\u7eed\u8282\u70b9\u5927\u5c0f\u4e3a250-253&#xff08;\u524d\u9a71\u8282\u70b9\u5927\u5c0f1\u5b57\u8282&#xff09;&#xff0c;\u6709\u4e00\u8282\u70b9\u6570\u636e\u53d8\u66f4\u8d85\u51fa253\u5b57\u8282&#xff0c;\u540e\u7eed\u8282\u70b9\u7684prelen\u53d8\u4e3a5\u5b57\u8282\u5b58\u50a8&#xff0c;\u53d8\u66f4\u540e\u8fd9\u4e2a\u8282\u70b9\u7684\u5927\u5c0f\u4e5f\u8d85\u8fc7\u4e86253\u5b57\u8282&#xff0c;\u5faa\u73af\u5f80\u590d\u3002<\/p>\n<h5>2. \u6027\u80fd\u5f71\u54cd<\/h5>\n<ul>\n<li>\u6700\u574f\u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;O(n\u00b2)&#xff08;\u5982\u6240\u6709 entry \u7684 prevlen \u5747\u9700\u8c03\u6574&#xff09;\u3002<\/li>\n<li>\u5b9e\u9645\u573a\u666f&#xff1a;\u6982\u7387\u6781\u4f4e&#xff0c;\u901a\u5e38\u5728\u5c0f\u89c4\u6a21 ziplist \u4e2d\u5f71\u54cd\u6709\u9650\u3002<\/li>\n<\/ul>\n<h3>QuickList<\/h3>\n<p>quicklist \u662f Redis \u7528\u4e8e\u5b9e\u73b0 \u5217\u8868&#xff08;List&#xff09; \u6570\u636e\u7c7b\u578b\u7684\u6838\u5fc3\u6570\u636e\u7ed3\u6784&#xff0c;\u7ed3\u5408\u4e86 ziplist&#xff08;\u538b\u7f29\u5217\u8868&#xff09;\u548c linkedlist&#xff08;\u53cc\u5411\u94fe\u8868&#xff09;\u7684\u4f18\u52bf&#xff0c;\u5728\u5185\u5b58\u6548\u7387\u4e0e\u64cd\u4f5c\u6027\u80fd\u4e4b\u95f4\u53d6\u5f97\u5e73\u8861\u3002<\/p>\n<h4>\u4e00\u3001qiucklist\u7684\u8bbe\u8ba1\u80cc\u666f<\/h4>\n<h5>1.\u65e9\u671f\u5217\u8868\u5b9e\u73b0\u7684\u4e0d\u8db3<\/h5>\n<ul>\n<li>ziplist\n<ul>\n<li>**\u4f18\u70b9&#xff1a;**\u5185\u5b58\u7d27\u51d1&#xff0c;\u4e0d\u9700\u8981\u6307\u9488\u5360\u636e\u989d\u5916\u5185\u5b58\u7a7a\u95f4\u3002<\/li>\n<li>**\u7f3a\u70b9&#xff1a;**\u63d2\u5165\u3001\u5220\u9664\u64cd\u4f5c\u9700\u91cd\u5206\u914d\u5185\u5b58&#xff0c;\u79fb\u52a8\u540e\u7eed\u8282\u70b9&#xff0c;\u5927\u89c4\u6a21\u6570\u636e\u4e0b\u6027\u80fd\u5dee\u3002<\/li>\n<\/ul>\n<\/li>\n<li>linedlist\n<ul>\n<li>\u4f18\u70b9&#xff1a;\u63d2\u5165\u3001\u5220\u9664\u9ad8\u6548\u3002<\/li>\n<li>\u7f3a\u70b9&#xff1a;\u5185\u5b58\u788e\u7247\u591a&#xff0c;\u6307\u9488\u5360\u636e\u989d\u5916\u7a7a\u95f4\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>2.qiucklist\u7684\u4f18\u52bf<\/h5>\n<p>\u200b \u4fdd\u7559ziplist\u7684\u5185\u5b58\u7d27\u51d1\u4f18\u52bf&#xff0c;\u540c\u65f6\u9650\u5236ziplist\u5927\u5c0f&#xff0c;\u5c06\u591a\u4e2aziplist\u901a\u8fc7\u53cc\u5411\u94fe\u8868\u8fde\u63a5&#xff0c;\u907f\u514d\u4e86\u5355\u4e2aziplist\u5728\u5927\u89c4\u6a21\u6570\u636e\u4e0b\u5185\u5b58\u91cd\u5206\u914d\u5e26\u6765\u7684\u6027\u80fd\u5dee\u7684\u5f0a\u7aef\u3002<\/p>\n<h4>\u4e8c\u3001quicklist\u7684\u7ed3\u6784<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250529013808-6837ba80d47da.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u4e3a\u4e86\u907f\u514dQuickList\u4e2d\u7684\u6bcf\u4e2aZipList\u4e2dentry\u8fc7\u591a&#xff0c;Redis\u63d0\u4f9b\u4e86\u4e00\u4e2a\u914d\u7f6e\u9879&#xff1a;list-max-ziplist-size\u6765\u9650\u5236\u3002 \u5982\u679c\u503c\u4e3a\u6b63&#xff0c;\u5219\u4ee3\u8868ZipList\u7684\u5141\u8bb8\u7684entry\u4e2a\u6570\u7684\u6700\u5927\u503c \u5982\u679c\u503c\u4e3a\u8d1f&#xff0c;\u5219\u4ee3\u8868ZipList\u7684\u6700\u5927\u5185\u5b58\u5927\u5c0f&#xff0c;\u52065\u79cd\u60c5\u51b5&#xff1a;<\/p>\n<ul>\n<li>-1&#xff1a;\u6bcf\u4e2aZipList\u7684\u5185\u5b58\u5360\u7528\u4e0d\u80fd\u8d85\u8fc74kb<\/li>\n<li>-2&#xff1a;\u6bcf\u4e2aZipList\u7684\u5185\u5b58\u5360\u7528\u4e0d\u80fd\u8d85\u8fc78kb<\/li>\n<li>-3&#xff1a;\u6bcf\u4e2aZipList\u7684\u5185\u5b58\u5360\u7528\u4e0d\u80fd\u8d85\u8fc716kb<\/li>\n<li>-4&#xff1a;\u6bcf\u4e2aZipList\u7684\u5185\u5b58\u5360\u7528\u4e0d\u80fd\u8d85\u8fc732kb<\/li>\n<li>-5&#xff1a;\u6bcf\u4e2aZipList\u7684\u5185\u5b58\u5360\u7528\u4e0d\u80fd\u8d85\u8fc764kb<\/li>\n<\/ul>\n<p>\u5176\u9ed8\u8ba4\u503c\u4e3a -2<\/p>\n<h4>\u4e09\u3001quicklist \u7684\u6838\u5fc3\u673a\u5236<\/h4>\n<h5>1. \u52a8\u6001\u8282\u70b9\u7ba1\u7406<\/h5>\n<ul>\n<li>\u8282\u70b9\u5206\u88c2&#xff1a;\u5f53\u63d2\u5165\u5143\u7d20\u5bfc\u81f4\u5355\u4e2a ziplist \u8d85\u8fc7 fill \u9608\u503c\u65f6&#xff0c;\u5206\u88c2\u4e3a\u4e24\u4e2a\u8282\u70b9\u3002<\/li>\n<li>\u8282\u70b9\u5408\u5e76&#xff1a;\u5f53\u5220\u9664\u5143\u7d20\u5bfc\u81f4\u76f8\u90bb\u8282\u70b9\u5bb9\u91cf\u8fc7\u5c0f\u65f6&#xff0c;\u5408\u5e76\u4ee5\u51cf\u5c11\u5185\u5b58\u788e\u7247\u3002<\/li>\n<\/ul>\n<h5>2. \u538b\u7f29\u4f18\u5316<\/h5>\n<ul>\n<li>LZF \u538b\u7f29\u7b97\u6cd5&#xff1a;\u5bf9\u4e2d\u95f4\u8282\u70b9\u8fdb\u884c\u538b\u7f29&#xff08;compress \u53c2\u6570\u63a7\u5236\u538b\u7f29\u6df1\u5ea6&#xff09;\u3002\n<ul>\n<li>\u538b\u7f29\u6df1\u5ea6\u4e3a 0&#xff1a;\u4e0d\u538b\u7f29\u3002<\/li>\n<li>\u538b\u7f29\u6df1\u5ea6\u4e3a 1&#xff1a;\u5934\u5c3e\u5404\u4fdd\u7559 1 \u4e2a\u8282\u70b9\u4e0d\u538b\u7f29&#xff0c;\u5176\u4f59\u538b\u7f29\u3002<\/li>\n<li>\u538b\u7f29\u6df1\u5ea6\u4e3a 2&#xff1a;\u5934\u5c3e\u5404\u4fdd\u7559 2 \u4e2a\u8282\u70b9\u4e0d\u538b\u7f29&#xff0c;\u5176\u4f59\u538b\u7f29\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>SkipList<\/h3>\n<h4>\u4e00\u3001\u8df3\u8868\u7684\u6838\u5fc3\u8bbe\u8ba1<\/h4>\n<h5>1. \u57fa\u672c\u6982\u5ff5<\/h5>\n<p>\u8df3\u8868\u901a\u8fc7 \u591a\u5c42\u94fe\u8868 \u5b9e\u73b0\u6709\u5e8f\u6570\u636e\u7684\u5feb\u901f\u8bbf\u95ee\u3002\u6bcf\u4e2a\u8282\u70b9\u5305\u542b\u591a\u4e2a \u5c42\u7ea7&#xff0c;\u6bcf\u5c42\u7ef4\u62a4\u4e00\u4e2a\u6307\u5411\u540e\u7eed\u8282\u70b9\u7684\u6307\u9488&#xff0c;\u9ad8\u5c42\u6307\u9488\u53ef\u8de8\u8d8a\u591a\u4e2a\u4f4e\u5c42\u8282\u70b9&#xff0c;\u4ece\u800c\u52a0\u901f\u67e5\u627e\u3002<\/p>\n<h5>2. \u8282\u70b9\u7ed3\u6784<\/h5>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250529013809-6837ba810a0b6.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h5>3. \u5c42\u6570\u751f\u6210\u89c4\u5219<\/h5>\n<ul>\n<li>\u5e42\u6b21\u5b9a\u5f8b&#xff1a;\u65b0\u8282\u70b9\u7684\u5c42\u6570\u968f\u673a\u751f\u6210&#xff0c;\u6982\u7387\u9010\u5c42\u51cf\u534a\u3002\n<ul>\n<li>\u7b2c 1 \u5c42\u6982\u7387&#xff1a;100%<\/li>\n<li>\u7b2c 2 \u5c42\u6982\u7387&#xff1a;50%<\/li>\n<li>\u7b2c 3 \u5c42\u6982\u7387&#xff1a;25%<\/li>\n<li>\u2026<\/li>\n<li>\u6700\u5927\u5c42\u6570&#xff1a;ZSKIPLIST_MAXLEVEL &#061; 32&#xff08;Redis \u9ed8\u8ba4\u9650\u5236&#xff09;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>\u4e8c\u3001\u8df3\u8868\u7684\u64cd\u4f5c\u673a\u5236<\/h4>\n<h5>1. \u67e5\u627e\u64cd\u4f5c<\/h5>\n<ul>\n<li>\u4ece\u6700\u9ad8\u5c42\u5f00\u59cb&#xff1a;\u9010\u5c42\u904d\u5386&#xff0c;\u82e5\u5f53\u524d\u5c42\u7684\u4e0b\u4e2a\u8282\u70b9\u5206\u503c\u5927\u4e8e\u76ee\u6807\u503c&#xff0c;\u5219\u4e0b\u964d\u4e00\u5c42\u7ee7\u7eed\u67e5\u627e\u3002<\/li>\n<li>\u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;\u5e73\u5747 O(log n)&#xff0c;\u6700\u574f O(n)\u3002<\/li>\n<\/ul>\n<h5>2. \u63d2\u5165\u64cd\u4f5c<\/h5>\n<li>\u786e\u5b9a\u63d2\u5165\u4f4d\u7f6e&#xff1a;\u67e5\u627e\u8fc7\u7a0b\u4e2d\u8bb0\u5f55\u6bcf\u5c42\u7684\u524d\u9a71\u8282\u70b9\u3002<\/li>\n<li>\u751f\u6210\u968f\u673a\u5c42\u6570&#xff1a;\u6839\u636e\u5e42\u6b21\u5b9a\u5f8b\u786e\u5b9a\u65b0\u8282\u70b9\u5c42\u6570\u3002<\/li>\n<li>\u8c03\u6574\u6307\u9488&#xff1a;\u5c06\u65b0\u8282\u70b9\u63d2\u5165\u5404\u5c42\u94fe\u8868&#xff0c;\u66f4\u65b0\u524d\u540e\u8282\u70b9\u7684\u6307\u9488\u548c\u8de8\u5ea6\u3002<\/li>\n<h5>3. \u5220\u9664\u64cd\u4f5c<\/h5>\n<li>\u5b9a\u4f4d\u8282\u70b9&#xff1a;\u67e5\u627e\u76ee\u6807\u8282\u70b9&#xff0c;\u5e76\u8bb0\u5f55\u5404\u5c42\u524d\u9a71\u8282\u70b9\u3002<\/li>\n<li>\u66f4\u65b0\u6307\u9488&#xff1a;\u5c06\u524d\u9a71\u8282\u70b9\u7684\u6307\u9488\u6307\u5411\u76ee\u6807\u8282\u70b9\u7684\u540e\u7ee7\u8282\u70b9\u3002<\/li>\n<li>\u91ca\u653e\u5185\u5b58&#xff1a;\u82e5\u8282\u70b9\u65e0\u5176\u4ed6\u5f15\u7528&#xff0c;\u91ca\u653e\u5185\u5b58\u3002<\/li>\n<h3>RedisObject<\/h3>\n<p>Redis \u7684 redisObject \u662f\u7ba1\u7406\u6240\u6709\u6570\u636e\u7c7b\u578b&#xff08;\u5982\u5b57\u7b26\u4e32\u3001\u5217\u8868\u3001\u54c8\u5e0c\u7b49&#xff09;\u7684\u6838\u5fc3\u7ed3\u6784&#xff0c;\u5b83\u901a\u8fc7\u7edf\u4e00\u7684\u63a5\u53e3\u62bd\u8c61&#xff0c;\u5b9e\u73b0\u4e86\u5185\u5b58\u4f18\u5316\u3001\u7f16\u7801\u8f6c\u6362\u7b49\u64cd\u4f5c\u3002<\/p>\n<h4>\u4e00\u3001redisObject \u7684\u7ed3\u6784\u5b9a\u4e49<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250529013809-6837ba813637b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h4>\u4e8c\u3001\u6838\u5fc3\u5b57\u6bb5\u8be6\u89e3<\/h4>\n<h5>1. \u6570\u636e\u7c7b\u578b&#xff08;type&#xff09;<\/h5>\n<p>Redis \u652f\u6301 5 \u79cd\u57fa\u7840\u6570\u636e\u7c7b\u578b&#xff0c;\u7531 type \u6807\u8bc6&#xff1a;<\/p>\n<ul>\n<li>OBJ_STRING&#xff1a;\u5b57\u7b26\u4e32&#xff08;\u7b80\u5355\u503c\u3001\u8ba1\u6570\u5668\u3001\u4e8c\u8fdb\u5236\u6570\u636e&#xff09;\u3002<\/li>\n<li>OBJ_LIST&#xff1a;\u5217\u8868&#xff08;\u961f\u5217\u3001\u6808\u3001\u963b\u585e\u961f\u5217&#xff09;\u3002<\/li>\n<li>OBJ_HASH&#xff1a;\u54c8\u5e0c&#xff08;\u5bf9\u8c61\u5c5e\u6027\u5b58\u50a8&#xff09;\u3002<\/li>\n<li>OBJ_SET&#xff1a;\u96c6\u5408&#xff08;\u552f\u4e00\u6027\u96c6\u5408\u3001\u4ea4\u5e76\u5dee\u8fd0\u7b97&#xff09;\u3002<\/li>\n<li>OBJ_ZSET&#xff1a;\u6709\u5e8f\u96c6\u5408&#xff08;\u6392\u884c\u699c\u3001\u8303\u56f4\u67e5\u8be2&#xff09;\u3002<\/li>\n<\/ul>\n<h5>2. \u7f16\u7801\u65b9\u5f0f&#xff08;encoding&#xff09;<\/h5>\n<p>\u540c\u4e00\u6570\u636e\u7c7b\u578b\u53ef\u5bf9\u5e94\u591a\u79cd\u5e95\u5c42\u7f16\u7801&#xff0c;Redis \u6839\u636e\u6570\u636e\u7279\u5f81\u81ea\u52a8\u9009\u62e9\u6700\u4f18\u7f16\u7801&#xff1a;<\/p>\n<table>\n<tr>\u6570\u636e\u7c7b\u578b\u7f16\u7801\u65b9\u5f0f&#xff08;encoding&#xff09;\u5e95\u5c42\u7ed3\u6784\u9002\u7528\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">\u5b57\u7b26\u4e32<\/td>\n<td align=\"left\">OBJ_ENCODING_INT<\/td>\n<td align=\"left\">\u6574\u6570\u76f4\u63a5\u5b58\u50a8<\/td>\n<td align=\"left\">\u503c\u4e3a\u6574\u6570&#xff08;\u5982 SET key 42&#xff09;<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><\/td>\n<td align=\"left\">OBJ_ENCODING_EMBSTR<\/td>\n<td align=\"left\">embstr \u683c\u5f0f SDS<\/td>\n<td align=\"left\">\u77ed\u5b57\u7b26\u4e32&#xff08;\u226444\u5b57\u8282&#xff09;<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><\/td>\n<td align=\"left\">OBJ_ENCODING_RAW<\/td>\n<td align=\"left\">SDS \u52a8\u6001\u5b57\u7b26\u4e32<\/td>\n<td align=\"left\">\u957f\u5b57\u7b26\u4e32\u6216\u4e8c\u8fdb\u5236\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u5217\u8868<\/td>\n<td align=\"left\">OBJ_ENCODING_QUICKLIST<\/td>\n<td align=\"left\">\u5feb\u901f\u5217\u8868&#xff08;\u5206\u6bb5 ziplist&#xff09;<\/td>\n<td align=\"left\">\u9ed8\u8ba4\u5b9e\u73b0&#xff08;Redis 3.2&#043;&#xff09;<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u54c8\u5e0c<\/td>\n<td align=\"left\">OBJ_ENCODING_ZIPLIST<\/td>\n<td align=\"left\">\u538b\u7f29\u5217\u8868&#xff08;ziplist&#xff09;<\/td>\n<td align=\"left\">\u5b57\u6bb5\u5c11\u4e14\u503c\u5c0f&#xff08;\u914d\u7f6e\u9608\u503c\u5185&#xff09;<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><\/td>\n<td align=\"left\">OBJ_ENCODING_HT<\/td>\n<td align=\"left\">\u54c8\u5e0c\u8868&#xff08;dict&#xff09;<\/td>\n<td align=\"left\">\u5b57\u6bb5\u591a\u6216\u503c\u5927<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u96c6\u5408<\/td>\n<td align=\"left\">OBJ_ENCODING_INTSET<\/td>\n<td align=\"left\">\u6574\u6570\u96c6\u5408&#xff08;intset&#xff09;<\/td>\n<td align=\"left\">\u5143\u7d20\u5168\u4e3a\u6574\u6570\u4e14\u6570\u91cf\u5c11<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><\/td>\n<td align=\"left\">OBJ_ENCODING_HT<\/td>\n<td align=\"left\">\u54c8\u5e0c\u8868&#xff08;dict&#xff09;<\/td>\n<td align=\"left\">\u5143\u7d20\u542b\u975e\u6574\u6570\u6216\u6570\u91cf\u8d85\u9650<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u6709\u5e8f\u96c6\u5408<\/td>\n<td align=\"left\">OBJ_ENCODING_ZIPLIST<\/td>\n<td align=\"left\">\u538b\u7f29\u5217\u8868&#xff08;ziplist&#xff09;<\/td>\n<td align=\"left\">\u5143\u7d20\u5c11\u4e14\u503c\u5c0f&#xff08;\u914d\u7f6e\u9608\u503c\u5185&#xff09;<\/td>\n<\/tr>\n<tr>\n<td align=\"left\"><\/td>\n<td align=\"left\">OBJ_ENCODING_SKIPLIST<\/td>\n<td align=\"left\">\u8df3\u8dc3\u8868 &#043; \u54c8\u5e0c\u8868&#xff08;\u7ec4\u5408\u7ed3\u6784&#xff09;<\/td>\n<td align=\"left\">\u5143\u7d20\u591a\u6216\u503c\u5927<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.2k\u6b21\uff0c\u70b9\u8d5e35\u6b21\uff0c\u6536\u85cf20\u6b21\u3002\u6570\u636e\u7c7b\u578b\uff08typeRedis \u652f\u6301 5 \u79cd\u57fa\u7840\u6570\u636e\u7c7b\u578b\uff0c\u7531typeOBJ_STRING\uff1a\u5b57\u7b26\u4e32\uff08\u7b80\u5355\u503c\u3001\u8ba1\u6570\u5668\u3001\u4e8c\u8fdb\u5236\u6570\u636e\uff09\u3002OBJ_LIST\uff1a\u5217\u8868\uff08\u961f\u5217\u3001\u6808\u3001\u963b\u585e\u961f\u5217\uff09\u3002OBJ_HASH\uff1a\u54c8\u5e0c\uff08\u5bf9\u8c61\u5c5e\u6027\u5b58\u50a8\uff09\u3002OBJ_SET\uff1a\u96c6\u5408\uff08\u552f\u4e00\u6027\u96c6\u5408\u3001\u4ea4\u5e76\u5dee\u8fd0\u7b97\uff09\u3002OBJ_ZSET\uff1a\u6709\u5e8f\u96c6\u5408\uff08\u6392\u884c\u699c\u3001\u8303\u56f4\u67e5\u8be2\uff09\u3002<\/p>\n","protected":false},"author":2,"featured_media":40518,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[105,100,1813],"topic":[],"class_list":["post-40528","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-redis","tag-100","tag-1813"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010redis\u539f\u7406\u7bc7\u3011\u5e95\u5c42\u6570\u636e\u7ed3\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/40528.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010redis\u539f\u7406\u7bc7\u3011\u5e95\u5c42\u6570\u636e\u7ed3\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.2k\u6b21\uff0c\u70b9\u8d5e35\u6b21\uff0c\u6536\u85cf20\u6b21\u3002\u6570\u636e\u7c7b\u578b\uff08typeRedis \u652f\u6301 5 \u79cd\u57fa\u7840\u6570\u636e\u7c7b\u578b\uff0c\u7531typeOBJ_STRING\uff1a\u5b57\u7b26\u4e32\uff08\u7b80\u5355\u503c\u3001\u8ba1\u6570\u5668\u3001\u4e8c\u8fdb\u5236\u6570\u636e\uff09\u3002OBJ_LIST\uff1a\u5217\u8868\uff08\u961f\u5217\u3001\u6808\u3001\u963b\u585e\u961f\u5217\uff09\u3002OBJ_HASH\uff1a\u54c8\u5e0c\uff08\u5bf9\u8c61\u5c5e\u6027\u5b58\u50a8\uff09\u3002OBJ_SET\uff1a\u96c6\u5408\uff08\u552f\u4e00\u6027\u96c6\u5408\u3001\u4ea4\u5e76\u5dee\u8fd0\u7b97\uff09\u3002OBJ_ZSET\uff1a\u6709\u5e8f\u96c6\u5408\uff08\u6392\u884c\u699c\u3001\u8303\u56f4\u67e5\u8be2\uff09\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/40528.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-29T01:38:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250529013808-6837ba8011140.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/40528.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/40528.html\",\"name\":\"\u3010redis\u539f\u7406\u7bc7\u3011\u5e95\u5c42\u6570\u636e\u7ed3\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-29T01:38:10+00:00\",\"dateModified\":\"2025-05-29T01:38:10+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/40528.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/40528.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/40528.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010redis\u539f\u7406\u7bc7\u3011\u5e95\u5c42\u6570\u636e\u7ed3\u6784\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010redis\u539f\u7406\u7bc7\u3011\u5e95\u5c42\u6570\u636e\u7ed3\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/40528.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010redis\u539f\u7406\u7bc7\u3011\u5e95\u5c42\u6570\u636e\u7ed3\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.2k\u6b21\uff0c\u70b9\u8d5e35\u6b21\uff0c\u6536\u85cf20\u6b21\u3002\u6570\u636e\u7c7b\u578b\uff08typeRedis \u652f\u6301 5 \u79cd\u57fa\u7840\u6570\u636e\u7c7b\u578b\uff0c\u7531typeOBJ_STRING\uff1a\u5b57\u7b26\u4e32\uff08\u7b80\u5355\u503c\u3001\u8ba1\u6570\u5668\u3001\u4e8c\u8fdb\u5236\u6570\u636e\uff09\u3002OBJ_LIST\uff1a\u5217\u8868\uff08\u961f\u5217\u3001\u6808\u3001\u963b\u585e\u961f\u5217\uff09\u3002OBJ_HASH\uff1a\u54c8\u5e0c\uff08\u5bf9\u8c61\u5c5e\u6027\u5b58\u50a8\uff09\u3002OBJ_SET\uff1a\u96c6\u5408\uff08\u552f\u4e00\u6027\u96c6\u5408\u3001\u4ea4\u5e76\u5dee\u8fd0\u7b97\uff09\u3002OBJ_ZSET\uff1a\u6709\u5e8f\u96c6\u5408\uff08\u6392\u884c\u699c\u3001\u8303\u56f4\u67e5\u8be2\uff09\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/40528.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-29T01:38:10+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250529013808-6837ba8011140.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"9 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/40528.html","url":"https:\/\/www.wsisp.com\/helps\/40528.html","name":"\u3010redis\u539f\u7406\u7bc7\u3011\u5e95\u5c42\u6570\u636e\u7ed3\u6784 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-29T01:38:10+00:00","dateModified":"2025-05-29T01:38:10+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/40528.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/40528.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/40528.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010redis\u539f\u7406\u7bc7\u3011\u5e95\u5c42\u6570\u636e\u7ed3\u6784"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/40528","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=40528"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/40528\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/40518"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=40528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=40528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=40528"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=40528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}