{"id":10007060,"date":"2023-01-10T12:25:10","date_gmt":"2023-01-10T04:25:10","guid":{"rendered":"https:\/\/ityet.com\/?p=10007060"},"modified":"2023-01-10T12:25:10","modified_gmt":"2023-01-10T04:25:10","slug":"redis%e7%9a%84string%e7%b1%bb%e5%9e%8b%ef%bc%8c%e5%8e%9f%e6%9d%a5%e8%bf%99%e4%b9%88%e5%8d%a0%e5%86%85%e5%ad%98","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10007060","title":{"rendered":"Redis\u7684String\u7c7b\u578b\uff0c\u539f\u6765\u8fd9\u4e48\u5360\u5185\u5b58"},"content":{"rendered":"<h2>Redis\u7684String\u7c7b\u578b\uff0c\u539f\u6765\u8fd9\u4e48\u5360\u5185\u5b58<\/h2>\n<blockquote><p>\u5b58\u4e00\u4e2a Long \u7c7b\u578b\u8fd9\u4e48\u5360\u5185\u5b58\uff0cRedis \u7684\u5185\u5b58\u5f00\u9500\u90fd\u82b1\u5728\u54ea\u513f\u4e86\uff1f<\/p><\/blockquote>\n<h3>1\u3001\u573a\u666f\u4ecb\u7ecd<\/h3>\n<p>\u5047\u8bbe\u73b0\u5728\u6211\u4eec\u8981\u5f00\u53d1\u4e00\u4e2a\u56fe\u7247\u5b58\u50a8\u7cfb\u7edf\uff0c\u8981\u6c42\u8fd9\u4e2a\u7cfb\u7edf\u80fd\u591f\u6839\u636e\u56fe\u7247 ID \u5feb\u901f\u67e5\u627e\u5230\u56fe\u7247\u5b58\u50a8\u5bf9\u8c61 ID\u3002\u56fe\u7247 ID \u548c\u56fe\u7247\u5b58\u50a8\u5bf9\u8c61 ID \u7684\u6837\u4f8b\u6570\u636e\u5982\u4e0b\uff1a<\/p>\n<pre><code>photo_id: 1101000060\nphoto_obj_id: 3302000080<\/code><\/pre>\n<p>\u5728\u8fd9\u79cd\u573a\u666f\u4e0b\uff0c\u56fe\u7247 ID \u548c\u56fe\u7247\u5b58\u50a8\u5bf9\u8c61 ID \u521a\u597d\u662f\u4e00\u5bf9\u4e00\u7684\u5173\u7cfb\uff0c\u662f\u5178\u578b\u7684\u201c\u952e &#8211; \u5355\u503c\u201d\u6a21\u5f0f\uff0cRedis \u7684 String \u7c7b\u578b\u63d0\u4f9b\u4e86\u201c\u4e00\u4e2a\u952e\u5bf9\u5e94\u4e00\u4e2a\u503c\u7684\u6570\u636e\u201d\u7684\u4fdd\u5b58\u5f62\u5f0f\uff0c\u5728\u8fd9\u79cd\u573a\u666f\u4e0b\u521a\u597d\u9002\u7528\u3002<\/p>\n<p>\u786e\u5b9a\u4f7f\u7528 String \u7c7b\u578b\u540e\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u901a\u8fc7\u5b9e\u6218\uff0c\u6765\u770b\u770b\u5b83\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u3002\u9996\u5148\u901a\u8fc7\u4e0b\u9762\u547d\u4ee4\u8fde\u63a5\u4e0a Redis\u3002<\/p>\n<blockquote><p>\u672c\u6587\u6211\u4f7f\u7528\u7684 Redis Server \u53ca\u4e0b\u6587\u6e90\u7801\u90fd\u662f 6.2.4 \u7248\u672c\u3002<\/p><\/blockquote>\n<pre><code class=\"shell\">redis-cli -h 127.0.0.1 -p 6379<\/code><\/pre>\n<p>\u7136\u540e\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\u67e5\u770b Redis \u7684\u521d\u59cb\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u3002<\/p>\n<pre><code class=\"shell\">127.0.0.1:6379&gt; info memory\n# Memory\nused_memory:871840<\/code><\/pre>\n<p>\u63a5\u7740\u63d2\u5165 10 \u6761\u6570\u636e\uff1a<\/p>\n<pre><code>10.118.32.170:0&gt; set 1101000060 3302000080\n10.118.32.170:0&gt; set 1101000061 3302000081\n10.118.32.170:0&gt; set 1101000062 3302000082\n10.118.32.170:0&gt; set 1101000063 3302000083\n10.118.32.170:0&gt; set 1101000064 3302000084\n10.118.32.170:0&gt; set 1101000065 3302000085\n10.118.32.170:0&gt; set 1101000066 3302000086\n10.118.32.170:0&gt; set 1101000067 3302000087\n10.118.32.170:0&gt; set 1101000068 3302000088\n10.118.32.170:0&gt; set 1101000069 3302000089<\/code><\/pre>\n<p>\u518d\u6b21\u67e5\u770b\u5185\u5b58\uff1a<\/p>\n<pre><code class=\"shell\">127.0.0.1:6379&gt; info memory\n# Memory\nused_memory:872528<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5b58\u50a8 10 \u4e2a\u56fe\u7247\uff0c\u5185\u5b58\u4f7f\u7528\u4e86 688 \u4e2a\u5b57\u8282\u3002\u4e00\u4e2a\u56fe\u7247 ID \u548c\u56fe\u7247\u5b58\u50a8\u5bf9\u8c61 ID \u7684\u8bb0\u5f55\u5e73\u5747\u7528\u4e86 68 \u5b57\u8282\u3002<\/p>\n<p>\u4f46\u95ee\u9898\u662f\uff0c\u4e00\u7ec4\u56fe\u7247 ID \u53ca\u5176\u5b58\u50a8\u5bf9\u8c61 ID \u7684\u8bb0\u5f55\uff0c\u5b9e\u9645\u53ea\u9700\u8981 16 \u5b57\u8282\u5c31\u53ef\u4ee5\u4e86\u3002\u56fe\u7247 ID \u548c\u56fe\u7247\u5b58\u50a8\u5bf9\u8c61 ID \u90fd\u662f 10 \u4f4d\u6570\uff0c\u800c 8 \u5b57\u8282\u7684 Long \u7c7b\u578b\u6700\u5927\u53ef\u4ee5\u8868\u793a 2 \u7684 64 \u6b21\u65b9\u7684\u6570\u503c\uff0c\u80af\u5b9a\u53ef\u4ee5\u8868\u793a 10 \u4f4d\u6570\u3002\u8fd9\u6837\u7b97\u4e0b\u6765\u53ea\u9700 16 \u5b57\u8282\u5c31\u53ef\u4ee5\u4e86\uff0c\u4e3a\u4ec0\u4e48 String \u7c7b\u578b\u5374\u7528\u4e86 68 \u5b57\u8282\u5462\uff1f<\/p>\n<p>\u4e3a\u4e86\u4e00\u63a2\u7a76\u7adf\uff0c\u6211\u4eec\u4e0d\u5f97\u4e0d\u4ece String \u7c7b\u578b\u7684\u5e95\u5c42\u5b9e\u73b0\u6252\u8d77\u3002<\/p>\n<h3>2\u3001String \u7c7b\u578b\u7684\u5e95\u5c42\u5b9e\u73b0<\/h3>\n<p>\u5f53\u4f60\u4fdd\u5b58\u7684\u6570\u636e\u4e2d\u5305\u542b\u5b57\u7b26\u65f6\uff0cString \u7c7b\u578b\u5c31\u4f1a\u7528\u7b80\u5355\u52a8\u6001\u5b57\u7b26\u4e32\uff08Simple Dynamic String\uff0cSDS\uff09\u7ed3\u6784\u4f53\u6765\u4fdd\u5b58\u3002<\/p>\n<h4>2.1 SDS<\/h4>\n<p>SDS \u7684\u7ed3\u6784\u5b9a\u4e49\u5728<code>sds.h<\/code>\u6587\u4ef6\u4e2d\uff0c\u5728 Redis 3.2 \u7248\u672c\u4e4b\u540e\uff0cSDS \u7531\u4e00\u79cd\u6570\u636e\u7ed3\u6784\u53d8\u6210\u4e86 5 \u79cd\u6570\u636e\u7ed3\u6784\u3002<\/p>\n<pre><code class=\"c\">\/* Note: sdshdr5 is never used, we just access the flags byte directly.\n * However is here to document the layout of type 5 SDS strings. *\/\nstruct __attribute__ ((__packed__)) hisdshdr5 {\n    unsigned char flags; \/* 3 lsb of type, and 5 msb of string length *\/\n    char buf[];\n};\nstruct __attribute__ ((__packed__)) hisdshdr8 {\n    uint8_t len; \/* used *\/\n    uint8_t alloc; \/* excluding the header and null terminator *\/\n    unsigned char flags; \/* 3 lsb of type, 5 unused bits *\/\n    char buf[];\n};\nstruct __attribute__ ((__packed__)) hisdshdr16 {\n    uint16_t len; \/* used *\/\n    uint16_t alloc; \/* excluding the header and null terminator *\/\n    unsigned char flags; \/* 3 lsb of type, 5 unused bits *\/\n    char buf[];\n};\nstruct __attribute__ ((__packed__)) hisdshdr32 {\n    uint32_t len; \/* used *\/\n    uint32_t alloc; \/* excluding the header and null terminator *\/\n    unsigned char flags; \/* 3 lsb of type, 5 unused bits *\/\n    char buf[];\n};\nstruct __attribute__ ((__packed__)) hisdshdr64 {\n    uint64_t len; \/* used *\/\n    uint64_t alloc; \/* excluding the header and null terminator *\/\n    unsigned char flags; \/* 3 lsb of type, 5 unused bits *\/\n    char buf[];\n};<\/code><\/pre>\n<p>\u8fd9 5 \u79cd\u6570\u636e\u7ed3\u6784\u4f9d\u6b21\u5b58\u50a8\u4e0d\u540c\u957f\u5ea6\u7684\u5185\u5bb9\uff0cRedis \u4f1a\u6839\u636e SDS \u5b58\u50a8\u7684\u5185\u5bb9\u957f\u5ea6\u6765\u9009\u62e9\u4e0d\u540c\u7684\u7ed3\u6784\u3002<\/p>\n<ul>\n<li>sdshdr5\uff1a\u5b58\u50a8\u5927\u5c0f\u4e3a 32 \u5b57\u8282\uff082 \u7684 5 \u6b21\u65b9\uff09\uff0c\u53ea\u88ab\u5e94\u7528\u5728\u4e86 Redis \u4e2d\u7684 key \u4e2d\u3002<\/li>\n<li>sdshdr8\uff1a\u5b58\u50a8\u5927\u5c0f\u4e3a 256 \u5b57\u8282\uff082 \u7684 8 \u6b21\u65b9\uff09\u3002<\/li>\n<li>sdshdr16\uff1a\u5b58\u50a8\u5927\u5c0f\u4e3a 64KB\uff082 \u7684 16 \u6b21\u65b9\uff09\u3002<\/li>\n<li>sdshdr32\uff1a\u5b58\u50a8\u5927\u5c0f\u4e3a 4GB\uff082 \u7684 32 \u6b21\u65b9\uff09\u3002<\/li>\n<li>sdshdr64\uff1a\u5b58\u50a8\u5927\u5c0f\u4e3a 2 \u7684 64 \u6b21\u65b9\u5b57\u8282\u3002<\/li>\n<\/ul>\n<p>\u4ee5 sdshdr8 \u4e3a\u4f8b\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043289478\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<ul>\n<li>buf\uff1a\u5b57\u8282\u6570\u7ec4\uff0c\u4fdd\u5b58\u5b9e\u9645\u6570\u636e\u3002\u4e3a\u4e86\u8868\u793a\u5b57\u8282\u6570\u7ec4\u7684\u7ed3\u675f\uff0cRedis \u4f1a\u81ea\u52a8\u5728\u6570\u7ec4\u6700\u540e\u52a0\u4e00\u4e2a<code>'\/0'<\/code>\uff0c\u8fd9\u5c31\u4f1a\u989d\u5916\u5360\u7528 1 \u4e2a\u5b57\u8282\u7684\u5f00\u9500\u3002<\/li>\n<li>len\uff1a\u5360 4 \u4e2a\u5b57\u8282\uff0c\u8868\u793a buf \u7684\u5df2\u7528\u957f\u5ea6\uff0c\u4e0d\u5305\u62ec<code>'\/0'<\/code>\u3002<\/li>\n<li>alloc\uff1a\u4e5f\u5360 4 \u4e2a\u5b57\u8282\uff0c\u8868\u793a buf \u7684\u5b9e\u9645\u5206\u914d\u957f\u5ea6\uff0c\u4e0d\u5305\u62ec<code>'\/0'<\/code>\u3002<\/li>\n<li>flags\uff1a\u5360 1 \u4e2a\u5b57\u8282\uff0c\u6807\u8bb0\u5f53\u524d\u5b57\u8282\u6570\u7ec4\u7684\u5c5e\u6027\uff0c\u662f<code>sdshdr8<\/code>\u8fd8\u662f<code>sdshdr16<\/code>\u7b49\u3002\uff08flags \u503c\u7684\u5b9a\u4e49\u53ef\u4ee5\u770b\u4e0b\u9762\u4ee3\u7801\uff09<\/li>\n<\/ul>\n<p>\u5728\u6e90\u7801<code>sds.h<\/code>\u4e2d\uff0cflags \u503c\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n<pre><code>#define HI_SDS_TYPE_5  0 \n#define HI_SDS_TYPE_8  1\n#define HI_SDS_TYPE_16 2\n#define HI_SDS_TYPE_32 3\n#define HI_SDS_TYPE_64 4<\/code><\/pre>\n<h4>2.2 RedisObject<\/h4>\n<p>\u56e0\u4e3a Redis \u7684\u6570\u636e\u7c7b\u578b\u6709\u5f88\u591a\uff0c\u800c\u4e14\uff0c\u4e0d\u540c\u6570\u636e\u7c7b\u578b\u90fd\u6709\u4e9b\u76f8\u540c\u7684\u5143\u6570\u636e\u8981\u8bb0\u5f55\uff0c\u6240\u4ee5\uff0c\u503c\u5bf9\u8c61\u5e76\u4e0d\u662f\u76f4\u63a5\u5b58\u50a8\uff0c\u800c\u662f\u88ab\u5305\u88c5\u6210<code>redisObject<\/code>\u5bf9\u8c61\uff0c\u5b83\u7684\u5b9a\u4e49\u5982\u4e0b\u3002<\/p>\n<pre><code class=\"c\">typedef struct redisObject {\n    unsigned type:4;\/\/\u5bf9\u8c61\u7c7b\u578b\uff084\u4f4d=0.5\u5b57\u8282\uff09\n    unsigned encoding:4;\/\/\u7f16\u7801\uff084\u4f4d=0.5\u5b57\u8282\uff09\n    unsigned lru:LRU_BITS;\/\/\u8bb0\u5f55\u5bf9\u8c61\u6700\u540e\u4e00\u6b21\u88ab\u5e94\u7528\u7a0b\u5e8f\u8bbf\u95ee\u7684\u65f6\u95f4\uff0824\u4f4d=3\u5b57\u8282\uff09\n    int refcount;\/\/\u5f15\u7528\u8ba1\u6570\u3002\u7b49\u4e8e0\u65f6\u8868\u793a\u53ef\u4ee5\u88ab\u5783\u573e\u56de\u6536\uff0832\u4f4d=4\u5b57\u8282\uff09\n    void *ptr;\/\/\u6307\u5411\u5e95\u5c42\u5b9e\u9645\u7684\u6570\u636e\u5b58\u50a8\u7ed3\u6784\uff0c\u5982\uff1asds\u7b49(8\u5b57\u8282)\n} robj;<\/code><\/pre>\n<p>\u4e0b\u9762\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u7406\u89e3\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043289479\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4e3a\u4e86\u8282\u7701\u5185\u5b58\u7a7a\u95f4\uff0cRedis \u8fd8\u505a\u4e86\u4e00\u4e9b\u4f18\u5316\u3002<\/p>\n<p>\u5f53\u4fdd\u5b58\u7684\u662f Long \u7c7b\u578b\u6574\u6570\u65f6\uff0cRedisObject \u4e2d\u7684\u6307\u9488\u5c31\u76f4\u63a5\u8d4b\u503c\u4e3a\u6574\u6570\u6570\u636e\u4e86\uff0c\u8fd9\u6837\u5c31\u4e0d\u7528\u989d\u5916\u7684\u6307\u9488\u518d\u6307\u5411\u6574\u6570\u4e86\u3002\u8fd9\u79cd\u4fdd\u5b58\u65b9\u5f0f\u901a\u5e38\u4e5f\u53eb\u4f5c int \u7f16\u7801\u65b9\u5f0f\u3002<\/p>\n<p>\u5f53\u4fdd\u5b58\u7684\u662f\u5b57\u7b26\u4e32\u6570\u636e\uff0c\u5e76\u4e14\u5b57\u7b26\u4e32\u5c0f\u4e8e\u7b49\u4e8e 44 \u5b57\u8282\u65f6\uff0cRedisObject \u4e2d\u7684\u5143\u6570\u636e\u3001\u6307\u9488\u548c SDS \u662f\u4e00\u5757\u8fde\u7eed\u7684\u5185\u5b58\u533a\u57df\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u907f\u514d\u5185\u5b58\u788e\u7247\u3002\u8fd9\u79cd\u5e03\u5c40\u65b9\u5f0f\u4e5f\u88ab\u79f0\u4e3a embstr \u7f16\u7801\u65b9\u5f0f\u3002<\/p>\n<p>\u5f53\u5b57\u7b26\u4e32\u5927\u4e8e 44 \u5b57\u8282\u65f6\uff0cSDS \u7684\u6570\u636e\u91cf\u5c31\u5f00\u59cb\u53d8\u591a\u4e86\uff0cRedis \u5c31\u4e0d\u518d\u628a SDS \u548c RedisObject \u5e03\u5c40\u5728\u4e00\u8d77\u4e86\uff0c\u800c\u662f\u4f1a\u7ed9 SDS \u5206\u914d\u72ec\u7acb\u7684\u7a7a\u95f4\uff0c\u5e76\u7528\u6307\u9488\u6307\u5411 SDS \u7ed3\u6784\u3002\u8fd9\u79cd\u5e03\u5c40\u65b9\u5f0f\u88ab\u79f0\u4e3a raw \u7f16\u7801\u6a21\u5f0f\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043289480\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u4f7f\u7528 OBJECT ENCODING \u547d\u4ee4\u53ef\u4ee5\u67e5\u770b\u4e00\u4e2a\u6570\u636e\u5e93\u952e\u7684\u503c\u5bf9\u8c61\u7684\u7f16\u7801\uff1a<\/p>\n<pre><code class=\"shell\">127.0.0.1:6379&gt; SET msg &quot;hello world&quot;\nOK\n127.0.0.1:6379&gt; OBJECT ENCODING msg\n&quot;embstr&quot;\n127.0.0.1:6379&gt; SET story &quot;long long long ago...&quot;\nOK\n127.0.0.1:6379&gt; OBJECT ENCODING story\n&quot;raw&quot;\n127.0.0.1:6379&gt; SADD numbers 1 3 5\n(integer) 3\n127.0.0.1:6379&gt; OBJECT ENCODING numbers\n&quot;intset&quot;\n127.0.0.1:6379&gt; SADD numbers &quot;seven&quot;\n(integer) 1\n127.0.0.1:6379&gt; OBJECT ENCODING numbers\n&quot;hashtable&quot;<\/code><\/pre>\n<blockquote><p>\u6ce8\u610f\u8fd9\u4e2a\u547d\u4ee4<code>SET story &quot;long long long ago...&quot;<\/code>\uff0c\u7701\u7565\u53f7\u6307\u7684\u662f\u7701\u7565\u4e86\u5f88\u591a\u5b57\u7b26\u3002<\/p><\/blockquote>\n<p>\u77e5\u9053\u4e86 SDS \u548c RedisObject \u989d\u5916\u5143\u6570\u636e\u5f00\u9500\uff0c\u73b0\u5728\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u8ba1\u7b97 String \u7c7b\u578b\u7684\u5185\u5b58\u4f7f\u7528\u91cf\u4e86\u3002<\/p>\n<p>\u56fe\u7247\u5b58\u50a8\u5bf9\u8c61 ID \u662f Long \u7c7b\u578b\u6574\u6570\uff0c\u6240\u4ee5\u53ef\u4ee5\u76f4\u63a5\u7528 int \u7f16\u7801\u7684 RedisObject \u4fdd\u5b58\u3002\u6bcf\u4e2a int \u7f16\u7801\u7684 RedisObject \u5143\u6570\u636e\u90e8\u5206\u5360 8 \u5b57\u8282\uff0c\u6307\u9488\u90e8\u5206\u88ab\u76f4\u63a5\u8d4b\u503c\u4e3a 8 \u5b57\u8282\u7684\u6574\u6570\u4e86\u3002\u56fe\u7247 ID \u4f7f\u7528 sdshdr5 \u6570\u636e\u7ed3\u6784\u6765\u4fdd\u5b58\uff0c\u4f1a\u4e3a 10 \u4f4d\u7684\u56fe\u7247 ID \u5206\u914d 16 \u4e2a\u5b57\u8282\uff0c\u7ed3\u675f\u7b26 &#8216;\/0&#8217; \u5360 1 \u4e2a\u5b57\u8282\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043289481\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>\u5171\u5360\u7528 34 \u4e2a\u5b57\u8282\u3002\u4e0e\u4e0a\u6587\u6240\u8bf4\u7684\u4e00\u4e2a\u56fe\u7247 ID \u548c\u56fe\u7247\u5b58\u50a8\u5bf9\u8c61 ID \u7684\u8bb0\u5f55\u5e73\u5747\u7528\u4e86 68 \u5b57\u8282\u76f8\u5dee\u6709\u70b9\u5927\u554a\uff0c\u53e6\u5916\u7684\u5f00\u9500\u53bb\u54ea\u513f\u4e86\uff1f<\/p>\n<h4>2.3 \u5168\u5c40\u54c8\u5e0c\u8868<\/h4>\n<p>\u4e3a\u4e86\u5b9e\u73b0\u4ece\u952e\u5230\u503c\u7684\u5feb\u901f\u8bbf\u95ee\uff0cRedis \u4f7f\u7528\u4e86\u4e00\u4e2a\u54c8\u5e0c\u8868\u6765\u4fdd\u5b58\u6240\u6709\u952e\u503c\u5bf9\u3002\u56e0\u4e3a\u8fd9\u4e2a\u54c8\u5e0c\u8868\u4fdd\u5b58\u4e86\u6240\u6709\u7684\u952e\u503c\u5bf9\uff0c\u6240\u4ee5\uff0c\u4e5f\u79f0\u4e3a\u5168\u5c40\u54c8\u5e0c\u8868\u3002\u54c8\u5e0c\u8868\u7684\u6bcf\u4e00\u9879\u662f\u4e00\u4e2a dictEntry \u7684\u7ed3\u6784\u4f53\uff0c\u7528\u6765\u6307\u5411\u4e00\u4e2a\u952e\u503c\u5bf9\u3002dictEntry \u7ed3\u6784\u4e2d\u6709\u4e09\u4e2a 8 \u5b57\u8282\u7684\u6307\u9488\uff0c\u5206\u522b\u6307\u5411 key\u3001value \u4ee5\u53ca\u4e0b\u4e00\u4e2a dictEntry\uff0c\u4e09\u4e2a\u6307\u9488\u5171 24 \u5b57\u8282\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000043289482\" alt=\"\" title=\"\" loading=\"lazy\"><\/p>\n<p>jemalloc \u5728\u5206\u914d\u5185\u5b58\u65f6\uff0c\u4f1a\u5206\u914d\u4e00\u4e2a\u6700\u63a5\u8fd1 2 \u7684 N \u6b21\u65b9\u7684\u6570\u503c\u3002\u4e3e\u4e2a\u4f8b\u5b50\u3002\u5982\u679c\u4f60\u7533\u8bf7 6 \u5b57\u8282\u7a7a\u95f4\uff0cjemalloc \u5b9e\u9645\u4f1a\u5206\u914d 2 \u7684 4 \u6b21\u65b9\u5373 8 \u5b57\u8282\u7a7a\u95f4\uff1b\u5982\u679c\u4f60\u7533\u8bf7 24 \u5b57\u8282\u7a7a\u95f4\uff0cjemalloc \u5219\u4f1a\u5206\u914d 32 \u5b57\u8282\u3002<\/p>\n<p>\u6700\u7ec8\u6211\u4eec\u5206\u6790\u51fa\u6765\u7684\u5185\u5b58\u5f00\u9500\uff0c\u4e3a 66 \u5b57\u8282\uff0c\u6bd4\u8f83\u63a5\u8fd1\u4e0a\u6587\u573a\u666f\u4e2d\u7684\u5e73\u5747\u503c 68 \u4e86\u3002<\/p>\n<h3>\u6700\u540e<\/h3>\n<p>\u65e2\u7136 String \u7c7b\u578b\u8fd9\u4e48\u5360\u5185\u5b58\uff0c\u90a3\u4e48\u4f60\u6709\u597d\u7684\u65b9\u6848\u6765\u8282\u7701\u5185\u5b58\u5417\uff1f<\/p>\n<p>\u8fd9\u7bc7\u6587\u7ae0\u5185\u5bb9\u6211\u51c6\u5907\u4e86\u4e00\u5468\uff0c\u5982\u679c\u5bf9\u4f60\u6709\u5e2e\u52a9\uff0c\u53ef\u4ee5\u70b9\u4e2a\u300c\u5728\u770b\u300d\u5417\uff1f\u4f60\u7684\u70b9\u8d5e\u4f1a\u8ba9\u4f5c\u8005\u5174\u594b\u5f97\u4e00\u665a\u4e0a\u7761\u4e0d\u7740\u89c9\u3002<\/p>\n<p>\u5bf9\u540e\u9762\u7684\u5185\u5bb9\u611f\u5174\u8da3\uff0c\u4e5f\u53ef\u4ee5\u5173\u6ce8\u516c\u4f17\u53f7\u300c\u6768\u540c\u5b66technotes\u300d\uff0c\u611f\u8c22\u652f\u6301\uff01<\/p>\n<h3>\u53c2\u8003\u8d44\u6599<\/h3>\n<ul>\n<li>\u6587\u4e2d\u7684\u4e00\u4e9b\u547d\u4ee4\uff0c\u53c2\u8003\u83dc\u9e1f\u6559\u7a0b\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=wydeKdfyLG3YY36w40OaWg%3D%3D.ENdDm3twjQs5DQvv8FiM2Qam3zjgf4a16yfOrWFJVqncVEjVEZsh%2BvBa00ZfkWtv8VdXTEUAJgb%2FhNhRA3TJOQ%3D%3D\" rel=\"nofollow\">https:\/\/www.runoob.com\/redis\/&#8230;<\/a><\/li>\n<li>Redis \u7684 key \u4e5f\u662f SDS \u7c7b\u578b\u7684\uff0c\u53c2\u8003\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=GEQOa%2BZLyvnaWyJXTxXz4g%3D%3D.%2BraPaf8Wz5EzFPDr06fu1N9XPvWR1zRLRl9NhUxV98RGG8k4RhOHBNHHBCSH3ye%2FS%2BVRApqU3%2B2SrflboPiYWQ%3D%3D\" rel=\"nofollow\">https:\/\/www.cnblogs.com\/lonel&#8230;<\/a><\/li>\n<li>SDS \u7684\u5b9a\u4e49\uff0c\u53c2\u8003\uff1a<a href=\"https:\/\/link.segmentfault.com\/?enc=4BxSzE8r%2F%2F5WCeG6%2BDRhoQ%3D%3D.Sf9C00q9Le9WVDucmfFI2bnzgE%2FJF4C460BSd5TI6gNCLKjLaZIXdK048tV9PWo5iOngv1luW6zzNXeX2f9HAg%3D%3D\" rel=\"nofollow\">https:\/\/juejin.cn\/post\/684490&#8230;<\/a><\/li>\n<li>\u6587\u7ae0\u5927\u7eb2\uff0c\u53c2\u8003\u6781\u5ba2\u65f6\u95f4\u300aRedis\u6838\u5fc3\u6280\u672f\u4e0e\u5b9e\u6218\u300b<\/li>\n<li>\u300aRedis\u8bbe\u8ba1\u4e0e\u5b9e\u73b0\u300b<\/li>\n<\/ul>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000043289476\">https:\/\/segmentfault.com\/a\/1190000043289476<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis\u7684String\u7c7b\u578b\uff0c\u539f\u6765\u8fd9\u4e48\u5360\u5185\u5b58 \u5b58\u4e00\u4e2a Long \u7c7b\u578b\u8fd9\u4e48\u5360\u5185\u5b58\uff0cRedis \u7684\u5185\u5b58\u5f00\u9500\u90fd\u82b1\u5728\u54ea [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10007060","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10007060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10007060"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10007060\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10007060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10007060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10007060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}