{"id":10006172,"date":"2022-08-11T14:00:14","date_gmt":"2022-08-11T06:00:14","guid":{"rendered":"https:\/\/ityet.com\/?p=10006172"},"modified":"2022-08-11T14:00:14","modified_gmt":"2022-08-11T06:00:14","slug":"redis%e4%b8%ba%e4%bb%80%e4%b9%88%e8%bf%99%e4%b9%88%e5%bf%ab%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006172","title":{"rendered":"Redis\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u5feb\uff1f"},"content":{"rendered":"<p>\u9996\u5148Redis\u662f\u4e00\u4e2a\u4f7f\u7528ANSI C\u7f16\u5199\u7684\u3001\u5f00\u6e90\u7684\u3001\u652f\u6301\u7f51\u7edc\u7684\u3001\u57fa\u4e8e\u5185\u5b58\u7684\u3001\u53ef\u9009\u6301\u4e45\u5316\u7684\u952e\u503c\u5bf9\u5b58\u50a8\u7cfb\u7edf\u3002<\/p>\n<p>1 Redis\u7684\u53d1\u5bb6\u53f2<br \/>2009\u5e74\u7531 Salvatore Sanfilippo\uff08Redis\u4e4b\u7236\uff09\u53d1\u5e03\u521d\u59cb\u7248\u672c<br \/>2013\u5e745\u6708\u4e4b\u524d\uff0c\u7531VMare\u8d5e\u52a9<br \/>2013\u5e745\u6708-2015\u5e746\u6708\uff0c\u7531Pivotal\u8d5e\u52a9<br \/>2015\u5e746\u6708\u8d77\uff0c\u7531Redis Labs\u8d5e\u52a9\u6839\u636edb-engines.com\u4e0a\u7684\u6392\u540d\uff0c\u5230\u76ee\u524d\u4e3a\u6b62Redis\u4f9d\u7136\u662f\u6700\u6d41\u884c\u7684\u952e\u503c\u5bf9\u5b58\u50a8\u7cfb\u7edf\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302482\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302483\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>2 Redis\u4e3b\u8981\u7248\u672c<br \/>2009\u5e745\u6708\u53d1\u5e03Redis\u521d\u59cb\u7248\u672c<br \/>2012\u5e74\u53d1\u5e03Redis 2.6.0<br \/>2013\u5e7411\u6708\u53d1\u5e03Redis 2.8.0<br \/>2015\u5e744\u6708\u53d1\u5e03Redis 3.0.0\uff0c\u5728\u8be5\u7248\u672cRedis\u5f15\u5165\u96c6\u7fa4<br \/>2017\u5e747\u6708\u53d1\u5e03Redis 4.0.0\uff0c\u5728\u8be5\u7248\u672cRedis\u5f15\u5165\u4e86\u6a21\u5757\u7cfb\u7edf<br \/>2018\u5e7410\u6708\u53d1\u5e03Redis 5.0.0\uff0c\u5728\u8be5\u7248\u672c\u5f15\u5165\u4e86Streams\u7ed3\u6784<br \/>2020\u5e745\u67082\u65e5\u53d1\u5e03 6.0.1\uff08\u7a33\u5b9a\u7248\uff09\uff0c\u5728\u8be5\u7248\u672c\u4e2d\u5f15\u5165\u591a\u7ebf\u7a0b\u3001RESP3\u534f\u8bae\u3001\u65e0\u76d8\u590d\u5236\u526f\u672c<br \/>2022\u5e741\u670831\u65e5\u53d1\u5e03 7.0 RC1\uff0c\u5728\u8be5\u7248\u672c\u4e2d\u4e3b\u8981\u662f\u5bf9\u6027\u80fd\u548c\u5185\u5b58\u8fdb\u884c\u4f18\u5316\uff0c\u65b0\u7684AOF\u6a21\u5f0f<\/p>\n<p>3 Redis \u6709\u591a\u5feb\uff1f<\/p>\n<p>Redis\u4e2d\u5e26\u6709\u4e00\u4e2a\u53ef\u4ee5\u8fdb\u884c\u6027\u80fd\u6d4b\u8bd5\u7684\u5de5\u5177 redis-benchmark\uff0c\u901a\u8fc7\u8fd9\u4e2a\u547d\u4ee4\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u6a21\u62df\u591a\u4e2a\u5ba2\u6237\u7aef\u540c\u65f6\u53d1\u8d77\u8bf7\u6c42\u7684\u573a\u666f\uff0c\u5e76\u4e14\u53ef\u4ee5\u68c0\u6d4bRedis\u5904\u7406\u8fd9\u4e9b\u8bf7\u6c42\u6240\u9700\u8981\u7684\u65f6\u95f4\u3002<\/p>\n<p>\u6839\u636e\u5b98\u65b9\u7684\u6587\u6863\uff0cRedis \u5df2\u7ecf\u5728\u8d85\u8fc7 60000 \u4e2a\u8fde\u63a5\u4e0a\u8fdb\u884c\u4e86\u57fa\u51c6\u6d4b\u8bd5\uff0c\u5e76\u4e14\u5728\u8fd9\u4e9b\u6761\u4ef6\u4e0b\u4ecd\u7136\u80fd\u591f\u7ef4\u6301 50000 q\/s\u3002\u540c\u6837\u7684\u8bf7\u6c42\u91cf\u5982\u679c\u6253\u5230MySQL\u4e0a\uff0c\u90a3\u80af\u5b9a\u625b\u4e0d\u4f4f\uff0c\u76f4\u63a5\u5c31\u5d29\u6389\u4e86\u3002<\/p>\n<p>With high-end configurations, the number of client connections is also an important factor. Being based on epoll\/kqueue, the Redis event loop is quite scalable. Redis has already been benchmarked at more than 60000 connections, and was still able to sustain 50000 q\/s in these conditions. As a rule of thumb, an instance with 30000 connections can only process half the throughput achievable with 100 connections. Here is an example showing the throughput of a Redis instance per number of connections\uff1b<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302484\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>4 Redis\u4e3a\u4ec0\u4e48\u53ef\u4ee5\u8fd9\u4e48\u5feb\uff1f<\/p>\n<p>\u90a3\u662f\u4ec0\u4e48\u539f\u56e0\u9020\u5c31\u4e86Redis\u53ef\u4ee5\u5177\u6709\u5982\u6b64\u9ad8\u7684\u6027\u80fd\uff1f\u4e3b\u8981\u5206\u4e3a\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302485\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>4.1 \u57fa\u4e8e\u5185\u5b58\u5b9e\u73b0<\/p>\n<p>Mysql\u7684\u6570\u636e\u5b58\u50a8\u6301\u4e45\u5316\u662f\u5b58\u50a8\u5230\u78c1\u76d8\u4e0a\u7684\uff0c\u8bfb\u53d6\u6570\u636e\u662f\u5185\u5b58\u4e2d\u5982\u679c\u6ca1\u6709\u7684\u8bdd\uff0c\u5c31\u4f1a\u4ea7\u751f\u78c1\u76d8I\/O\uff0c\u5148\u628a\u6570\u636e\u8bfb\u53d6\u5230\u5185\u5b58\u4e2d\uff0c\u518d\u8bfb\u53d6\u6570\u636e\u3002\u800cRedis\u5219\u662f\u76f4\u63a5\u628a\u6570\u636e\u5b58\u50a8\u5230\u5185\u5b58\u4e2d\uff0c\u51cf\u5c11\u4e86\u78c1\u76d8I\/O\u9020\u6210\u7684\u6d88\u8017\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302486\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>4.2 \u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784<\/p>\n<p>\u5408\u7406\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5c31\u662f\u53ef\u4ee5\u8ba9\u4f60\u7684\u5e94\u7528\/\u7a0b\u5e8f\u66f4\u5feb\u3002Mysql\u7d22\u5f15\u4e3a\u4e86\u63d0\u9ad8\u6548\u7387\uff0c\u9009\u62e9\u4e86B+\u6811\u7684\u6570\u636e\u7ed3\u6784\u3002\u5148\u770b\u4e0bRedis\u7684\u6570\u636e\u7ed3\u6784&#038;\u5185\u90e8\u7f16\u7801\u56fe\uff1a<br \/><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302487\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>4.2.1 SDS\u7b80\u5355\u52a8\u6001\u5b57\u7b26\u4e32<\/p>\n<p>Redis\u6ca1\u6709\u91c7\u7528\u539f\u751fC\u8bed\u8a00\u7684\u5b57\u7b26\u4e32\u7c7b\u578b\u800c\u662f\u81ea\u5df1\u5b9e\u73b0\u4e86\u5b57\u7b26\u4e32\u7ed3\u6784-\u7b80\u5355\u52a8\u6001\u5b57\u7b26\u4e32\uff08simple dynamic string)<br \/><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302488\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302489\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>SDS\u4e0eC\u8bed\u8a00\u5b57\u7b26\u4e32\u7684\u533a\u522b\uff1a<br \/>\u83b7\u53d6\u5b57\u7b26\u4e32\u957f\u5ea6\uff1aC\u5b57\u7b26\u4e32\u7684\u590d\u6742\u5ea6\u4e3aO(N)\uff0c\u800cSDS\u7684\u590d\u6742\u5ea6\u4e3aO(1)\u3002<br \/>\u675c\u7edd\u7f13\u51b2\u533a\u6ea2\u51fa\uff08C\u8bed\u8a00\u6bcf\u6b21\u9700\u8981\u624b\u52a8\u6269\u5bb9\uff09\uff0c\u5982\u679cC\u5b57\u7b26\u4e32\u60f3\u8981\u6269\u5bb9\uff0c\u5728\u6ca1\u6709\u7533\u8bf7\u8db3\u591f\u591a\u7684\u5185\u5b58\u7a7a\u95f4\u4e0b\uff0c\u4f1a\u51fa\u73b0\u5185\u5b58\u6ea2\u51fa\u7684\u60c5\u51b5\uff0c\u800cSDS\u8bb0\u5f55\u4e86\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\uff0c\u5982\u679c\u957f\u5ea6\u4e0d\u591f\u7684\u60c5\u51b5\u4e0b\u4f1a\u8fdb\u884c\u6269\u5bb9\u3002<br \/>\u51cf\u5c11\u4fee\u6539\u5b57\u7b26\u4e32\u65f6\u5e26\u6765\u7684\u5185\u5b58\u91cd\u5206\u914d\u6b21\u6570<br \/>\u7a7a\u95f4\u9884\u5206\u914d\uff0c<br \/>\u89c4\u52191\uff1a\u4fee\u6539\u540e\u957f\u5ea6&lt; 1MB\uff0c\u9884\u5206\u914d\u540c\u6837\u5927\u5c0f\u672a\u4f7f\u7528\u7a7a\u95f4\uff0cfree=len\uff1b<br \/>\u89c4\u52192\uff1a\u4fee\u6539\u540e\u957f\u5ea6 &gt;= 1MB\uff0c\u9884\u5206\u914d1MB\u672a\u4f7f\u7528\u7a7a\u95f4\u3002<br \/>\u60f0\u6027\u7a7a\u95f4\u91ca\u653e\uff0cSDS \u7f29\u77ed\u65f6\uff0c\u4e0d\u662f\u56de\u6536\u591a\u4f59\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u800c\u662ffree\u8bb0\u5f55\u4e0b\u591a\u4f59\u7684\u7a7a\u95f4\uff0c\u540e\u7eed\u6709\u53d8\u66f4\uff0c\u76f4\u63a5\u4f7f\u7528free\u4e2d\u8bb0\u5f55\u7684\u7a7a\u95f4\uff0c\u51cf\u5c11\u5206\u914d\u3002<\/p>\n<p>4.2.2 embstr &#038; raw<\/p>\n<p>Redis \u7684\u5b57\u7b26\u4e32\u6709\u4e24\u79cd\u5b58\u50a8\u65b9\u5f0f\uff0c\u5728\u957f\u5ea6\u7279\u522b\u77ed\u65f6\uff0c\u4f7f\u7528 emb \u5f62\u5f0f\u5b58\u50a8 (embeded)\uff0c\u5f53\u957f\u5ea6\u8d85\u8fc7 44 \u65f6\uff0c\u4f7f\u7528 raw \u5f62\u5f0f\u5b58\u50a8\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302490\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>\u4e3a\u4ec0\u4e48\u5206\u754c\u7ebf\u662f 44 \u5462\uff1f<br \/>\u5728CPU\u548c\u4e3b\u5185\u5b58\u4e4b\u95f4\u8fd8\u6709\u4e00\u4e2a\u9ad8\u901f\u6570\u636e\u7f13\u51b2\u533a\uff0c\u6709L1\uff0cL2\uff0cL3\u4e09\u7ea7\u7f13\u5b58\uff0cL1\u7ea7\u7f13\u5b58\u65f6\u8ddd\u79bbCPU\u6700\u8fd1\u7684\uff0cCPU\u4f1a\u6709\u9650\u4eceL1\u7f13\u5b58\u4e2d\u83b7\u53d6\u6570\u636e\uff0c\u5176\u6b21\u662fL2\uff0cL3\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302491\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>L1\u6700\u5feb\u4f46\u662f\u4ed6\u7684\u5b58\u50a8\u7a7a\u95f4\u4e5f\u662f\u6709\u9650\u7684\uff0c\u5927\u698264\u5b57\u8282\uff0c\u629b\u53bb\u5bf9\u8c61\u56fa\u5b9a\u5c5e\u6027\u5360\u7528\u7684\u7a7a\u95f4\uff0c\u4ee5\u53ca\u2018\/0\u2019\uff0c\u5269\u4f59\u7684\u7a7a\u95f4\u6700\u591a\u4e5f\u5c31\u662f44\u4e2a\u5b57\u8282\uff0c\u8d85\u8fc744\u5b57\u8282L1\u7f13\u5b58\u5c31\u5b58\u4e0d\u4e0b\u4e86\u3002<br \/><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302492\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>4.2.3 \u5b57\u5178(DICT)<br \/>Redis \u4f5c\u4e3a K-V \u578b\u5185\u5b58\u6570\u636e\u5e93\uff0c\u6240\u6709\u7684\u952e\u503c\u5c31\u662f\u7528\u5b57\u5178\u6765\u5b58\u50a8\u3002\u5b57\u5178\u5c31\u662f\u54c8\u5e0c\u8868\uff0c\u6bd4\u5982HashMap\uff0c\u901a\u8fc7key\u5c31\u53ef\u4ee5\u76f4\u63a5\u83b7\u53d6\u5230\u5bf9\u5e94\u7684value\u3002\u800c\u54c8\u5e0c\u8868\u7684\u7279\u6027\uff0c\u5728O\uff081\uff09\u65f6\u95f4\u590d\u6742\u5ea6\u5c31\u53ef\u4ee5\u83b7\u5f97\u5bf9\u5e94\u7684\u503c\u3002<\/p>\n<pre><code>\/\/\u5b57\u5178\u7ed3\u6784\u6570\u636etypedef struct dict {    dictType *type;  \/\/\u63a5\u53e3\u5b9e\u73b0\uff0c\u4e3a\u5b57\u5178\u63d0\u4f9b\u591a\u6001\u6027    void *privdata;  \/\/\u5b58\u50a8\u4e00\u4e9b\u989d\u5916\u7684\u6570\u636e    dictht ht[2];   \/\/\u4e24\u4e2ahash\u8868    long rehashidx. \/\/\u6e10\u8fdb\u5f0frehash\u65f6\u8bb0\u5f55\u5f53\u524drehash\u7684\u4f4d\u7f6e} dict;\n<\/code><\/pre>\n<p>\u4e24\u4e2ahashtable\u901a\u5e38\u60c5\u51b5\u4e0b\u53ea\u6709\u4e00\u4e2ahashtable\u662f\u6709\u503c\u7684\uff0c\u53e6\u5916\u4e00\u4e2a\u662f\u5728\u8fdb\u884crehash\u7684\u65f6\u5019\u624d\u4f1a\u7528\u5230\uff0c\u5728\u6269\u5bb9\u65f6\u9010\u6e10\u7684\u4ece\u4e00\u4e2ahashtable\u4e2d\u8fc1\u79fb\u81f3\u53e6\u5916\u4e00\u4e2ahashtable\u4e2d\uff0c\u642c\u8fc1\u7ed3\u675f\u540e\u65e7\u7684hashtable\u4f1a\u88ab\u6e05\u7a7a\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302493\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<pre><code>hashtable\u7684\u7ed3\u6784\u5982\u4e0b\uff1atypedef struct dictht {    dictEntry **table;  \/\/\u6307\u5411\u7b2c\u4e00\u4e2a\u6570\u7ec4    unsigned long size;  \/\/\u6570\u7ec4\u7684\u957f\u5ea6    unsigned long sizemask; \/\/\u7528\u4e8e\u5feb\u901fhash\u5b9a\u4f4d    unsigned long used; \/\/\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u4e2a\u6570} dictht;typedef struct dictEntry {    void *key;    union {        void *val;        uint64_t u64;        int64_t s64;        double d;   \/\/\u7528\u4e8ezset\uff0c\u5b58\u50a8score\u503c    } v;    struct dictEntry *next;} dictEntry;<\/code><\/pre>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302494\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>4.2.4 \u538b\u7f29\u5217\u8868\uff08ziplist\uff09<\/p>\n<p>redis\u4e3a\u4e86\u8282\u7701\u5185\u5b58\u7a7a\u95f4\uff0czset\u548chash\u5bf9\u8c61\u5728\u6570\u636e\u6bd4\u8f83\u5c11\u7684\u65f6\u5019\u91c7\u7528\u7684\u662fziplist\u7684\u7ed3\u6784\uff0c\u662f\u4e00\u5757\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u5e76\u4e14\u652f\u6301\u53cc\u5411\u904d\u5386<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302495\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>4.2.5 \u8df3\u8dc3\u8868<\/p>\n<p>\u8df3\u8dc3\u8868\u662fRedis\u7279\u6709\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5c31\u662f\u5728\u94fe\u8868\u7684\u57fa\u7840\u4e0a\uff0c\u589e\u52a0\u591a\u7ea7\u7d22\u5f15\u63d0\u5347\u67e5\u627e\u6548\u7387\u3002\u8df3\u8dc3\u8868\u652f\u6301\u5e73\u5747 O\uff08logN\uff09,\u6700\u574f O\uff08N\uff09\u590d\u6742\u5ea6\u7684\u8282\u70b9\u67e5\u627e\uff0c\u8fd8\u53ef\u4ee5\u901a\u8fc7\u987a\u5e8f\u6027\u64cd\u4f5c\u6279\u91cf\u5904\u7406\u8282\u70b9\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302496\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>4.3 \u5408\u7406\u7684\u6570\u636e\u7f16\u7801<\/p>\n<p>Redis \u652f\u6301\u591a\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u6bcf\u79cd\u57fa\u672c\u7c7b\u578b\uff0c\u53ef\u80fd\u5bf9\u591a\u79cd\u6570\u636e\u7ed3\u6784\u3002\u4ec0\u4e48\u65f6\u5019,\u4f7f\u7528\u4ec0\u4e48\u6837\u6570\u636e\u7ed3\u6784\uff0c\u4f7f\u7528\u4ec0\u4e48\u6837\u7f16\u7801\uff0c\u662fredis\u8bbe\u8ba1\u8005\u603b\u7ed3\u4f18\u5316\u7684\u7ed3\u679c\u3002<\/p>\n<p>String\uff1a\u5982\u679c\u5b58\u50a8\u6570\u5b57\u7684\u8bdd\uff0c\u662f\u7528int\u7c7b\u578b\u7684\u7f16\u7801;\u5982\u679c\u5b58\u50a8\u975e\u6570\u5b57\uff0c\u5c0f\u4e8e\u7b49\u4e8e39\u5b57\u8282\u7684\u5b57\u7b26\u4e32\uff0c\u662fembstr\uff1b\u5927\u4e8e39\u4e2a\u5b57\u8282\uff0c\u5219\u662fraw\u7f16\u7801\u3002<br \/>List\uff1a\u5982\u679c\u5217\u8868\u7684\u5143\u7d20\u4e2a\u6570\u5c0f\u4e8e512\u4e2a\uff0c\u5217\u8868\u6bcf\u4e2a\u5143\u7d20\u7684\u503c\u90fd\u5c0f\u4e8e64\u5b57\u8282\uff08\u9ed8\u8ba4\uff09\uff0c\u4f7f\u7528ziplist\u7f16\u7801\uff0c\u5426\u5219\u4f7f\u7528linkedlist\u7f16\u7801<br \/>Hash\uff1a\u54c8\u5e0c\u7c7b\u578b\u5143\u7d20\u4e2a\u6570\u5c0f\u4e8e512\u4e2a\uff0c\u6240\u6709\u503c\u5c0f\u4e8e64\u5b57\u8282\u7684\u8bdd\uff0c\u4f7f\u7528ziplist\u7f16\u7801,\u5426\u5219\u4f7f\u7528hashtable\u7f16\u7801\u3002<br \/>Set\uff1a\u5982\u679c\u96c6\u5408\u4e2d\u7684\u5143\u7d20\u90fd\u662f\u6574\u6570\u4e14\u5143\u7d20\u4e2a\u6570\u5c0f\u4e8e512\u4e2a\uff0c\u4f7f\u7528intset\u7f16\u7801\uff0c\u5426\u5219\u4f7f\u7528hashtable\u7f16\u7801\u3002<br \/>Zset\uff1a\u5f53\u6709\u5e8f\u96c6\u5408\u7684\u5143\u7d20\u4e2a\u6570\u5c0f\u4e8e128\u4e2a\uff0c\u6bcf\u4e2a\u5143\u7d20\u7684\u503c\u5c0f\u4e8e64\u5b57\u8282\u65f6\uff0c\u4f7f\u7528ziplist\u7f16\u7801\uff0c\u5426\u5219\u4f7f\u7528skiplist\uff08\u8df3\u8dc3\u8868\uff09\u7f16\u7801<\/p>\n<p>4.4 \u5408\u7406\u7684\u7ebf\u7a0b\u6a21\u578b<\/p>\n<p>\u9996\u5148\u662f\u5355\u7ebf\u7a0b\u6a21\u578b-\u907f\u514d\u4e86\u4e0a\u4e0b\u6587\u5207\u6362\u9020\u6210\u7684\u65f6\u95f4\u6d6a\u8d39\uff0c\u5355\u7ebf\u7a0b\u6307\u7684\u662f\u7f51\u7edc\u8bf7\u6c42\u6a21\u5757\u4f7f\u7528\u4e86\u4e00\u4e2a\u7ebf\u7a0b\uff0c\u5373\u4e00\u4e2a\u7ebf\u7a0b\u5904\u7406\u6240\u6709\u7f51\u7edc\u8bf7\u6c42\uff0c\u5176\u4ed6\u6a21\u5757\u8be5\u4f7f\u7528\u591a\u7ebf\u7a0b\uff0c\u4ecd\u4f1a\u4f7f\u7528\u4e86\u591a\u4e2a\u7ebf\u7a0b\uff0c\u4f7f\u7528\u591a\u7ebf\u7a0b\uff0c\u5982\u679c\u6ca1\u6709\u4e00\u4e2a\u826f\u597d\u7684\u8bbe\u8ba1\uff0c\u5f88\u6709\u53ef\u80fd\u9020\u6210\u5728\u591a\u7ebf\u7a0b\u6570\u589e\u52a0\u7684\u65f6\u5019\u524d\u671f\u541e\u5410\u7387\u589e\u52a0\uff0c\u540e\u671f\u541e\u5410\u7387\u53cd\u800c\u589e\u957f\u6ca1\u6709\u90a3\u4e48\u660e\u663e\u4e86\u3002<\/p>\n<p>\u591a\u7ebf\u7a0b\u7684\u60c5\u51b5\u4e0b\u901a\u5e38\u4f1a\u51fa\u73b0\u5171\u4eab\u4e00\u90e8\u5206\u8d44\u6e90\uff0c\u5f53\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u4fee\u6539\u8fd9\u4e00\u90e8\u5206\u5171\u4eab\u8d44\u6e90\u65f6\u5c31\u9700\u8981\u6709\u989d\u5916\u7684\u673a\u5236\u6765\u8fdb\u884c\u4fdd\u969c\uff0c\u5c31\u4f1a\u9020\u6210\u989d\u5916\u7684\u5f00\u9500<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302497\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>\u53e6\u5916\u4e00\u70b9\u5219\u662fI\/O\u591a\u8def\u590d\u7528\u6a21\u578b\uff0c\u5728\u4e0d\u4e86\u89e3\u539f\u7406\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u7c7b\u6bd4\u4e00\u4e2a\u5b9e\u4f8b\uff1a\u5728\u8bfe\u5802\u4e0a\u8ba9\u5168\u73ed30\u4e2a\u4eba\u540c\u65f6\u505a\u4f5c\u4e1a\uff0c\u505a\u5b8c\u540e\u8001\u5e08\u68c0\u67e5\uff0c30\u4e2a\u5b66\u751f\u7684\u4f5c\u4e1a\u90fd\u68c0\u67e5\u5b8c\u6210\u624d\u80fd\u4e0b\u8bfe\u3002\u5982\u4f55\u5728\u6709\u9650\u7684\u8d44\u6e90\u4e0b\uff0c\u4ee5\u6700\u5feb\u7684\u901f\u5ea6\u4e0b\u8bfe\u5462\uff1f<\/p>\n<p>\u7b2c\u4e00\u79cd\uff1a\u5b89\u6392\u4e00\u4e2a\u8001\u5e08\uff0c\u6309\u987a\u5e8f\u9010\u4e2a\u68c0\u67e5\u3002\u5148\u68c0\u67e5A\uff0c\u7136\u540e\u662fB\uff0c\u4e4b\u540e\u662fC\u3001D\u3002\u3002\u3002\u8fd9\u4e2d\u95f4\u5982\u679c\u6709\u4e00\u4e2a\u5b66\u751f\u5361\u4f4f\uff0c\u5168\u73ed\u90fd\u4f1a\u88ab\u803d\u8bef\u3002\u8fd9\u79cd\u6a21\u5f0f\u5c31\u597d\u6bd4\uff0c\u4f60\u7528\u5faa\u73af\u6328\u4e2a\u5904\u7406socket\uff0c\u6839\u672c\u4e0d\u5177\u6709\u5e76\u53d1\u80fd\u529b\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ea\u9700\u8981\u4e00\u4e2a\u8001\u5e08\uff0c\u4f46\u662f\u8017\u65f6\u65f6\u95f4\u4f1a\u6bd4\u8f83\u957f\u3002<\/p>\n<p>\u7b2c\u4e8c\u79cd\uff1a\u5b89\u639230\u4e2a\u8001\u5e08\uff0c\u6bcf\u4e2a\u8001\u5e08\u68c0\u67e5\u4e00\u4e2a\u5b66\u751f\u7684\u4f5c\u4e1a\u3002 \u8fd9\u79cd\u7c7b\u4f3c\u4e8e\u4e3a\u6bcf\u4e00\u4e2asocket\u521b\u5efa\u4e00\u4e2a\u8fdb\u7a0b\u6216\u8005\u7ebf\u7a0b\u5904\u7406\u8fde\u63a5\u3002\u8fd9\u79cd\u65b9\u5f0f\u9700\u898130\u4e2a\u8001\u5e08\uff08\u6700\u6d88\u8017\u8d44\u6e90\uff09\uff0c\u4f46\u662f\u901f\u5ea6\u6700\u5feb\u3002<\/p>\n<p>\u7b2c\u4e09\u79cd\uff1a\u5b89\u6392\u4e00\u4e2a\u8001\u5e08\uff0c\u7ad9\u5728\u8bb2\u53f0\u4e0a\uff0c\u8c01\u89e3\u7b54\u5b8c\u8c01\u4e3e\u624b\u3002\u8fd9\u65f6C\u3001D\u4e3e\u624b\uff0c\u8868\u793a\u4ed6\u4eec\u4f5c\u4e1a\u505a\u5b8c\u4e86\uff0c\u8001\u5e08\u4e0b\u53bb\u4f9d\u6b21\u68c0\u67e5C\u3001D\u7684\u7b54\u6848\uff0c\u7136\u540e\u7ee7\u7eed\u56de\u5230\u8bb2\u53f0\u4e0a\u7b49\u3002\u6b64\u65f6E\u3001A\u53c8\u4e3e\u624b\uff0c\u7136\u540e\u53bb\u5904\u7406E\u548cA\u3002\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u5728\u6700\u5c0f\u7684\u8d44\u6e90\u6d88\u8017\u7684\u60c5\u51b5\u4e0b\uff0c\u6700\u5feb\u7684\u5904\u7406\u5b8c\u4efb\u52a1\u3002<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302498\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>\u591a\u8defI\/O\u590d\u7528\u6280\u672f\u53ef\u4ee5\u8ba9\u5355\u4e2a\u7ebf\u7a0b\u9ad8\u6548\u7684\u5904\u7406\u591a\u4e2a\u8fde\u63a5\u8bf7\u6c42\uff0c\u800cRedis\u4f7f\u7528\u7528epoll\u4f5c\u4e3aI\/O\u591a\u8def\u590d\u7528\u6280\u672f\u7684\u5b9e\u73b0\u3002\u5e76\u4e14\uff0cRedis\u81ea\u8eab\u7684\u4e8b\u4ef6\u5904\u7406\u6a21\u578b\u5c06epoll\u4e2d\u7684\u8fde\u63a5\u3001\u8bfb\u5199\u3001\u5173\u95ed\u90fd\u8f6c\u6362\u4e3a\u4e8b\u4ef6\uff0c\u4e0d\u5728\u7f51\u7edcI\/O\u4e0a\u6d6a\u8d39\u8fc7\u591a\u7684\u65f6\u95f4\u3002<\/p>\n<p>5 \u4f7f\u7528\u573a\u666f<\/p>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042302499\" alt=\"\u56fe\u7247\" title=\"\u56fe\u7247\" loading=\"lazy\"><\/p>\n<p>6 \u53c2\u8003\u6587\u6863<br \/>DB-Engines Ranking\u00a0<a href=\"https:\/\/link.segmentfault.com\/?enc=k20MzZtpwYScVsMTHgCHTw%3D%3D.Q4lXBXrIE0oy1rUX3UWGR8OeL7%2BNWuRKJil7bz4JJpbHW695mYQbInEH8HnC367x\" rel=\"nofollow\">https:\/\/db-engines.com\/en\/ran&#8230;<\/a> benchmarks\u00a0<br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=zylvXjfvhtiId8C7MzesFA%3D%3D.3fXoEISNoS6sjI1U4wphXSaE%2FyeewNDXz8qYSlsOZ06qmDyGV54M96ktABCaEzL9\" rel=\"nofollow\">https:\/\/redis.io\/topics\/bench&#8230;<\/a>\u4e2d\u7684IO\u591a\u8def\u590d\u7528\u673a\u5236\u00a0<br \/><a href=\"https:\/\/link.segmentfault.com\/?enc=5S8qBWj8GeDWFwbybsyhww%3D%3D.swr5UPOy%2B6PaOQY82vgc54weXJMp%2B697ODeYpHvlXU%2BswtN9w537uQo6CK%2F4TCaXO4g0xH4CiufqIh363wLy4g%3D%3D\" rel=\"nofollow\">https:\/\/www.cnblogs.com\/reece&#8230;<\/a><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042302480\">https:\/\/segmentfault.com\/a\/1190000042302480<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148Redis\u662f\u4e00\u4e2a\u4f7f\u7528ANSI C\u7f16\u5199\u7684\u3001\u5f00\u6e90\u7684\u3001\u652f\u6301\u7f51\u7edc\u7684\u3001\u57fa\u4e8e\u5185\u5b58\u7684\u3001\u53ef\u9009\u6301\u4e45\u5316\u7684\u952e\u503c\u5bf9\u5b58\u50a8\u7cfb\u7edf\u3002 1  [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-10006172","post","type-post","status-publish","format-standard","hentry"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006172","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"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006172"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006172\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}