{"id":84815,"date":"2026-07-26T18:18:08","date_gmt":"2026-07-26T10:18:08","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/84815.html"},"modified":"2026-07-26T18:18:08","modified_gmt":"2026-07-26T10:18:08","slug":"linux-c-c-%e5%ad%a6%e4%b9%a0%e6%97%a5%e8%ae%b0%ef%bc%8865%ef%bc%89%ef%bc%9aredis%ef%bc%88%e5%85%ad%ef%bc%89%ef%bc%9a%e8%ae%ba%e5%8d%95%e7%ba%bf%e7%a8%8b%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/84815.html","title":{"rendered":"Linux C\/C++ \u5b66\u4e60\u65e5\u8bb0\uff0865\uff09\uff1aRedis\uff08\u516d\uff09\uff1a\u8bba\u201d\u5355\u7ebf\u7a0b\u201c\u670d\u52a1\u5668\u662f\u5982\u4f55\u5b9e\u73b0\u9ad8\u6027\u80fd\u7684\uff0c\u542b\u90e8\u5206\u6e90\u7801\u5256\u6790"},"content":{"rendered":"<p>\u6ce8&#xff1a;\u8be5\u6587\u7528\u4e8e\u4e2a\u4eba\u5b66\u4e60\u8bb0\u5f55\u548c\u77e5\u8bc6\u4ea4\u6d41&#xff0c;\u5982\u6709\u4e0d\u8db3&#xff0c;\u6b22\u8fce\u6307\u70b9\u3002<\/p>\n<h2>\u4e00\u3001\u7ebf\u7a0b\u6570\u76ee<\/h2>\n<ul>\n<li>\u64cd\u4f5c\u6570\u636e\u7ed3\u6784\u7684\u8bed\u53e5&#xff08;\u5373\u6267\u884c\u6307\u4ee4&#xff09;\u662f\u4e3b\u7ebf\u7a0b&#xff08;\u5355\u7ebf\u7a0b&#xff0c;\u5929\u7136\u5177\u5907\u9694\u79bb\u6027\u3001\u4e0d\u9700\u8981\u52a0\u9501&#xff09;<\/li>\n<li>\u522b\u7684\u7ebf\u7a0b\u4e3b\u8981\u7528\u4e8e\u4f18\u5316&#xff1a;\u907f\u514dIO\u5bc6\u96c6\u578b\u548cCPU\u5bc6\u96c6\u578b\u8fc7\u591a\u5360\u7528\u4e3b\u7ebf\u7a0b<\/li>\n<\/ul>\n<h2>\u4e8c\u3001IO\u5bc6\u96c6\u578b\u5c42\u9762\u7684\u4f18\u5316<\/h2>\n<h3>1. \u78c1\u76d8IO<\/h3>\n<ul>\n<li>rdb&#xff1a;\u901a\u8fc7fork\u5b50\u8fdb\u7a0b\u6765\u6301\u4e45\u5316<\/li>\n<li>aof&#xff1a;\u6709\u5f02\u6b65\u5237\u76d8\u673a\u5236&#xff08;\u53ef\u9009&#xff09;<\/li>\n<\/ul>\n<h3>2. \u7f51\u7edcIO<\/h3>\n<ul>\n<li>\u901a\u8fc7reactor\u6a21\u578b\u7ba1\u7406\u591a\u4e2a\u8fde\u63a5&#xff08;\u4e3b\u7ebf\u7a0b&#xff09;<\/li>\n<li>\u6570\u636e\u7684\u63a5\u6536&#xff0c;\u6570\u636e\u53d1\u9001\u5206\u644a\u5230\u591a\u4e2aio\u5b50\u8fdb\u7a0b\u4e2d<\/li>\n<\/ul>\n<h2>\u4e09\u3001CPU\u5bc6\u96c6\u578b\u5c42\u9762\u7684\u4f18\u5316<\/h2>\n<ul>\n<li>\u5206\u6cbb\u601d\u60f3&#xff1a;\u534f\u8bae\u7684\u89e3\u6790&#xff08;\u547d\u4ee4\u63a5\u6536\u5b8c\u4e4b\u540e&#xff09;\u3001\u534f\u8bae\u7684\u52a0\u5bc6&#xff08;\u54cd\u5e94\u56de\u590d\u524d&#xff09;\u5206\u644a\u5230\u591a\u4e2aio\u5b50\u8fdb\u7a0b<\/li>\n<li>\u6570\u636e\u7ed3\u6784\u7684\u5207\u6362&#xff1a;value\u7684\u4e0d\u540c\u6570\u636e\u7ed3\u6784\u5e95\u5c42\u5b58\u50a8\u65b9\u5f0f\u5728\u6570\u636e\u91cf\u4e0d\u540c\u60c5\u51b5\u4e0b\u91c7\u53d6\u4e0d\u540c\u7684\u7b56\u7565&#xff08;\u5728\u6267\u884c\u6548\u7387\u4e0e\u7a7a\u95f4\u5360\u6bd4\u95f4\u4fdd\u6301\u5e73\u8861&#xff09;<\/li>\n<li>\u6e10\u8fdb\u5f0f\u6570\u636e\u8fc1\u79fb&#xff1a;rehash\u7684\u4e24\u79cd\u65b9\u5f0f&#xff1a;\n<ul>\n<li>\u6bcf\u6267\u884c\u4e00\u6761\u6307\u4ee4copy\u4e00\u4e2a\u69fd\u4f4d<\/li>\n<li>\u5f53\u670d\u52a1\u5668\u7a7a\u95f2\u65f6&#xff0c;\u5b9a\u65f61ms\u8fdb\u884crehash\u7684\u6570\u636e\u8fc1\u79fb<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u56db\u3001\u6570\u636e\u7ed3\u6784\u5c42\u9762\u4f18\u5316<\/h2>\n<table>\n<tr>\u7f16\u7801\u7c7b\u578b\u7279\u70b9&#xff08;\u5185\u5b58 \/ \u6027\u80fd&#xff09;\u9002\u7528\u573a\u666f<\/tr>\n<tbody>\n<tr>\n<td>\u7d27\u51d1\u7f16\u7801&#xff08;ziplist\/intset\/embstr&#xff09;<\/td>\n<td>\u5185\u5b58\u5360\u7528\u6781\u5c11&#xff0c;\u5b58\u50a8\u5bc6\u5ea6\u9ad8&#xff0c;\u4f46\u589e\u5220\u6539\u9700\u8981\u9891\u7e41\u91cd\u6392\u5185\u5b58<\/td>\n<td>\u6570\u636e\u91cf\u5c0f\u3001\u8bbf\u95ee\u4e0d\u9891\u7e41<\/td>\n<\/tr>\n<tr>\n<td>\u9ad8\u6548\u7f16\u7801&#xff08;dict\/skiplist\/raw&#xff09;<\/td>\n<td>\u5185\u5b58\u5360\u7528\u9ad8&#xff08;\u6709\u7ed3\u6784\u5f00\u9500&#xff09;&#xff0c;\u4f46\u589e\u5220\u6539\u67e5\u6548\u7387\u9ad8&#xff08;O (1)\/O (logN)&#xff09;<\/td>\n<td>\u6570\u636e\u91cf\u5927\u3001\u8bbf\u95ee\u9891\u7e41<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7b80\u5355\u8bf4&#xff1a;\u6570\u636e\u91cf\u5c0f\u65f6\u7528 \u201c\u7d27\u51d1\u7f16\u7801\u201d \u7701\u5185\u5b58&#xff0c;\u6570\u636e\u91cf\u5927\u65f6\u7528 \u201c\u9ad8\u6548\u7f16\u7801\u201d \u4fdd\u6027\u80fd\u3002<\/p>\n<\/p>\n<h3 style=\"background-color:transparent\">1. \u54c8\u5e0c &#xff08;ziplist \u2192 dict&#xff09;<\/h3>\n<ul>\n<li>ziplist&#xff08;\u538b\u7f29\u5217\u8868&#xff09;&#xff1a;\n<ul>\n<li>\u5185\u5b58\u4e0a&#xff1a;\u6240\u6709\u952e\u503c\u5bf9 \/ \u5143\u7d20\u8fde\u7eed\u5b58\u50a8&#xff0c;\u65e0\u5197\u4f59\u6307\u9488&#xff08;dict \u6bcf\u4e2a\u952e\u503c\u5bf9\u8981\u5b58\u4e24\u4e2a\u6307\u9488&#xff0c;skiplist \u6bcf\u4e2a\u8282\u70b9\u6709\u591a\u5c42\u6307\u9488&#xff09;&#xff0c;\u5185\u5b58\u5bc6\u5ea6\u662f dict \u7684 1\/5 \u4ee5\u4e0a&#xff1b;<\/li>\n<li>\u6027\u80fd\u4e0a&#xff1a;\u589e\u5220\u6539\u9700\u8981\u91cd\u6392\u6574\u4e2a\u5217\u8868&#xff08;O (n)&#xff09;&#xff0c;\u4f46\u6570\u636e\u91cf\u5c0f&#xff08;\u2264512\/128 \u4e2a\u5143\u7d20&#xff09;\u65f6&#xff0c;n \u5f88\u5c0f&#xff0c;\u6027\u80fd\u635f\u8017\u53ef\u5ffd\u7565&#xff1b;<\/li>\n<\/ul>\n<\/li>\n<li>dict\/skiplist&#xff1a;\n<ul>\n<li>\u5185\u5b58\u4e0a&#xff1a;dict \u6709\u54c8\u5e0c\u8868\u5f00\u9500&#xff08;\u6876\u6570\u7ec4 &#043; \u94fe\u8868&#xff09;\u00a0&#xff1b;<\/li>\n<li>\u6027\u80fd\u4e0a&#xff1a;dict \u67e5\u6539 O (1), \u6570\u636e\u91cf\u5927\u65f6\u8fdc\u5feb\u4e8e ziplist \u7684 O (n)\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u8bbe\u8ba1\u76ee\u7684&#xff1a;\u5c0f\u54c8\u5e0c\u7701\u5185\u5b58&#xff0c;\u5927\u54c8\u5e0c\u7528 dict\u4fdd\u8bc1\u8bfb\u5199\u6027\u80fd\u3002<\/p>\n<\/p>\n<h4>1.1 hashTypeSet<\/h4>\n<p>\/* \u7ed9\u54c8\u5e0c\u5bf9\u8c61\u8bbe\u7f6e field-value \u952e\u503c\u5bf9<br \/>\n * \u53c2\u6570\u8bf4\u660e&#xff1a;<br \/>\n *   o: \u76ee\u6807\u54c8\u5e0c\u5bf9\u8c61&#xff08;robj \u7c7b\u578b&#xff09;<br \/>\n *   field: \u54c8\u5e0c\u7684\u5b57\u6bb5&#xff08;SDS \u5b57\u7b26\u4e32&#xff09;<br \/>\n *   value: \u54c8\u5e0c\u7684\u53d6\u503c&#xff08;SDS \u5b57\u7b26\u4e32&#xff09;<br \/>\n *   flags: \u63a7\u5236\u6807\u5fd7&#xff08;\u5982\u662f\u5426\u63a5\u7ba1 field\/value \u7684\u5185\u5b58\u6240\u6709\u6743&#xff09;<br \/>\n * \u8fd4\u56de\u503c&#xff1a;1 \u8868\u793a\u66f4\u65b0\u4e86\u5df2\u6709\u5b57\u6bb5&#xff0c;0 \u8868\u793a\u65b0\u589e\u4e86\u5b57\u6bb5<br \/>\n *\/<br \/>\nint hashTypeSet(robj *o, sds field, sds value, int flags) {<br \/>\n    int update &#061; 0; \/\/ \u6807\u8bb0\u662f\u5426\u662f\u201c\u66f4\u65b0\u201d\u64cd\u4f5c&#xff08;1&#061;\u66f4\u65b0&#xff0c;0&#061;\u65b0\u589e&#xff09;<\/p>\n<p>    \/* \u5206\u652f1&#xff1a;\u54c8\u5e0c\u5bf9\u8c61\u5f53\u524d\u662f LISTPACK \u7f16\u7801&#xff08;\u7d27\u51d1\u5b58\u50a8&#xff0c;\u66ff\u4ee3\u65e7\u7684 ziplist&#xff09; *\/<br \/>\n    if (o-&gt;encoding &#061;&#061; OBJ_ENCODING_LISTPACK) {<br \/>\n        unsigned char *zl, *fptr, *vptr;<\/p>\n<p>        zl &#061; o-&gt;ptr; \/\/ \u53d6\u51fa listpack \u6307\u9488&#xff08;o-&gt;ptr \u6307\u5411 listpack \u7ed3\u6784\u4f53&#xff09;<br \/>\n        fptr &#061; lpFirst(zl); \/\/ \u6307\u5411 listpack \u7b2c\u4e00\u4e2a\u5143\u7d20<br \/>\n        if (fptr !&#061; NULL) { \/\/ listpack \u975e\u7a7a<br \/>\n            \/\/ \u5728 listpack \u4e2d\u67e5\u627e\u6307\u5b9a field&#xff08;1 \u8868\u793a\u201c\u5339\u914d\u6574\u4e2a\u5b57\u6bb5\u201d&#xff09;<br \/>\n            fptr &#061; lpFind(zl, fptr, (unsigned char*)field, sdslen(field), 1);<br \/>\n            if (fptr !&#061; NULL) { \/\/ \u627e\u5230\u8be5 field&#xff0c;\u6267\u884c\u201c\u66f4\u65b0\u201d\u903b\u8f91<br \/>\n                \/* fptr \u6307\u5411 field&#xff0c;vptr \u6307\u5411 field \u5bf9\u5e94\u7684 value&#xff08;listpack \u4e2d field\/value \u6210\u5bf9\u5b58\u50a8&#xff09; *\/<br \/>\n                vptr &#061; lpNext(zl, fptr);<br \/>\n                serverAssert(vptr !&#061; NULL); \/\/ \u65ad\u8a00&#xff1a;field \u5fc5\u987b\u6709\u5bf9\u5e94\u7684 value&#xff08;\u9632\u5fa1\u6027\u7f16\u7a0b&#xff09;<br \/>\n                update &#061; 1; \/\/ \u6807\u8bb0\u4e3a\u66f4\u65b0\u64cd\u4f5c<\/p>\n<p>                \/* \u66ff\u6362\u539f\u6709 value&#xff1a;lpReplace \u4f1a\u91cd\u65b0\u5206\u914d listpack \u5185\u5b58&#xff08;\u82e5\u9700\u8981&#xff09;&#xff0c;\u8fd4\u56de\u65b0\u7684 listpack \u6307\u9488 *\/<br \/>\n                zl &#061; lpReplace(zl, &amp;vptr, (unsigned char*)value, sdslen(value));<br \/>\n            }<br \/>\n        }<\/p>\n<p>        if (!update) { \/\/ \u672a\u627e\u5230 field&#xff0c;\u6267\u884c\u201c\u65b0\u589e\u201d\u903b\u8f91<br \/>\n            \/* \u5c06 field \u548c value \u4f9d\u6b21\u8ffd\u52a0\u5230 listpack \u5c3e\u90e8&#xff08;\u6210\u5bf9\u5b58\u50a8&#xff09; *\/<br \/>\n            zl &#061; lpAppend(zl, (unsigned char*)field, sdslen(field)); \/\/ \u8ffd\u52a0 field<br \/>\n            zl &#061; lpAppend(zl, (unsigned char*)value, sdslen(value)); \/\/ \u8ffd\u52a0 value<br \/>\n        }<br \/>\n        o-&gt;ptr &#061; zl; \/\/ \u66f4\u65b0\u5bf9\u8c61\u7684 listpack \u6307\u9488&#xff08;\u53ef\u80fd\u662f\u65b0\u5206\u914d\u7684\u5185\u5b58&#xff09;<\/p>\n<p>        \/* \u5173\u952e&#xff1a;\u68c0\u67e5\u662f\u5426\u9700\u8981\u4ece LISTPACK \u8f6c\u6362\u4e3a\u54c8\u5e0c\u8868&#xff08;HT&#xff09;<br \/>\n         * hash_max_listpack_entries \u662f\u914d\u7f6e\u9608\u503c&#xff08;\u9ed8\u8ba4512&#xff09;&#xff0c;\u5143\u7d20\u6570\u8d85\u8fc7\u9608\u503c\u5219\u8f6c\u6362<br \/>\n         * \u76ee\u7684&#xff1a;listpack \u589e\u5220\u6539\u662f O(n)&#xff0c;\u6570\u636e\u91cf\u5927\u65f6\u6027\u80fd\u5dee&#xff0c;\u8f6c\u4e3a HT&#xff08;O(1) \u8bfb\u5199&#xff09;<br \/>\n         *\/<br \/>\n        if (hashTypeLength(o) &gt; server.hash_max_listpack_entries)<br \/>\n            hashTypeConvert(o, OBJ_ENCODING_HT);<br \/>\n    }<br \/>\n    \/* \u5206\u652f2&#xff1a;\u54c8\u5e0c\u5bf9\u8c61\u5f53\u524d\u662f HT \u7f16\u7801&#xff08;\u54c8\u5e0c\u8868&#xff0c;\u9ad8\u6548\u5b58\u50a8&#xff09; *\/<br \/>\n    else if (o-&gt;encoding &#061;&#061; OBJ_ENCODING_HT) {<br \/>\n        \/\/ \u5728\u54c8\u5e0c\u8868\u4e2d\u67e5\u627e field \u5bf9\u5e94\u7684\u6761\u76ee<br \/>\n        dictEntry *de &#061; dictFind(o-&gt;ptr,field);<br \/>\n        if (de) { \/\/ \u627e\u5230\u6761\u76ee&#xff0c;\u6267\u884c\u201c\u66f4\u65b0\u201d\u903b\u8f91<br \/>\n            sdsfree(dictGetVal(de)); \/\/ \u91ca\u653e\u539f\u6709 value \u7684 SDS \u5185\u5b58<br \/>\n            \/\/ \u6839\u636e flags \u51b3\u5b9a\u662f\u5426\u63a5\u7ba1 value \u7684\u5185\u5b58\u6240\u6709\u6743<br \/>\n            if (flags &amp; HASH_SET_TAKE_VALUE) {<br \/>\n                dictGetVal(de) &#061; value; \/\/ \u76f4\u63a5\u590d\u7528 value \u6307\u9488&#xff08;\u4e0d\u590d\u5236&#xff09;<br \/>\n                value &#061; NULL; \/\/ \u6807\u8bb0 value \u5df2\u88ab\u63a5\u7ba1&#xff0c;\u540e\u7eed\u65e0\u9700\u91ca\u653e<br \/>\n            } else {<br \/>\n                dictGetVal(de) &#061; sdsdup(value); \/\/ \u590d\u5236 value&#xff08;\u4fdd\u7559\u539f value \u6240\u6709\u6743&#xff09;<br \/>\n            }<br \/>\n            update &#061; 1; \/\/ \u6807\u8bb0\u4e3a\u66f4\u65b0\u64cd\u4f5c<br \/>\n        } else { \/\/ \u672a\u627e\u5230\u6761\u76ee&#xff0c;\u6267\u884c\u201c\u65b0\u589e\u201d\u903b\u8f91<br \/>\n            sds f,v;<br \/>\n            \/\/ \u5904\u7406 field \u7684\u5185\u5b58\u6240\u6709\u6743&#xff1a;\u662f\u5426\u63a5\u7ba1&#xff08;\u4e0d\u590d\u5236&#xff09;<br \/>\n            if (flags &amp; HASH_SET_TAKE_FIELD) {<br \/>\n                f &#061; field; \/\/ \u76f4\u63a5\u590d\u7528 field \u6307\u9488<br \/>\n                field &#061; NULL; \/\/ \u6807\u8bb0 field \u5df2\u88ab\u63a5\u7ba1<br \/>\n            } else {<br \/>\n                f &#061; sdsdup(field); \/\/ \u590d\u5236 field<br \/>\n            }<br \/>\n            \/\/ \u5904\u7406 value \u7684\u5185\u5b58\u6240\u6709\u6743&#xff1a;\u662f\u5426\u63a5\u7ba1&#xff08;\u4e0d\u590d\u5236&#xff09;<br \/>\n            if (flags &amp; HASH_SET_TAKE_VALUE) {<br \/>\n                v &#061; value; \/\/ \u76f4\u63a5\u590d\u7528 value \u6307\u9488<br \/>\n                value &#061; NULL; \/\/ \u6807\u8bb0 value \u5df2\u88ab\u63a5\u7ba1<br \/>\n            } else {<br \/>\n                v &#061; sdsdup(value); \/\/ \u590d\u5236 value<br \/>\n            }<br \/>\n            dictAdd(o-&gt;ptr,f,v); \/\/ \u5c06 field-value \u52a0\u5165\u54c8\u5e0c\u8868<br \/>\n        }<br \/>\n    }<br \/>\n    \/* \u5206\u652f3&#xff1a;\u672a\u77e5\u7f16\u7801&#xff0c;\u76f4\u63a5\u5d29\u6e83&#xff08;\u9632\u5fa1\u6027\u7f16\u7a0b&#xff09; *\/<br \/>\n    else {<br \/>\n        serverPanic(&#034;Unknown hash encoding&#034;);<br \/>\n    }<\/p>\n<p>    \/* \u6536\u5c3e&#xff1a;\u91ca\u653e\u672a\u88ab\u63a5\u7ba1\u7684 SDS \u5185\u5b58&#xff08;\u907f\u514d\u5185\u5b58\u6cc4\u6f0f&#xff09;<br \/>\n     * \u82e5 flags \u8981\u6c42\u51fd\u6570\u63a5\u7ba1 field\/value \u6240\u6709\u6743&#xff0c;\u4f46\u672a\u88ab\u4f7f\u7528&#xff0c;\u5219\u91ca\u653e<br \/>\n     *\/<br \/>\n    if (flags &amp; HASH_SET_TAKE_FIELD &amp;&amp; field) sdsfree(field);<br \/>\n    if (flags &amp; HASH_SET_TAKE_VALUE &amp;&amp; value) sdsfree(value);<br \/>\n    return update; \/\/ \u8fd4\u56de\u662f\u5426\u662f\u66f4\u65b0\u64cd\u4f5c<br \/>\n}<\/p>\n<p>&#xff08;t_hash.c)<\/p>\n<\/p>\n<h4>1.2 dict\u7ed3\u6784\u4f53<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"415\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260726101806-6a65dede5b436.png\" width=\"865\" \/><\/p>\n<p>&#xff08;dict.h&#xff09;<\/p>\n<\/p>\n<h4>1.3 rehash<\/h4>\n<p>ht_table[0];\u00a0 \/\/ \u7528\u6237\u8bbf\u95ee\u7684\u6570\u636e\u7ed3\u6784<\/p>\n<p>ht_table[1] &#061; null; \/\/ \u7528\u4e8e\u6e10\u8fdb\u5f0f\u6570\u636e\u8fc1\u79fb&#xff08;rehashidx&#xff09;<\/p>\n<p>\u6e10\u8fdb\u5f0f\u8fc1\u79fb<\/p>\n<ul>\n<li style=\"text-align:justify\">\u6cd51&#xff1a;\u5206\u644a\u5728\u589e\u5220\u6539\u67e5\u4e2d&#xff0c;\u6bcf\u6b21\u64cd\u4f5c\u5c31\u8fc1\u79fb\u4e00\u4e2a\u69fd\u4f4d<\/li>\n<li style=\"text-align:justify\">\u6cd52&#xff1a;redis\u7a7a\u95f2\u65f6&#xff0c;\u8fc1\u79fb1ms\u7684\u65f6\u95f4<\/li>\n<\/ul>\n<p>\u64cd\u4f5c\u5b8c\u4e4b\u540e&#xff0c;\u91ca\u653eht_table[0]&#xff0c;\u5c06\u5176\u6307\u5411\u6570\u636e\u8fc1\u79fb\u5b8c\u6bd5\u7684\u7ed3\u6784\u4f53&#xff0c;\u7136\u540e\u7f6eht_table[1]\u4e3anull<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"701\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260726101806-6a65dede818b1.png\" width=\"855\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"494\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260726101806-6a65dedeb3f1d.png\" width=\"844\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"446\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260726101806-6a65dededb7cc.png\" width=\"821\" \/><\/p>\n<\/p>\n<h3 style=\"background-color:transparent\">2. \u5b57\u7b26\u4e32&#xff08;int \u2192 embstr \u2192 raw&#xff09;<\/h3>\n<ul>\n<li>int \u7f16\u7801&#xff1a;\u6570\u5b57\u578b\u5b57\u7b26\u4e32\u76f4\u63a5\u5b58\u6210\u6574\u6570&#xff0c;\u629b\u5f03 SDS \u7ed3\u6784&#xff0c;\u5185\u5b58\u4ece \u201credisObject&#043;SDS\u201d&#xff08;\u226523 \u5b57\u8282&#xff09;\u964d\u5230\u4ec5 redisObject&#xff08;16 \u5b57\u8282&#xff09;&#xff0c;\u4e14\u6574\u6570\u8fd0\u7b97\u65e0\u9700\u89e3\u6790\u5b57\u7b26\u4e32&#xff0c;\u6548\u7387\u62c9\u6ee1&#xff1b;<\/li>\n<li>embstr \u7f16\u7801&#xff1a;\u77ed\u5b57\u7b26\u4e32&#xff08;\u226444 \u5b57\u8282&#xff09;\u7528\u8fde\u7eed\u5185\u5b58\u5b58\u50a8&#xff0c;\u4e00\u6b21\u5206\u914d \/ \u91ca\u653e&#xff0c;CPU \u7f13\u5b58\u547d\u4e2d\u7387\u9ad8&#xff08;64 \u5b57\u8282\u7f13\u5b58\u884c\u521a\u597d\u88c5\u4e0b&#xff09;&#xff0c;\u6bd4 raw \u5c11\u4e00\u6b21\u5185\u5b58\u7533\u8bf7&#xff1b;<\/li>\n<li>raw \u7f16\u7801&#xff1a;\u957f\u5b57\u7b26\u4e32\u65e0\u6cd5\u585e\u8fdb 64 \u5b57\u8282\u7f13\u5b58\u884c&#xff0c;\u53ea\u80fd\u5206\u79bb\u5b58\u50a8&#xff0c;\u727a\u7272\u4e00\u70b9\u5185\u5b58\u6548\u7387&#xff0c;\u4fdd\u8bc1\u957f\u5b57\u7b26\u4e32\u7684\u8bfb\u5199\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p>\u8bbe\u8ba1\u76ee\u7684&#xff1a;\u6570\u5b57 \/ \u77ed\u5b57\u7b26\u4e32\u6781\u81f4\u7701\u5185\u5b58&#xff0c;\u957f\u5b57\u7b26\u4e32\u4fdd\u8bc1\u529f\u80fd\u517c\u5bb9&#xff08;\u6700\u5927 512MB&#xff09;<\/p>\n<\/p>\n<h4>2.1\u00a0string\u5bf9\u8c61\u7684\u6784\u5efa<\/h4>\n<p>\/* \u5c1d\u8bd5\u5bf9\u5b57\u7b26\u4e32\u5bf9\u8c61\u8fdb\u884c\u7f16\u7801\u4f18\u5316&#xff0c;\u4ee5\u8282\u7701\u5185\u5b58\u7a7a\u95f4<br \/>\n * \u6838\u5fc3\u903b\u8f91&#xff1a;RAW\/EMBSTR \u2192 INT&#xff08;\u6570\u5b57\u578b&#xff09; \u6216 \u77ed\u5b57\u7b26\u4e32\u2192EMBSTR&#xff0c;\u957f\u5b57\u7b26\u4e32\u4f18\u5316SDS<br \/>\n * \u8fd4\u56de\u503c&#xff1a;\u4f18\u5316\u540e\u7684\u5bf9\u8c61&#xff08;\u53ef\u80fd\u662f\u65b0\u5bf9\u8c61&#xff0c;\u4e5f\u53ef\u80fd\u662f\u539f\u5bf9\u8c61&#xff09;<br \/>\n *\/<br \/>\nrobj *tryObjectEncoding(robj *o) {<br \/>\n    long value;          \/\/ \u5b58\u50a8\u5b57\u7b26\u4e32\u8f6c\u6362\u540e\u7684\u6574\u6570\u503c<br \/>\n    sds s &#061; o-&gt;ptr;      \/\/ \u53d6\u51fa\u5b57\u7b26\u4e32\u5bf9\u8c61\u7684SDS\u6307\u9488<br \/>\n    size_t len;          \/\/ \u5b57\u7b26\u4e32\u957f\u5ea6<\/p>\n<p>    \/* \u65ad\u8a00&#xff1a;\u5f53\u524d\u5bf9\u8c61\u5fc5\u987b\u662f\u5b57\u7b26\u4e32\u7c7b\u578b&#xff08;OBJ_STRING&#xff09;<br \/>\n     * \u8fd9\u4e2a\u51fd\u6570\u53ea\u5904\u7406\u5b57\u7b26\u4e32\u5bf9\u8c61\u7684\u7f16\u7801\u4f18\u5316&#xff0c;\u5176\u4ed6\u7c7b\u578b\u7531\u5404\u81ea\u7684\u547d\u4ee4\u5904\u7406<br \/>\n     *\/<br \/>\n    serverAssertWithInfo(NULL,o,o-&gt;type &#061;&#061; OBJ_STRING);<\/p>\n<p>    \/* \u53ea\u5bf9 RAW\/EMBSTR \u7f16\u7801\u7684\u5b57\u7b26\u4e32\u505a\u4f18\u5316&#xff08;\u8fd9\u4e24\u79cd\u7f16\u7801\u662f\u57fa\u4e8e\u5b57\u7b26\u6570\u7ec4\u7684\u539f\u59cb\u5b58\u50a8&#xff09;<br \/>\n     * \u5df2\u7ecf\u662fINT\u7f16\u7801\u7684\u5bf9\u8c61\u65e0\u9700\u518d\u4f18\u5316<br \/>\n     *\/<br \/>\n    if (!sdsEncodedObject(o)) return o;<\/p>\n<p>    \/* \u5171\u4eab\u5bf9\u8c61\u4e0d\u505a\u7f16\u7801\u4f18\u5316&#xff1a;<br \/>\n     * \u5171\u4eab\u5bf9\u8c61&#xff08;\u5982\u5171\u4eab\u6574\u6570&#xff09;\u53ef\u80fd\u88ab\u6574\u4e2aRedis\u7684\u5bf9\u8c61\u7a7a\u95f4\u5f15\u7528&#xff0c;\u4f18\u5316\u540e\u53ef\u80fd\u5bfc\u81f4\u903b\u8f91\u5f02\u5e38<br \/>\n     * \u5171\u4eab\u5bf9\u8c61\u4ec5\u4f5c\u4e3a\u952e\u7a7a\u95f4\u7684\u503c\u4f7f\u7528\u65f6\u624d\u5b89\u5168&#xff0c;\u56e0\u6b64\u5f15\u7528\u8ba1\u6570&gt;1\u65f6\u76f4\u63a5\u8fd4\u56de\u539f\u5bf9\u8c61<br \/>\n     *\/<br \/>\n    if (o-&gt;refcount &gt; 1) return o;<\/p>\n<p>    \/* \u7b2c\u4e00\u6b65&#xff1a;\u5c1d\u8bd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u957f\u6574\u6570&#xff08;INT\u7f16\u7801\u4f18\u5316&#xff09;<br \/>\n     * \u6ce8&#xff1a;\u957f\u5ea6&gt;20\u5b57\u8282\u7684\u5b57\u7b26\u4e32\u4e0d\u53ef\u80fd\u8f6c\u621032\/64\u4f4d\u6574\u6570&#xff0c;\u76f4\u63a5\u8df3\u8fc7<br \/>\n     *\/<br \/>\n    len &#061; sdslen(s); \/\/ \u83b7\u53d6SDS\u5b57\u7b26\u4e32\u7684\u5b9e\u9645\u957f\u5ea6<br \/>\n    if (len &lt;&#061; 20 &amp;&amp; string2l(s,len,&amp;value)) { \/\/ \u957f\u5ea6\u226420\u4e14\u80fd\u8f6c\u6210long\u6574\u6570<br \/>\n        \/* \u5c1d\u8bd5\u4f7f\u7528\u5171\u4eab\u6574\u6570\u5bf9\u8c61&#xff08;\u8fdb\u4e00\u6b65\u8282\u7701\u5185\u5b58&#xff09;<br \/>\n         * \u4f8b\u5916\u573a\u666f&#xff1a;\u5f00\u542fmaxmemory\u4e14\u7b56\u7565\u4e0d\u5141\u8bb8\u5171\u4eab\u6574\u6570\u65f6&#xff0c;\u4e0d\u4f7f\u7528\u5171\u4eab\u5bf9\u8c61<br \/>\n         * \u539f\u56e0&#xff1a;LRU\u6dd8\u6c70\u7b97\u6cd5\u9700\u8981\u6bcf\u4e2a\u5bf9\u8c61\u6709\u72ec\u7acb\u7684LRU\u5b57\u6bb5&#xff0c;\u5171\u4eab\u5bf9\u8c61\u4f1a\u5bfc\u81f4LRU\u7edf\u8ba1\u9519\u8bef<br \/>\n         *\/<br \/>\n        if ((server.maxmemory &#061;&#061; 0 ||<br \/>\n            !(server.maxmemory_policy &amp; MAXMEMORY_FLAG_NO_SHARED_INTEGERS)) &amp;&amp;<br \/>\n            value &gt;&#061; 0 &amp;&amp;<br \/>\n            value &lt; OBJ_SHARED_INTEGERS) \/\/ OBJ_SHARED_INTEGERS\u9ed8\u8ba4\u662f10000&#xff0c;\u5171\u4eab0~9999\u7684\u6574\u6570<br \/>\n        {<br \/>\n            decrRefCount(o); \/\/ \u91ca\u653e\u539f\u5bf9\u8c61\u7684\u5f15\u7528\u8ba1\u6570<br \/>\n            incrRefCount(shared.integers[value]); \/\/ \u589e\u52a0\u5171\u4eab\u5bf9\u8c61\u7684\u5f15\u7528\u8ba1\u6570<br \/>\n            return shared.integers[value]; \/\/ \u8fd4\u56de\u5171\u4eab\u6574\u6570\u5bf9\u8c61<br \/>\n        } else {<br \/>\n            \/\/ \u4e0d\u6ee1\u8db3\u5171\u4eab\u6761\u4ef6\u65f6&#xff0c;\u76f4\u63a5\u5c06\u539f\u5bf9\u8c61\u8f6c\u4e3aINT\u7f16\u7801<br \/>\n            if (o-&gt;encoding &#061;&#061; OBJ_ENCODING_RAW) { \/\/ \u539f\u7f16\u7801\u662fRAW<br \/>\n                sdsfree(o-&gt;ptr); \/\/ \u91ca\u653e\u539fSDS\u5185\u5b58<br \/>\n                o-&gt;encoding &#061; OBJ_ENCODING_INT; \/\/ \u6807\u8bb0\u4e3aINT\u7f16\u7801<br \/>\n                o-&gt;ptr &#061; (void*) value; \/\/ ptr\u4e0d\u518d\u6307\u5411SDS&#xff0c;\u800c\u662f\u5b58\u50a8\u6574\u6570\u503c<br \/>\n                return o; \/\/ \u8fd4\u56de\u4f18\u5316\u540e\u7684\u539f\u5bf9\u8c61<br \/>\n            } else if (o-&gt;encoding &#061;&#061; OBJ_ENCODING_EMBSTR) { \/\/ \u539f\u7f16\u7801\u662fEMBSTR<br \/>\n                decrRefCount(o); \/\/ \u91ca\u653e\u539fEMBSTR\u5bf9\u8c61<br \/>\n                return createStringObjectFromLongLongForValue(value); \/\/ \u521b\u5efa\u65b0\u7684INT\u7f16\u7801\u5bf9\u8c61<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/* \u7b2c\u4e8c\u6b65&#xff1a;\u77ed\u5b57\u7b26\u4e32\u4f18\u5316&#xff08;RAW\u2192EMBSTR&#xff09;<br \/>\n     * OBJ_ENCODING_EMBSTR_SIZE_LIMIT\u9ed8\u8ba4\u662f44\u5b57\u8282&#xff0c;\u957f\u5ea6\u226444\u7684RAW\u5b57\u7b26\u4e32\u8f6cEMBSTR<br \/>\n     * EMBSTR\u7684\u4f18\u52bf&#xff1a;redisObject\u548cSDS\u8fde\u7eed\u5b58\u50a8&#xff0c;\u4e00\u6b21\u5206\u914d\/\u91ca\u653e&#xff0c;\u7f13\u5b58\u547d\u4e2d\u7387\u9ad8<br \/>\n     *\/<br \/>\n    if (len &lt;&#061; OBJ_ENCODING_EMBSTR_SIZE_LIMIT) {<br \/>\n        robj *emb; \/\/ \u65b0\u7684EMBSTR\u7f16\u7801\u5bf9\u8c61<\/p>\n<p>        if (o-&gt;encoding &#061;&#061; OBJ_ENCODING_EMBSTR) return o; \/\/ \u5df2\u7ecf\u662fEMBSTR&#xff0c;\u76f4\u63a5\u8fd4\u56de<br \/>\n        emb &#061; createEmbeddedStringObject(s,sdslen(s)); \/\/ \u521b\u5efaEMBSTR\u5bf9\u8c61<br \/>\n        decrRefCount(o); \/\/ \u91ca\u653e\u539f\u5bf9\u8c61<br \/>\n        return emb; \/\/ \u8fd4\u56de\u65b0\u7684EMBSTR\u5bf9\u8c61<br \/>\n    }<\/p>\n<p>    \/* \u7b2c\u4e09\u6b65&#xff1a;\u957f\u5b57\u7b26\u4e32SDS\u4f18\u5316&#xff08;\u65e0\u6cd5\u8f6cINT\/EMBSTR\u65f6&#xff09;<br \/>\n     * \u5982\u679cSDS\u5c3e\u90e8\u6709\u8d85\u8fc710%\u7684\u7a7a\u95f2\u7a7a\u95f4&#xff0c;\u88c1\u526aSDS\u4ee5\u8282\u7701\u5185\u5b58<br \/>\n     * \u4ec5\u5bf9\u957f\u5ea6&gt;44\u5b57\u8282\u7684\u5b57\u7b26\u4e32\u505a\u6b64\u4f18\u5316&#xff08;\u56e0\u4e3a\u524d\u9762\u5df2\u7ecf\u5904\u7406\u4e86\u77ed\u5b57\u7b26\u4e32&#xff09;<br \/>\n     *\/<br \/>\n    trimStringObjectIfNeeded(o);<\/p>\n<p>    \/* \u65e0\u6cd5\u505a\u4efb\u4f55\u7f16\u7801\u4f18\u5316&#xff0c;\u8fd4\u56de\u539f\u5bf9\u8c61 *\/<br \/>\n    return o;<br \/>\n}<\/p>\n<p>&#xff08;object.c&#xff09;<\/p>\n<\/p>\n<h4>2.2 redisObject\u7ed3\u6784\u4f53<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"263\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260726101807-6a65dedf0b0dd.png\" width=\"946\" \/><\/p>\n<p>&#xff08;server.h&#xff0c;LRU_BITS\u4e3a24 : \u7ed3\u6784\u4f53\u536016\u5b57\u8282&#xff09;<\/p>\n<\/p>\n<h4>2.3\u00a0int\u5f62\u5f0f&#xff1a;\u5f53string\u4e3a\u7eaf\u6570\u5b57\u65f6&#xff08;\u53ef\u4ee5\u542b&#043;-\u53f7&#xff09;\u4e14\u957f\u5ea6 &lt;&#061; 20\u4f4d\u3002<\/h4>\n<p>64 \u4f4d\u7cfb\u7edf\u4e2d void *ptr \u672c\u8eab\u5360 8 \u5b57\u8282&#xff0c;\u4f46\u5728 int \u7f16\u7801\u65f6&#xff0c;Redis \u628a ptr \u5f53\u4f5c long long \u7c7b\u578b&#xff08;\u4e5f\u662f 8 \u5b57\u8282&#xff09;\u6765\u7528&#xff0c;\u800c\u975e\u6307\u9488&#xff1a;<\/p>\n<ul>\n<li>long long \u7684\u53d6\u503c\u8303\u56f4\u662f -9223372036854775808 ~ 9223372036854775807&#xff1b;<\/li>\n<li>\u8fd9\u4e2a\u8303\u56f4\u5bf9\u5e94\u7684\u5341\u8fdb\u5236\u6570\u5b57\u7684\u6700\u5927\u957f\u5ea6\u662f 19 \u4f4d&#xff08;\u6bd4\u5982 9223372036854775807 \u662f 19 \u4f4d&#xff09;&#xff0c;\u52a0\u4e0a\u6b63\u8d1f\u53f7\u5c31\u662f 20 \u4f4d<\/li>\n<\/ul>\n<h4>2.4\u00a0embstr\u5f62\u5f0f<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"68\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260726101807-6a65dedf247cf.png\" width=\"638\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"151\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260726101807-6a65dedf30dde.png\" width=\"656\" \/><\/p>\n<p>&#xff08;sds.h, \u7ed3\u6784\u4f53\u53603\u5b57\u8282&#xff09;<\/p>\n<\/p>\n<h4>2.5.\u00a0raw\u7f16\u7801\u5219\u662fredisObject\u4e2d\u6210\u5458ptr\u6307\u5411\u4e00\u5757\u53e6\u5916\u5206\u914d\u7684\u5185\u5b58\u7a7a\u95f4<\/h4>\n<\/p>\n<h4>2.6 \u603b\u7ed3<\/h4>\n<ul>\n<li>\u5c0f\u4e8e20\u5b57\u8282\u4e14\u4e3a\u6570\u5b57\u65f6&#xff0c;\u9009\u62e9int\u7f16\u7801\u3002<\/li>\n<li>\u5927\u4e8e20\u5b57\u8282\u5c0f\u4e8e44\u5b57\u8282&#xff0c;\u9009\u62e9embstr\u7f16\u7801\u3002\u5927\u4e8e44\u5b57\u8282&#xff0c;\u9009\u62e9raw\u7f16\u7801<\/li>\n<li>embstr&#xff1a;\u5d4c\u5165\u5b57\u7b26\u4e32&#xff0c;\u5d4c\u5165\u5230redisObject\u4e2d&#xff0c;\u800craw\u5c31\u662f\u5728redisObject\u4e2d\u7ef4\u6301\u4e00\u4e2a\u6307\u5411\u5806\u4e0a\u7684\u8d44\u6e90<\/li>\n<li>cpu cache line\u6700\u5c0f\u8bbf\u95ee\u5355\u4f4d\u4e3a64\u5b57\u8282&#xff0c;\u6240\u4ee5\u9009\u62e964\u4e2a\u5b57\u8282\u4f5c\u4e3a\u5206\u754c\u7ebf\u3002<\/li>\n<li>20\u5b57\u8282\u4e3a\u754c\u7684\u539f\u56e0&#xff1a;long long int \u8868\u793a\u7684\u6570\u5b57\u8303\u56f4&#xff1a;-19\u4f4d ~ &#043;19\u4f4d&#xff0c;\u5373\u957f\u5ea6\u4e3a20\u7684\u5b57\u7b26\u4e32<\/li>\n<li>44\u5b57\u8282\u4e3a\u754c\u7684\u539f\u56e0&#xff1a;buf\u53ef\u7528\u7a7a\u95f4\u4e3a&#xff1a;64-16-3-1 &#061; 44\u3002 &#xff08;\u8fd9\u4e2a1\u4f5c\u4e3a&#039;\\\\0&#039;&#xff0c;\u4ee5\u4fbf\u517c\u5bb9c\u7684\u5b57\u7b26\u4e32\u5e93\u51fd\u6570&#xff09;<\/li>\n<\/ul>\n<h3 style=\"background-color:transparent\">3. \u5217\u8868&#xff08;quicklist \u5c01\u88c5 ziplist&#xff09;<\/h3>\n<ul>\n<li>\u65e9\u671f Redis \u5217\u8868\u7528 ziplist&#xff08;\u5c0f\u5217\u8868&#xff09;\u548c linkedlist&#xff08;\u5927\u5217\u8868&#xff09;&#xff0c;\u4f46 linkedlist \u6bcf\u4e2a\u8282\u70b9\u6709\u6307\u9488\u5f00\u9500&#xff0c;\u5185\u5b58\u6548\u7387\u4f4e&#xff1b;<\/li>\n<li>\u73b0\u5728\u6539\u7528 quicklist&#xff08;\u53cc\u5411\u94fe\u8868 &#043; \u6bcf\u4e2a\u8282\u70b9\u662f ziplist&#xff09;&#xff1a;\n<ul>\n<li>\u65e2\u4fdd\u7559\u4e86 ziplist \u7684\u5185\u5b58\u7d27\u51d1\u6027&#xff08;\u6bcf\u4e2a\u8282\u70b9\u5185\u7684\u5143\u7d20\u8fde\u7eed\u5b58\u50a8&#xff09;&#xff1b;<\/li>\n<li>\u53c8\u907f\u514d\u4e86\u7eaf ziplist \u91cd\u6392\u5185\u5b58\u7684\u6027\u80fd\u95ee\u9898&#xff08;\u589e\u5220\u53ea\u5f71\u54cd\u5355\u4e2a ziplist \u8282\u70b9&#xff0c;\u800c\u975e\u6574\u4e2a\u5217\u8868&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u8bbe\u8ba1\u76ee\u7684&#xff1a;\u5e73\u8861\u5185\u5b58\u6548\u7387\u548c\u589e\u5220\u6027\u80fd&#xff0c;\u662f\u5bf9\u4f20\u7edf ziplist\/linkedlist \u7684\u4f18\u5316\u5347\u7ea7\u3002<\/p>\n<h4>\u6838\u5fc3\u8bf4\u660e<\/h4>\n<ul>\n<li>list \u7684\u5e95\u5c42\u7f16\u7801\u662f quicklist&#xff08;\u53cc\u5411\u94fe\u8868&#xff09;&#xff0c;\u800c quicklist \u7684\u6bcf\u4e2a\u8282\u70b9\u53c8\u662f\u4e00\u4e2a ziplist&#xff08;\u538b\u7f29\u5217\u8868\u8282\u70b9&#xff09;&#xff1b;<\/li>\n<li>\u56e0\u6b64&#xff0c;list \u5e76\u4e0d\u76f4\u63a5\u8f6c\u6362\u4e3a ziplist&#xff0c;\u800c\u662f quicklist \u5185\u90e8\u95f4\u63a5\u4f7f\u7528 ziplist \u6765\u5b58\u50a8\u6bcf\u4e2a\u8282\u70b9\u7684\u6570\u636e\u3002<\/li>\n<\/ul>\n<p>\/* &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 1. quicklist \u7ed3\u6784\u4f53&#xff08;\u5217\u8868\u7684\u9876\u5c42\u7ed3\u6784&#xff09;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n * \u8bf4\u660e&#xff1a;Redis\u5217\u8868(List)\u7684\u5e95\u5c42\u5b9e\u73b0&#xff0c;\u662f\u300c\u53cc\u5411\u94fe\u8868 &#043; \u6bcf\u4e2a\u8282\u70b9\u5185\u5d4c listpack\u300d\u7684\u6df7\u5408\u7ed3\u6784&#xff0c;<br \/>\n * \u66ff\u4ee3\u4e86\u65e9\u671f\u7684 ziplist&#xff08;\u5c0f\u5217\u8868&#xff09;\u548c linkedlist&#xff08;\u5927\u5217\u8868&#xff09;&#xff0c;\u5e73\u8861\u5185\u5b58\u6548\u7387\u548c\u589e\u5220\u6027\u80fd<br \/>\n *\/<br \/>\ntypedef struct quicklist {<br \/>\n    quicklistNode *head;          \/\/ \u6307\u5411\u53cc\u5411\u94fe\u8868\u7684\u5934\u8282\u70b9<br \/>\n    quicklistNode *tail;          \/\/ \u6307\u5411\u53cc\u5411\u94fe\u8868\u7684\u5c3e\u8282\u70b9<br \/>\n    unsigned long count;          \/\/ \u6240\u6709\u8282\u70b9\u4e2d listpack \u5b58\u50a8\u7684**\u603b\u5143\u7d20\u6570**&#xff08;\u5feb\u901f\u83b7\u53d6\u5217\u8868\u957f\u5ea6&#xff0c;\u65e0\u9700\u904d\u5386\u8282\u70b9&#xff09;<br \/>\n    unsigned long len;            \/\/ \u53cc\u5411\u94fe\u8868\u4e2d quicklistNode \u7684**\u8282\u70b9\u603b\u6570**<br \/>\n    signed int fill : QL_FILL_BITS;       \/\/ \u4f4d\u57df&#xff08;QL_FILL_BITS \u901a\u5e38\u662f16\u4f4d&#xff09;&#xff1a;\u63a7\u5236\u6bcf\u4e2a\u8282\u70b9\u7684 listpack \u586b\u5145\u56e0\u5b50<br \/>\n                                          \/\/ \u5bf9\u5e94\u914d\u7f6e\u9879 list-max-ziplist-size&#xff0c;\u6bd4\u5982-1&#061;\u6700\u591a4KB&#xff0c;-2&#061;\u6700\u591a8KB&#xff0c;1&#061;\u6700\u591a1\u4e2a\u5143\u7d20\u7b49<br \/>\n    unsigned int compress : QL_COMP_BITS; \/\/ \u4f4d\u57df&#xff08;QL_COMP_BITS \u901a\u5e38\u662f16\u4f4d&#xff09;&#xff1a;\u63a7\u5236\u5217\u8868\u7684\u538b\u7f29\u6df1\u5ea6<br \/>\n                                          \/\/ \u5bf9\u5e94\u914d\u7f6e\u9879 list-compress-depth&#xff0c;0&#061;\u4e0d\u538b\u7f29&#xff0c;1&#061;\u9996\u5c3e\u54041\u4e2a\u8282\u70b9\u4e0d\u538b\u7f29&#xff0c;\u5176\u4f59\u538b\u7f29&#xff0c;\u4ee5\u6b64\u7c7b\u63a8<br \/>\n    unsigned int bookmark_count: QL_BM_BITS; \/\/ \u4f4d\u57df&#xff08;QL_BM_BITS \u901a\u5e38\u662f3\u4f4d&#xff09;&#xff1a;\u4e66\u7b7e\u7684\u6570\u91cf&#xff0c;\u7528\u4e8e\u5feb\u901f\u5b9a\u4f4d\u8282\u70b9<br \/>\n    quicklistBookmark bookmarks[]; \/\/ \u67d4\u6027\u6570\u7ec4&#xff1a;\u5b58\u50a8\u4e66\u7b7e&#xff08;\u4f18\u5316\u5927\u5217\u8868\u7684\u968f\u673a\u8bbf\u95ee\u6027\u80fd&#xff0c;\u907f\u514d\u904d\u5386\u6574\u4e2a\u94fe\u8868&#xff09;<br \/>\n} quicklist;<\/p>\n<p>\/* &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; 2. quicklistNode \u7ed3\u6784\u4f53&#xff08;\u5217\u8868\u7684\u8282\u70b9\u7ed3\u6784&#xff09;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<br \/>\n * \u8bf4\u660e&#xff1a;quicklist \u7684\u6bcf\u4e2a\u8282\u70b9&#xff0c;\u5185\u90e8\u5c01\u88c5\u4e86 listpack&#xff08;\u7d27\u51d1\u5b58\u50a8\u7ed3\u6784&#xff0c;\u66ff\u4ee3\u65e7\u7684 ziplist&#xff09;&#xff0c;<br \/>\n * \u652f\u6301\u538b\u7f29&#xff08;LZF\u7b97\u6cd5&#xff09;&#xff0c;\u517c\u987e\u5185\u5b58\u6548\u7387\u548c\u8bbf\u95ee\u6027\u80fd<br \/>\n *\/<br \/>\ntypedef struct quicklistNode {<br \/>\n    struct quicklistNode *prev;   \/\/ \u6307\u5411\u53cc\u5411\u94fe\u8868\u7684\u524d\u4e00\u4e2a\u8282\u70b9<br \/>\n    struct quicklistNode *next;   \/\/ \u6307\u5411\u53cc\u5411\u94fe\u8868\u7684\u540e\u4e00\u4e2a\u8282\u70b9<br \/>\n    unsigned char *entry;         \/\/ \u6307\u5411\u5b9e\u9645\u5b58\u50a8\u6570\u636e\u7684\u6307\u9488&#xff1a;<br \/>\n                                  \/\/ &#8211; \u672a\u538b\u7f29\u65f6&#xff1a;\u6307\u5411 listpack \u7ed3\u6784<br \/>\n                                  \/\/ &#8211; \u538b\u7f29\u65f6&#xff1a;\u6307\u5411 LZF \u538b\u7f29\u540e\u7684\u6570\u636e<br \/>\n    size_t sz;             \/\/ entry \u6307\u5411\u6570\u636e\u7684**\u603b\u5b57\u8282\u6570**&#xff08;\u65b9\u4fbf\u5185\u5b58\u5206\u914d\/\u91ca\u653e\/\u538b\u7f29\u8ba1\u7b97&#xff09;<br \/>\n    unsigned int count : 16;     \/\/ \u4f4d\u57df&#xff08;16\u4f4d&#xff09;&#xff1a;\u5f53\u524d\u8282\u70b9\u7684 listpack \u4e2d\u5b58\u50a8\u7684**\u5143\u7d20\u4e2a\u6570**&#xff08;\u6700\u592765535\u4e2a&#xff09;<br \/>\n    unsigned int encoding : 2;   \/\/ \u4f4d\u57df&#xff08;2\u4f4d&#xff09;&#xff1a;\u5f53\u524d\u8282\u70b9\u7684\u7f16\u7801\u65b9\u5f0f<br \/>\n                                  \/\/ 1&#061;RAW&#xff08;\u672a\u538b\u7f29&#xff0c;\u76f4\u63a5\u5b58\u50a8 listpack&#xff09;<br \/>\n                                  \/\/ 2&#061;LZF&#xff08;\u7528 LZF \u7b97\u6cd5\u538b\u7f29 listpack&#xff0c;\u8282\u7701\u5185\u5b58&#xff09;<br \/>\n    unsigned int container : 2;  \/\/ \u4f4d\u57df&#xff08;2\u4f4d&#xff09;&#xff1a;\u5f53\u524d\u8282\u70b9\u7684\u6570\u636e\u5bb9\u5668\u7c7b\u578b<br \/>\n                                  \/\/ 1&#061;PLAIN&#xff08;\u65e9\u671f\u7684\u666e\u901a\u5b58\u50a8&#xff0c;\u5df2\u5e9f\u5f03&#xff09;<br \/>\n                                  \/\/ 2&#061;PACKED&#xff08;\u5f53\u524d\u552f\u4e00\u4f7f\u7528\u7684\u7c7b\u578b&#xff0c;\u5373\u4f7f\u7528 listpack \u5b58\u50a8\u6570\u636e&#xff09;<br \/>\n    unsigned int recompress : 1; \/\/ \u4f4d\u57df&#xff08;1\u4f4d&#xff09;&#xff1a;\u6807\u8bb0\u8be5\u8282\u70b9**\u4e4b\u524d\u662f\u5426\u88ab\u538b\u7f29\u8fc7**<br \/>\n                                  \/\/ \u5f53\u9700\u8981\u8bbf\u95ee\u538b\u7f29\u8282\u70b9\u65f6&#xff0c;\u4f1a\u4e34\u65f6\u89e3\u538b&#xff0c;\u8bbf\u95ee\u5b8c\u6210\u540e\u9700\u8981\u91cd\u65b0\u538b\u7f29<br \/>\n    unsigned int attempted_compress : 1; \/\/ \u4f4d\u57df&#xff08;1\u4f4d&#xff09;&#xff1a;\u6807\u8bb0\u8be5\u8282\u70b9**\u5c1d\u8bd5\u8fc7\u538b\u7f29\u4f46\u5931\u8d25**<br \/>\n                                  \/\/ \u539f\u56e0\u662f\u8282\u70b9\u6570\u636e\u592a\u5c0f&#xff0c;\u538b\u7f29\u540e\u53cd\u800c\u4f1a\u589e\u52a0\u5185\u5b58\u5f00\u9500<br \/>\n    unsigned int extra : 10; \/\/ \u4f4d\u57df&#xff08;10\u4f4d&#xff09;&#xff1a;\u9884\u7559\u4f4d&#xff0c;\u7528\u4e8e\u672a\u6765\u6269\u5c55\u529f\u80fd&#xff08;Redis \u9884\u7559\u4f4d\u7684\u5e38\u89c4\u64cd\u4f5c&#xff09;<br \/>\n} quicklistNode;<\/p>\n<p>&#xff08;quicklist.h)\u3002\u6bcf\u4e2a quicklistNode \u5185\u90e8\u5305\u542b\u4e00\u4e2a ziplist&#xff0c;\u7528\u4e8e\u5b58\u50a8\u5b9e\u9645\u6570\u636e&#xff0c;\u8fd9\u5c31\u662f \u201c\u95f4\u63a5\u4f7f\u7528 ziplist\u201d \u7684\u542b\u4e49\u3002<\/p>\n<\/p>\n<h3 style=\"background-color:transparent\">4. \u96c6\u5408&#xff08;intset \u2192 dict&#xff09;<\/h3>\n<ul>\n<li>intset&#xff08;\u6574\u6570\u96c6\u5408&#xff09;&#xff1a;\n<ul>\n<li>\u5185\u5b58\u4e0a&#xff1a;\u8fde\u7eed\u5b58\u50a8\u6574\u6570&#xff0c;\u65e0\u4efb\u4f55\u5197\u4f59&#xff08;\u6bd4\u5982\u5b58\u50a8 1,2,3 \u53ea\u5360 3\u00d78&#061;24 \u5b57\u8282&#xff09;&#xff0c;\u800c dict \u5b58\u50a8\u540c\u6837\u6570\u636e\u9700\u8981\u54c8\u5e0c\u8868 &#043; \u6307\u9488&#xff0c;\u81f3\u5c11\u5360\u4e0a\u767e\u5b57\u8282&#xff1b;<\/li>\n<li>\u9650\u5236&#xff1a;\u53ea\u80fd\u5b58\u6574\u6570&#xff0c;\u4e14\u589e\u5220\u9700\u8981\u91cd\u6392\u5185\u5b58&#xff1b;<\/li>\n<\/ul>\n<\/li>\n<li>dict&#xff1a;\n<ul>\n<li>\u5185\u5b58\u4e0a&#xff1a;\u6709\u54c8\u5e0c\u8868\u5f00\u9500&#xff0c;\u4f46\u652f\u6301\u4efb\u610f\u5b57\u7b26\u4e32\u5143\u7d20&#xff1b;<\/li>\n<li>\u6027\u80fd\u4e0a&#xff1a;\u589e\u5220\u67e5 O (1)&#xff0c;\u65e0\u7c7b\u578b\u9650\u5236\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u8bbe\u8ba1\u76ee\u7684&#xff1a;\u7eaf\u6574\u6570\u5c0f\u96c6\u5408\u7528 intset \u7701\u5185\u5b58&#xff0c;\u975e\u6574\u6570 \/ \u5927\u96c6\u5408\u7528 dict \u4fdd\u8bc1\u901a\u7528\u6027\u548c\u6027\u80fd&#xff08;\u6bd4\u5982\u7528\u6237\u6807\u7b7e\u96c6\u5408&#xff0c;\u53ef\u80fd\u5b58\u5b57\u7b26\u4e32\u6807\u7b7e&#xff0c;\u53ea\u80fd\u7528 dict&#xff09;\u3002<\/p>\n<\/p>\n<h3 style=\"background-color:transparent\">5. \u6709\u5e8f\u96c6\u5408<\/h3>\n<ul>\n<li>ziplist&#xff08;\u538b\u7f29\u5217\u8868&#xff09;&#xff1a;\n<ul>\n<li>\u5185\u5b58\u4e0a&#xff1a;\u6240\u6709\u952e\u503c\u5bf9 \/ \u5143\u7d20\u8fde\u7eed\u5b58\u50a8&#xff0c;\u65e0\u5197\u4f59\u6307\u9488&#xff08;dict \u6bcf\u4e2a\u952e\u503c\u5bf9\u8981\u5b58\u4e24\u4e2a\u6307\u9488&#xff0c;skiplist \u6bcf\u4e2a\u8282\u70b9\u6709\u591a\u5c42\u6307\u9488&#xff09;&#xff0c;\u5185\u5b58\u5bc6\u5ea6\u662f dict \u7684 1\/5 \u4ee5\u4e0a&#xff1b;<\/li>\n<li>\u6027\u80fd\u4e0a&#xff1a;\u589e\u5220\u6539\u9700\u8981\u91cd\u6392\u6574\u4e2a\u5217\u8868&#xff08;O (n)&#xff09;&#xff0c;\u4f46\u6570\u636e\u91cf\u5c0f&#xff08;\u2264512\/128 \u4e2a\u5143\u7d20&#xff09;\u65f6&#xff0c;n \u5f88\u5c0f&#xff0c;\u6027\u80fd\u635f\u8017\u53ef\u5ffd\u7565&#xff1b;<\/li>\n<\/ul>\n<\/li>\n<li>skiplist&#xff1a;\n<ul>\n<li>\u5185\u5b58\u4e0a&#xff1a;skiplist \u6709\u591a\u5c42\u6307\u9488\u5f00\u9500&#xff0c;\u5185\u5b58\u5360\u7528\u662f ziplist \u7684\u6570\u500d&#xff1b;<\/li>\n<li>\u6027\u80fd\u4e0a&#xff1a;skiplist \u67e5\u6539 O (logN)&#xff0c;\u6570\u636e\u91cf\u5927\u65f6\u8fdc\u5feb\u4e8e ziplist \u7684 O (n)\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u8bbe\u8ba1\u76ee\u7684\u00a0\u5c0f\u6709\u5e8f\u96c6\u5408\u7528 ziplist \u7701\u5185\u5b58 \u5927\u6709\u5e8f\u96c6\u5408\u7528 skiplist \u4fdd\u8bc1\u8bfb\u5199\u6027\u80fd&#xff08;\u6bd4\u5982\u7535\u5546\u573a\u666f\u7684\u5546\u54c1\u6392\u884c\u699c zset&#xff0c;\u6570\u636e\u91cf\u53d8\u5927\u540e&#xff0c;skiplist \u7684\u6392\u5e8f\u6548\u7387\u8fdc\u9ad8\u4e8e ziplist&#xff09;<\/p>\n<\/p>\n<p>\/* \u5411\u6709\u5e8f\u96c6\u5408\u4e2d\u6dfb\u52a0\/\u66f4\u65b0\u5143\u7d20&#xff08;\u6838\u5fc3\u51fd\u6570&#xff09;<br \/>\n * \u53c2\u6570\u8bf4\u660e&#xff1a;<br \/>\n *   zobj: \u76ee\u6807\u6709\u5e8f\u96c6\u5408\u5bf9\u8c61&#xff08;robj \u7c7b\u578b&#xff09;<br \/>\n *   score: \u5143\u7d20\u7684\u5206\u6570&#xff08;double \u7c7b\u578b&#xff09;<br \/>\n *   ele: \u5143\u7d20\u503c&#xff08;SDS \u5b57\u7b26\u4e32&#xff09;<br \/>\n *   in_flags: \u8f93\u5165\u63a7\u5236\u6807\u5fd7&#xff08;\u5982 ZADD_IN_INCR\/XX\/NX\/GT\/LT \u7b49&#xff09;<br \/>\n *   out_flags: \u8f93\u51fa\u6807\u5fd7&#xff08;\u8fd4\u56de\u64cd\u4f5c\u7ed3\u679c&#xff0c;\u5982\u662f\u5426\u65b0\u589e\/\u66f4\u65b0\/NaN \u7b49&#xff09;<br \/>\n *   newscore: \u8f93\u51fa\u53c2\u6570&#xff0c;\u8fd4\u56de\u66f4\u65b0\u540e\u7684\u5206\u6570&#xff08;NULL \u5219\u4e0d\u8fd4\u56de&#xff09;<br \/>\n * \u8fd4\u56de\u503c&#xff1a;1 \u8868\u793a\u64cd\u4f5c\u6210\u529f&#xff08;\u65b0\u589e\/\u66f4\u65b0&#xff09;&#xff0c;0 \u8868\u793a\u5931\u8d25&#xff08;\u5982 NaN \u8f93\u5165&#xff09;<br \/>\n *\/<br \/>\nint zsetAdd(robj *zobj, double score, sds ele, int in_flags, int *out_flags, double *newscore) {<br \/>\n    \/* \u5c06\u8f93\u5165\u6807\u5fd7\u89e3\u6790\u4e3a\u6613\u68c0\u67e5\u7684\u53d8\u91cf *\/<br \/>\n    int incr &#061; (in_flags &amp; ZADD_IN_INCR) !&#061; 0; \/\/ \u662f\u5426\u662f\u589e\u91cf\u66f4\u65b0&#xff08;\u5bf9\u5e94 ZINCRBY \u6216 ZADD INCR&#xff09;<br \/>\n    int nx &#061; (in_flags &amp; ZADD_IN_NX) !&#061; 0;     \/\/ \u4ec5\u5f53\u5143\u7d20\u4e0d\u5b58\u5728\u65f6\u6dfb\u52a0&#xff08;ZADD NX&#xff09;<br \/>\n    int xx &#061; (in_flags &amp; ZADD_IN_XX) !&#061; 0;     \/\/ \u4ec5\u5f53\u5143\u7d20\u5b58\u5728\u65f6\u66f4\u65b0&#xff08;ZADD XX&#xff09;<br \/>\n    int gt &#061; (in_flags &amp; ZADD_IN_GT) !&#061; 0;     \/\/ \u4ec5\u5f53\u65b0\u5206\u6570 &gt; \u65e7\u5206\u6570\u65f6\u66f4\u65b0&#xff08;ZADD GT&#xff09;<br \/>\n    int lt &#061; (in_flags &amp; ZADD_IN_LT) !&#061; 0;     \/\/ \u4ec5\u5f53\u65b0\u5206\u6570 &lt; \u65e7\u5206\u6570\u65f6\u66f4\u65b0&#xff08;ZADD LT&#xff09;<br \/>\n    *out_flags &#061; 0; \/* \u521d\u59cb\u5316\u8f93\u51fa\u6807\u5fd7 *\/<br \/>\n    double curscore; \/\/ \u5b58\u50a8\u5143\u7d20\u5f53\u524d\u7684\u5206\u6570&#xff08;\u82e5\u5b58\u5728&#xff09;<\/p>\n<p>    \/* \u8f93\u5165\u5206\u6570\u662f NaN \u76f4\u63a5\u8fd4\u56de\u9519\u8bef&#xff08;NaN \u65e0\u6cd5\u6bd4\u8f83&#xff0c;\u4e0d\u80fd\u4f5c\u4e3a\u6709\u5e8f\u96c6\u5408\u5206\u6570&#xff09; *\/<br \/>\n    if (isnan(score)) {<br \/>\n        *out_flags &#061; ZADD_OUT_NAN; \/\/ \u6807\u8bb0\u8f93\u51fa\u4e3a NaN \u9519\u8bef<br \/>\n        return 0;<br \/>\n    }<\/p>\n<p>    \/* \u5206\u652f1&#xff1a;\u6709\u5e8f\u96c6\u5408\u5f53\u524d\u662f LISTPACK \u7f16\u7801&#xff08;\u7d27\u51d1\u5b58\u50a8&#xff0c;\u66ff\u4ee3\u65e7\u7684 ziplist&#xff09; *\/<br \/>\n    if (zobj-&gt;encoding &#061;&#061; OBJ_ENCODING_LISTPACK) {<br \/>\n        unsigned char *eptr; \/\/ \u6307\u5411 listpack \u4e2d\u5143\u7d20\u7684\u6307\u9488<\/p>\n<p>        \/* \u67e5\u627e\u5143\u7d20&#xff1a;\u5b58\u5728\u5219\u8fd4\u56de\u5143\u7d20\u6307\u9488\u5e76\u586b\u5145 curscore&#xff0c;\u4e0d\u5b58\u5728\u5219\u8fd4\u56de NULL *\/<br \/>\n        if ((eptr &#061; zzlFind(zobj-&gt;ptr,ele,&amp;curscore)) !&#061; NULL) {<br \/>\n            \/* NX \u6a21\u5f0f&#xff1a;\u5143\u7d20\u5df2\u5b58\u5728&#xff0c;\u76f4\u63a5\u8fd4\u56de&#xff08;\u6807\u8bb0\u4e3a\u201c\u65e0\u64cd\u4f5c\u201d&#xff09; *\/<br \/>\n            if (nx) {<br \/>\n                *out_flags |&#061; ZADD_OUT_NOP;<br \/>\n                return 1;<br \/>\n            }<\/p>\n<p>            \/* INCR \u6a21\u5f0f&#xff1a;\u8ba1\u7b97\u589e\u91cf\u540e\u7684\u65b0\u5206\u6570&#xff08;score &#061; \u65e7\u5206\u6570 &#043; \u8f93\u5165\u589e\u91cf&#xff09; *\/<br \/>\n            if (incr) {<br \/>\n                score &#043;&#061; curscore;<br \/>\n                if (isnan(score)) { \/\/ \u589e\u91cf\u540e\u51fa\u73b0 NaN&#xff0c;\u8fd4\u56de\u9519\u8bef<br \/>\n                    *out_flags |&#061; ZADD_OUT_NAN;<br \/>\n                    return 0;<br \/>\n                }<br \/>\n            }<\/p>\n<p>            \/* GT\/LT \u6a21\u5f0f&#xff1a;\u4ec5\u5f53\u65b0\u5206\u6570\u6ee1\u8db3\u6761\u4ef6\u65f6\u66f4\u65b0 *\/<br \/>\n            if ((lt &amp;&amp; score &gt;&#061; curscore) || (gt &amp;&amp; score &lt;&#061; curscore)) {<br \/>\n                *out_flags |&#061; ZADD_OUT_NOP; \/\/ \u4e0d\u6ee1\u8db3\u6761\u4ef6&#xff0c;\u6807\u8bb0\u65e0\u64cd\u4f5c<br \/>\n                return 1;<br \/>\n            }<\/p>\n<p>            \/* \u82e5\u9700\u8981\u8fd4\u56de\u65b0\u5206\u6570&#xff0c;\u586b\u5145 newscore *\/<br \/>\n            if (newscore) *newscore &#061; score;<\/p>\n<p>            \/* \u5206\u6570\u53d8\u5316\u65f6&#xff1a;\u5148\u5220\u9664\u65e7\u5143\u7d20&#xff0c;\u518d\u63d2\u5165\u65b0\u5206\u6570\u7684\u5143\u7d20&#xff08;listpack \u662f\u6709\u5e8f\u7ed3\u6784&#xff0c;\u9700\u91cd\u6392&#xff09; *\/<br \/>\n            if (score !&#061; curscore) {<br \/>\n                zobj-&gt;ptr &#061; zzlDelete(zobj-&gt;ptr,eptr); \/\/ \u5220\u9664\u65e7\u5143\u7d20<br \/>\n                zobj-&gt;ptr &#061; zzlInsert(zobj-&gt;ptr,ele,score); \/\/ \u63d2\u5165\u65b0\u5206\u6570\u7684\u5143\u7d20<br \/>\n                *out_flags |&#061; ZADD_OUT_UPDATED; \/\/ \u6807\u8bb0\u4e3a\u201c\u66f4\u65b0\u64cd\u4f5c\u201d<br \/>\n            }<br \/>\n            return 1;<br \/>\n        } else if (!xx) { \/\/ \u5143\u7d20\u4e0d\u5b58\u5728&#xff0c;\u4e14\u4e0d\u662f XX \u6a21\u5f0f&#xff08;\u6267\u884c\u65b0\u589e\u903b\u8f91&#xff09;<br \/>\n            \/* \u65b0\u589e\u524d\u68c0\u67e5&#xff1a;\u662f\u5426\u9700\u8981\u4ece LISTPACK \u8f6c\u4e3a SKIPLIST<br \/>\n             * \u89e6\u53d1\u6761\u4ef6&#xff1a;<br \/>\n             * 1. \u5143\u7d20\u6570&#043;1 \u8d85\u8fc7 zset_max_listpack_entries&#xff08;\u9ed8\u8ba4128&#xff09;<br \/>\n             * 2. \u5143\u7d20\u957f\u5ea6\u8d85\u8fc7 zset_max_listpack_value&#xff08;\u9ed8\u8ba464&#xff09;<br \/>\n             * 3. listpack \u5269\u4f59\u7a7a\u95f4\u4e0d\u8db3\u4ee5\u6dfb\u52a0\u65b0\u5143\u7d20<br \/>\n             *\/<br \/>\n            if (zzlLength(zobj-&gt;ptr)&#043;1 &gt; server.zset_max_listpack_entries ||<br \/>\n                sdslen(ele) &gt; server.zset_max_listpack_value ||<br \/>\n                !lpSafeToAdd(zobj-&gt;ptr, sdslen(ele)))<br \/>\n            {<br \/>\n                zsetConvert(zobj,OBJ_ENCODING_SKIPLIST); \/\/ \u8f6c\u6362\u4e3a SKIPLIST \u7f16\u7801<br \/>\n            } else {<br \/>\n                \/\/ \u65e0\u9700\u8f6c\u6362&#xff0c;\u76f4\u63a5\u63d2\u5165\u65b0\u5143\u7d20\u5230 listpack<br \/>\n                zobj-&gt;ptr &#061; zzlInsert(zobj-&gt;ptr,ele,score);<br \/>\n                if (newscore) *newscore &#061; score;<br \/>\n                *out_flags |&#061; ZADD_OUT_ADDED; \/\/ \u6807\u8bb0\u4e3a\u201c\u65b0\u589e\u64cd\u4f5c\u201d<br \/>\n                return 1;<br \/>\n            }<br \/>\n        } else { \/\/ \u5143\u7d20\u4e0d\u5b58\u5728&#xff0c;\u4f46\u662f XX \u6a21\u5f0f&#xff08;\u4ec5\u66f4\u65b0\u5df2\u5b58\u5728\u5143\u7d20&#xff09;<br \/>\n            *out_flags |&#061; ZADD_OUT_NOP; \/\/ \u6807\u8bb0\u65e0\u64cd\u4f5c<br \/>\n            return 1;<br \/>\n        }<br \/>\n    }<\/p>\n<p>    \/* \u6ce8&#xff1a;\u4e0a\u9762\u7684 listpack \u5206\u652f\u8981\u4e48\u5df2\u8fd4\u56de&#xff0c;\u8981\u4e48\u5df2\u5c06\u5bf9\u8c61\u8f6c\u4e3a skiplist \u7f16\u7801 *\/<br \/>\n    \/* \u5206\u652f2&#xff1a;\u6709\u5e8f\u96c6\u5408\u5f53\u524d\u662f SKIPLIST \u7f16\u7801&#xff08;\u9ad8\u6548\u5b58\u50a8&#xff0c;\u5305\u542b dict &#043; skiplist&#xff09; *\/<br \/>\n    if (zobj-&gt;encoding &#061;&#061; OBJ_ENCODING_SKIPLIST) {<br \/>\n        zset *zs &#061; zobj-&gt;ptr; \/\/ zset \u7ed3\u6784\u4f53&#xff08;\u5305\u542b dict &#043; skiplist&#xff09;<br \/>\n        zskiplistNode *znode; \/\/ \u8df3\u8868\u8282\u70b9\u6307\u9488<br \/>\n        dictEntry *de;        \/\/ \u54c8\u5e0c\u8868\u6761\u76ee\u6307\u9488<\/p>\n<p>        \/* \u5728 dict \u4e2d\u67e5\u627e\u5143\u7d20&#xff08;dict \u7528\u4e8e\u5feb\u901f\u5b9a\u4f4d\u5143\u7d20\u662f\u5426\u5b58\u5728&#xff09; *\/<br \/>\n        de &#061; dictFind(zs-&gt;dict,ele);<br \/>\n        if (de !&#061; NULL) { \/\/ \u5143\u7d20\u5b58\u5728&#xff0c;\u6267\u884c\u66f4\u65b0\u903b\u8f91<br \/>\n            \/* NX \u6a21\u5f0f&#xff1a;\u5143\u7d20\u5df2\u5b58\u5728&#xff0c;\u8fd4\u56de\u65e0\u64cd\u4f5c *\/<br \/>\n            if (nx) {<br \/>\n                *out_flags |&#061; ZADD_OUT_NOP;<br \/>\n                return 1;<br \/>\n            }<\/p>\n<p>            curscore &#061; *(double*)dictGetVal(de); \/\/ \u83b7\u53d6\u5f53\u524d\u5206\u6570&#xff08;dict \u4e2d\u5b58\u7684\u662f\u5206\u6570\u6307\u9488&#xff09;<\/p>\n<p>            \/* INCR \u6a21\u5f0f&#xff1a;\u8ba1\u7b97\u589e\u91cf\u540e\u7684\u65b0\u5206\u6570 *\/<br \/>\n            if (incr) {<br \/>\n                score &#043;&#061; curscore;<br \/>\n                if (isnan(score)) {<br \/>\n                    *out_flags |&#061; ZADD_OUT_NAN;<br \/>\n                    return 0;<br \/>\n                }<br \/>\n            }<\/p>\n<p>            \/* GT\/LT \u6a21\u5f0f&#xff1a;\u68c0\u67e5\u5206\u6570\u6761\u4ef6 *\/<br \/>\n            if ((lt &amp;&amp; score &gt;&#061; curscore) || (gt &amp;&amp; score &lt;&#061; curscore)) {<br \/>\n                *out_flags |&#061; ZADD_OUT_NOP;<br \/>\n                return 1;<br \/>\n            }<\/p>\n<p>            \/* \u586b\u5145\u65b0\u5206\u6570&#xff08;\u82e5\u9700\u8981\u8fd4\u56de&#xff09; *\/<br \/>\n            if (newscore) *newscore &#061; score;<\/p>\n<p>            \/* \u5206\u6570\u53d8\u5316\u65f6&#xff1a;\u66f4\u65b0\u8df3\u8868\u4e2d\u7684\u5206\u6570 *\/<br \/>\n            if (score !&#061; curscore) {<br \/>\n                \/\/ \u66f4\u65b0\u8df3\u8868\u8282\u70b9\u7684\u5206\u6570&#xff08;\u5185\u90e8\u4f1a\u5220\u9664\u65e7\u8282\u70b9&#043;\u63d2\u5165\u65b0\u8282\u70b9&#xff09;<br \/>\n                znode &#061; zslUpdateScore(zs-&gt;zsl,curscore,ele,score);<br \/>\n                \/* \u6ce8&#xff1a;dict \u4e2d\u65e0\u9700\u5220\u9664\u65e7\u6761\u76ee&#xff0c;\u4ec5\u66f4\u65b0\u5206\u6570\u6307\u9488\u5373\u53ef *\/<br \/>\n                dictGetVal(de) &#061; &amp;znode-&gt;score; \/\/ \u66f4\u65b0 dict \u4e2d\u7684\u5206\u6570\u6307\u9488<br \/>\n                *out_flags |&#061; ZADD_OUT_UPDATED; \/\/ \u6807\u8bb0\u4e3a\u66f4\u65b0<br \/>\n            }<br \/>\n            return 1;<br \/>\n        } else if (!xx) { \/\/ \u5143\u7d20\u4e0d\u5b58\u5728&#xff0c;\u4e14\u4e0d\u662f XX \u6a21\u5f0f&#xff08;\u6267\u884c\u65b0\u589e\u903b\u8f91&#xff09;<br \/>\n            ele &#061; sdsdup(ele); \/\/ \u590d\u5236\u5143\u7d20&#xff08;\u63a5\u7ba1\u5185\u5b58\u6240\u6709\u6743&#xff09;<br \/>\n            znode &#061; zslInsert(zs-&gt;zsl,score,ele); \/\/ \u63d2\u5165\u8df3\u8868<br \/>\n            \/\/ \u5c06\u5143\u7d20\u548c\u5206\u6570\u6307\u9488\u52a0\u5165 dict&#xff08;\u4fdd\u8bc1 O(1) \u67e5\u627e&#xff09;<br \/>\n            serverAssert(dictAdd(zs-&gt;dict,ele,&amp;znode-&gt;score) &#061;&#061; DICT_OK);<br \/>\n            *out_flags |&#061; ZADD_OUT_ADDED; \/\/ \u6807\u8bb0\u4e3a\u65b0\u589e<br \/>\n            if (newscore) *newscore &#061; score;<br \/>\n            return 1;<br \/>\n        } else { \/\/ \u5143\u7d20\u4e0d\u5b58\u5728&#xff0c;\u4f46\u662f XX \u6a21\u5f0f<br \/>\n            *out_flags |&#061; ZADD_OUT_NOP;<br \/>\n            return 1;<br \/>\n        }<br \/>\n    } else {<br \/>\n        \/\/ \u672a\u77e5\u7f16\u7801&#xff0c;\u76f4\u63a5\u5d29\u6e83&#xff08;\u9632\u5fa1\u6027\u7f16\u7a0b&#xff09;<br \/>\n        serverPanic(&#034;Unknown sorted set encoding&#034;);<br \/>\n    }<br \/>\n    return 0; \/* \u6c38\u8fdc\u4e0d\u4f1a\u6267\u884c\u5230\u8fd9\u91cc&#xff08;\u4e0a\u9762\u5206\u652f\u5df2\u8986\u76d6\u6240\u6709\u60c5\u51b5&#xff09; *\/<br \/>\n}<\/p>\n<p>&#xff08;t_zet.c)<\/p>\n<\/p>\n<h3>6. \u603b\u7ed3&#xff1a;<\/h3>\n<p>\u8df3\u8868redis\u9009\u62e9\u91c7\u752832\u5c42&#xff0c;\u517c\u987e\u5185\u5b58\u5360\u7528\u548c\u67e5\u627e\u6548\u7387\u7684\u7efc\u5408\u8003\u91cf\u3002<\/p>\n<table>\n<tr>\u6570\u636e\u7c7b\u578b\u7f16\u7801\u8f6c\u6362\u903b\u8f91\u6838\u5fc3\u914d\u7f6e\u5b8f\u5b9a\u4e49\u8f6c\u6362\u89e6\u53d1\u51fd\u6570\u4e3b\u8981\u5b9e\u73b0\u6587\u4ef6<\/tr>\n<tbody>\n<tr>\n<td>zset<\/td>\n<td>ziplist \u2194 skiplist<\/td>\n<td>zset_max_ziplist_entries, zset_max_ziplist_value<\/td>\n<td>zsetConvert<\/td>\n<td>t_zset.c<\/td>\n<\/tr>\n<tr>\n<td>set<\/td>\n<td>intset \u2194 dict<\/td>\n<td>set_max_intset_entries<\/td>\n<td>setTypeConvert<\/td>\n<td>t_set.c<\/td>\n<\/tr>\n<tr>\n<td>hash<\/td>\n<td>ziplist \u2194 dict<\/td>\n<td>hash_max_ziplist_entries, hash_max_ziplist_value<\/td>\n<td>hashTypeConvert<\/td>\n<td>t_hash.c<\/td>\n<\/tr>\n<tr>\n<td>list<\/td>\n<td>quicklist&#xff08;\u5185\u90e8 ziplist&#xff09;<\/td>\n<td>list-max-ziplist-size<\/td>\n<td>\u5185\u90e8\u81ea\u52a8\u7ba1\u7406<\/td>\n<td>quicklist.c, t_list.c<\/td>\n<\/tr>\n<tr>\n<td>string<\/td>\n<td>int \u2194 embstr \u2194 raw<\/td>\n<td>OBJ_ENCODING_EMBSTR_SIZE_LIMIT (44)<\/td>\n<td>tryObjectEncoding<\/td>\n<td>object.c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u56db\u3001io \u591a\u8fdb\u7a0b\u7684\u5de5\u4f5c\u539f\u7406<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"820\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260726101807-6a65dedf3fde9.png\" width=\"838\" \/><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6ce8&#xff1a;\u8be5\u6587\u7528\u4e8e\u4e2a\u4eba\u5b66\u4e60\u8bb0\u5f55\u548c\u77e5\u8bc6\u4ea4\u6d41&#xff0c;\u5982\u6709\u4e0d\u8db3&#xff0c;\u6b22\u8fce\u6307\u70b9\u3002\u4e00\u3001\u7ebf\u7a0b\u6570\u76ee\u64cd\u4f5c\u6570\u636e\u7ed3\u6784\u7684\u8bed\u53e5&#xff08;\u5373\u6267\u884c\u6307\u4ee4&#xff09;\u662f\u4e3b\u7ebf\u7a0b&#xff08;\u5355\u7ebf\u7a0b&#xff0c;\u5929\u7136\u5177\u5907\u9694\u79bb\u6027\u3001\u4e0d\u9700\u8981\u52a0\u9501&#xff09;\u522b\u7684\u7ebf\u7a0b\u4e3b\u8981\u7528\u4e8e\u4f18\u5316&#xff1a;\u907f\u514dIO\u5bc6\u96c6\u578b\u548cCPU\u5bc6\u96c6\u578b\u8fc7\u591a\u5360\u7528\u4e3b\u7ebf\u7a0b\u4e8c\u3001IO\u5bc6\u96c6\u578b\u5c42\u9762\u7684\u4f18\u53161. \u78c1\u76d8IOrdb&#xff1a;\u901a\u8fc7fork\u5b50\u8fdb\u7a0b\u6765\u6301\u4e45\u5316aof&#xff1a;\u6709\u5f02\u6b65\u5237\u76d8\u673a\u5236&#xff08;\u53ef\u9009&amp;<\/p>\n","protected":false},"author":2,"featured_media":84807,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[105,371,100],"topic":[],"class_list":["post-84815","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-redis","tag-371","tag-100"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linux C\/C++ \u5b66\u4e60\u65e5\u8bb0\uff0865\uff09\uff1aRedis\uff08\u516d\uff09\uff1a\u8bba\u201d\u5355\u7ebf\u7a0b\u201c\u670d\u52a1\u5668\u662f\u5982\u4f55\u5b9e\u73b0\u9ad8\u6027\u80fd\u7684\uff0c\u542b\u90e8\u5206\u6e90\u7801\u5256\u6790 - \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\/84815.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux C\/C++ \u5b66\u4e60\u65e5\u8bb0\uff0865\uff09\uff1aRedis\uff08\u516d\uff09\uff1a\u8bba\u201d\u5355\u7ebf\u7a0b\u201c\u670d\u52a1\u5668\u662f\u5982\u4f55\u5b9e\u73b0\u9ad8\u6027\u80fd\u7684\uff0c\u542b\u90e8\u5206\u6e90\u7801\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6ce8&#xff1a;\u8be5\u6587\u7528\u4e8e\u4e2a\u4eba\u5b66\u4e60\u8bb0\u5f55\u548c\u77e5\u8bc6\u4ea4\u6d41&#xff0c;\u5982\u6709\u4e0d\u8db3&#xff0c;\u6b22\u8fce\u6307\u70b9\u3002\u4e00\u3001\u7ebf\u7a0b\u6570\u76ee\u64cd\u4f5c\u6570\u636e\u7ed3\u6784\u7684\u8bed\u53e5&#xff08;\u5373\u6267\u884c\u6307\u4ee4&#xff09;\u662f\u4e3b\u7ebf\u7a0b&#xff08;\u5355\u7ebf\u7a0b&#xff0c;\u5929\u7136\u5177\u5907\u9694\u79bb\u6027\u3001\u4e0d\u9700\u8981\u52a0\u9501&#xff09;\u522b\u7684\u7ebf\u7a0b\u4e3b\u8981\u7528\u4e8e\u4f18\u5316&#xff1a;\u907f\u514dIO\u5bc6\u96c6\u578b\u548cCPU\u5bc6\u96c6\u578b\u8fc7\u591a\u5360\u7528\u4e3b\u7ebf\u7a0b\u4e8c\u3001IO\u5bc6\u96c6\u578b\u5c42\u9762\u7684\u4f18\u53161. \u78c1\u76d8IOrdb&#xff1a;\u901a\u8fc7fork\u5b50\u8fdb\u7a0b\u6765\u6301\u4e45\u5316aof&#xff1a;\u6709\u5f02\u6b65\u5237\u76d8\u673a\u5236&#xff08;\u53ef\u9009&amp;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/84815.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-26T10:18:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260726101806-6a65dede5b436.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=\"11 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/84815.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/84815.html\",\"name\":\"Linux C\/C++ \u5b66\u4e60\u65e5\u8bb0\uff0865\uff09\uff1aRedis\uff08\u516d\uff09\uff1a\u8bba\u201d\u5355\u7ebf\u7a0b\u201c\u670d\u52a1\u5668\u662f\u5982\u4f55\u5b9e\u73b0\u9ad8\u6027\u80fd\u7684\uff0c\u542b\u90e8\u5206\u6e90\u7801\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-07-26T10:18:08+00:00\",\"dateModified\":\"2026-07-26T10:18:08+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/84815.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/84815.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/84815.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux C\/C++ \u5b66\u4e60\u65e5\u8bb0\uff0865\uff09\uff1aRedis\uff08\u516d\uff09\uff1a\u8bba\u201d\u5355\u7ebf\u7a0b\u201c\u670d\u52a1\u5668\u662f\u5982\u4f55\u5b9e\u73b0\u9ad8\u6027\u80fd\u7684\uff0c\u542b\u90e8\u5206\u6e90\u7801\u5256\u6790\"}]},{\"@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":"Linux C\/C++ \u5b66\u4e60\u65e5\u8bb0\uff0865\uff09\uff1aRedis\uff08\u516d\uff09\uff1a\u8bba\u201d\u5355\u7ebf\u7a0b\u201c\u670d\u52a1\u5668\u662f\u5982\u4f55\u5b9e\u73b0\u9ad8\u6027\u80fd\u7684\uff0c\u542b\u90e8\u5206\u6e90\u7801\u5256\u6790 - \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\/84815.html","og_locale":"zh_CN","og_type":"article","og_title":"Linux C\/C++ \u5b66\u4e60\u65e5\u8bb0\uff0865\uff09\uff1aRedis\uff08\u516d\uff09\uff1a\u8bba\u201d\u5355\u7ebf\u7a0b\u201c\u670d\u52a1\u5668\u662f\u5982\u4f55\u5b9e\u73b0\u9ad8\u6027\u80fd\u7684\uff0c\u542b\u90e8\u5206\u6e90\u7801\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6ce8&#xff1a;\u8be5\u6587\u7528\u4e8e\u4e2a\u4eba\u5b66\u4e60\u8bb0\u5f55\u548c\u77e5\u8bc6\u4ea4\u6d41&#xff0c;\u5982\u6709\u4e0d\u8db3&#xff0c;\u6b22\u8fce\u6307\u70b9\u3002\u4e00\u3001\u7ebf\u7a0b\u6570\u76ee\u64cd\u4f5c\u6570\u636e\u7ed3\u6784\u7684\u8bed\u53e5&#xff08;\u5373\u6267\u884c\u6307\u4ee4&#xff09;\u662f\u4e3b\u7ebf\u7a0b&#xff08;\u5355\u7ebf\u7a0b&#xff0c;\u5929\u7136\u5177\u5907\u9694\u79bb\u6027\u3001\u4e0d\u9700\u8981\u52a0\u9501&#xff09;\u522b\u7684\u7ebf\u7a0b\u4e3b\u8981\u7528\u4e8e\u4f18\u5316&#xff1a;\u907f\u514dIO\u5bc6\u96c6\u578b\u548cCPU\u5bc6\u96c6\u578b\u8fc7\u591a\u5360\u7528\u4e3b\u7ebf\u7a0b\u4e8c\u3001IO\u5bc6\u96c6\u578b\u5c42\u9762\u7684\u4f18\u53161. \u78c1\u76d8IOrdb&#xff1a;\u901a\u8fc7fork\u5b50\u8fdb\u7a0b\u6765\u6301\u4e45\u5316aof&#xff1a;\u6709\u5f02\u6b65\u5237\u76d8\u673a\u5236&#xff08;\u53ef\u9009&amp;","og_url":"https:\/\/www.wsisp.com\/helps\/84815.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-07-26T10:18:08+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260726101806-6a65dede5b436.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"11 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/84815.html","url":"https:\/\/www.wsisp.com\/helps\/84815.html","name":"Linux C\/C++ \u5b66\u4e60\u65e5\u8bb0\uff0865\uff09\uff1aRedis\uff08\u516d\uff09\uff1a\u8bba\u201d\u5355\u7ebf\u7a0b\u201c\u670d\u52a1\u5668\u662f\u5982\u4f55\u5b9e\u73b0\u9ad8\u6027\u80fd\u7684\uff0c\u542b\u90e8\u5206\u6e90\u7801\u5256\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-07-26T10:18:08+00:00","dateModified":"2026-07-26T10:18:08+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/84815.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/84815.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/84815.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Linux C\/C++ \u5b66\u4e60\u65e5\u8bb0\uff0865\uff09\uff1aRedis\uff08\u516d\uff09\uff1a\u8bba\u201d\u5355\u7ebf\u7a0b\u201c\u670d\u52a1\u5668\u662f\u5982\u4f55\u5b9e\u73b0\u9ad8\u6027\u80fd\u7684\uff0c\u542b\u90e8\u5206\u6e90\u7801\u5256\u6790"}]},{"@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\/84815","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=84815"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/84815\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/84807"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=84815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=84815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=84815"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=84815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}