{"id":32398,"date":"2022-12-23T09:52:06","date_gmt":"2022-12-23T01:52:06","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=32398"},"modified":"2022-12-23T09:52:06","modified_gmt":"2022-12-23T01:52:06","slug":"redisvsmemcached","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/redisvsmemcached.html","title":{"rendered":"redis\u548cmemcached\u7684\u533a\u522b"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nRedis \u548c Memcache \u90fd\u662f\u57fa\u4e8e\u5185\u5b58\u7684\u6570\u636e\u5b58\u50a8\u7cfb\u7edf\u3002Memcached\u662f\u9ad8\u6027\u80fd\u5206\u5e03\u5f0f\u5185\u5b58\u7f13\u5b58\u670d\u52a1\uff1bRedis\u662f\u4e00\u4e2a\u5f00\u6e90\u7684key-value\u5b58\u50a8\u7cfb\u7edf\u3002\u4e0eMemcached\u7c7b\u4f3c\uff0cRedis\u5c06\u5927\u90e8\u5206\u6570\u636e\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u652f\u6301\u7684\u6570\u636e\u7c7b\u578b\u5305\u62ec\uff1a\u5b57\u7b26\u4e32\u3001\u54c8\u5e0c \u8868\u3001\u94fe\u8868\u3001\u7b49\u6570\u636e\u7c7b\u578b\u7684\u76f8\u5173\u64cd\u4f5c\u3002\u4e0b\u9762\u6211\u4eec\u6765\u8fdb\u884c\u6765\u770b\u4e00\u4e0bredis\u548cmemcached\u7684\u533a\u522b\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u6743\u5a01\u6bd4\u8f83<\/strong><\/div>\n

Redis\u7684\u4f5c\u8005Salvatore Sanfilippo\u66fe\u7ecf\u5bf9\u8fd9\u4e24\u79cd\u57fa\u4e8e\u5185\u5b58\u7684\u6570\u636e\u5b58\u50a8\u7cfb\u7edf\u8fdb\u884c\u8fc7\u6bd4\u8f83\uff1a<\/p>\n

    \n
  1. Redis\u652f\u6301\u670d\u52a1\u5668\u7aef\u7684\u6570\u636e\u64cd\u4f5c\uff1aRedis\u76f8\u6bd4Memcached\u6765\u8bf4\uff0c\u62e5\u6709\u66f4\u591a\u7684\u6570\u636e\u7ed3\u6784\u548c\u5e76\u652f\u6301\u66f4\u4e30\u5bcc\u7684\u6570\u636e\u64cd\u4f5c\uff0c\u901a\u5e38\u5728Memcached\u91cc\uff0c\u4f60\u9700\u8981\u5c06\u6570\u636e\u62ff\u5230\u5ba2\u6237\u7aef\u6765\u8fdb\u884c\u7c7b\u4f3c\u7684\u4fee\u6539\u518dset\u56de\u53bb\u3002\u8fd9\u5927\u5927\u589e\u52a0\u4e86\u7f51\u7edcIO\u7684\u6b21\u6570\u548c\u6570\u636e\u4f53\u79ef\u3002\u5728Redis\u4e2d\uff0c\u8fd9\u4e9b\u590d\u6742\u7684\u64cd\u4f5c\u901a\u5e38\u548c\u4e00\u822c\u7684GET\/SET\u4e00\u6837\u9ad8\u6548\u3002\u6240\u4ee5\uff0c\u5982\u679c\u9700\u8981\u7f13\u5b58\u80fd\u591f\u652f\u6301\u66f4\u590d\u6742\u7684\u7ed3\u6784\u548c\u64cd\u4f5c\uff0c\u90a3\u4e48Redis\u4f1a\u662f\u4e0d\u9519\u7684\u9009\u62e9\u3002<\/li>\n
  2. \u5185\u5b58\u4f7f\u7528\u6548\u7387\u5bf9\u6bd4\uff1a\u4f7f\u7528\u7b80\u5355\u7684key-value\u5b58\u50a8\u7684\u8bdd\uff0cMemcached\u7684\u5185\u5b58\u5229\u7528\u7387\u66f4\u9ad8\uff0c\u800c\u5982\u679cRedis\u91c7\u7528hash\u7ed3\u6784\u6765\u505akey-value\u5b58\u50a8\uff0c\u7531\u4e8e\u5176\u7ec4\u5408\u5f0f\u7684\u538b\u7f29\uff0c\u5176\u5185\u5b58\u5229\u7528\u7387\u4f1a\u9ad8\u4e8eMemcached\u3002<\/li>\n
  3. \u6027\u80fd\u5bf9\u6bd4\uff1a\u7531\u4e8eRedis\u53ea\u4f7f\u7528\u5355\u6838\uff0c\u800cMemcached\u53ef\u4ee5\u4f7f\u7528\u591a\u6838\uff0c\u6240\u4ee5\u5e73\u5747\u6bcf\u4e00\u4e2a\u6838\u4e0aRedis\u5728\u5b58\u50a8\u5c0f\u6570\u636e\u65f6\u6bd4Memcached\u6027\u80fd\u66f4\u9ad8\u3002\u800c\u5728100k\u4ee5\u4e0a\u7684\u6570\u636e\u4e2d\uff0cMemcached\u6027\u80fd\u8981\u9ad8\u4e8eRedis\uff0c\u867d\u7136Redis\u6700\u8fd1\u4e5f\u5728\u5b58\u50a8\u5927\u6570\u636e\u7684\u6027\u80fd\u4e0a\u8fdb\u884c\u4f18\u5316\uff0c\u4f46\u662f\u6bd4\u8d77Memcached\uff0c\u8fd8\u662f\u7a0d\u6709\u900a\u8272\u3002<\/li>\n<\/ol>\n

    \u5177\u4f53\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u4e0a\u9762\u7684\u7ed3\u8bba\uff0c\u4ee5\u4e0b\u4e3a\u6536\u96c6\u5230\u7684\u8d44\u6599\uff1a<\/p>\n

    1\u3001\u6570\u636e\u7c7b\u578b\u652f\u6301\u4e0d\u540c<\/strong><\/div>\n

    \u4e0eMemcached\u4ec5\u652f\u6301\u7b80\u5355\u7684key-value\u7ed3\u6784\u7684\u6570\u636e\u8bb0\u5f55\u4e0d\u540c\uff0cRedis\u652f\u6301\u7684\u6570\u636e\u7c7b\u578b\u8981\u4e30\u5bcc\u5f97\u591a\u3002\u6700\u4e3a\u5e38\u7528\u7684\u6570\u636e\u7c7b\u578b\u4e3b\u8981\u7531\u4e94\u79cd\uff1aString\u3001Hash\u3001List\u3001Set\u548cSorted Set\u3002Redis\u5185\u90e8\u4f7f\u7528\u4e00\u4e2aredisObject\u5bf9\u8c61\u6765\u8868\u793a\u6240\u6709\u7684key\u548cvalue\u3002redisObject\u6700\u4e3b\u8981\u7684\u4fe1\u606f\u5982\u56fe\u6240\u793a\uff1a<\/p>\n

    \"\"
    \n<\/a><\/p>\n

    type\u4ee3\u8868\u4e00\u4e2avalue\u5bf9\u8c61\u5177\u4f53\u662f\u4f55\u79cd\u6570\u636e\u7c7b\u578b\uff0cencoding\u662f\u4e0d\u540c\u6570\u636e\u7c7b\u578b\u5728redis\u5185\u90e8\u7684\u5b58\u50a8\u65b9\u5f0f\uff0c\u6bd4\u5982\uff1atype=string\u4ee3\u8868value\u5b58\u50a8\u7684\u662f\u4e00\u4e2a\u666e\u901a\u5b57\u7b26\u4e32\uff0c\u90a3\u4e48\u5bf9\u5e94\u7684encoding\u53ef\u4ee5\u662fraw\u6216\u8005\u662fint\uff0c\u5982\u679c\u662fint\u5219\u4ee3\u8868\u5b9e\u9645redis\u5185\u90e8\u662f\u6309\u6570\u503c\u578b\u7c7b\u5b58\u50a8\u548c\u8868\u793a\u8fd9\u4e2a\u5b57\u7b26\u4e32\u7684\uff0c\u5f53\u7136\u524d\u63d0\u662f\u8fd9\u4e2a\u5b57\u7b26\u4e32\u672c\u8eab\u53ef\u4ee5\u7528\u6570\u503c\u8868\u793a\uff0c\u6bd4\u5982:\u201d123\u2033 \u201c456\u201d\u8fd9\u6837\u7684\u5b57\u7b26\u4e32\u3002\u53ea\u6709\u6253\u5f00\u4e86Redis\u7684\u865a\u62df\u5185\u5b58\u529f\u80fd\uff0cvm\u5b57\u6bb5\u5b57\u6bb5\u624d\u4f1a\u771f\u6b63\u7684\u5206\u914d\u5185\u5b58\uff0c\u8be5\u529f\u80fd\u9ed8\u8ba4\u662f\u5173\u95ed\u72b6\u6001\u7684\u3002<\/p>\n

    1\uff09String<\/strong><\/span><\/div>\n

    \u5e38\u7528\u547d\u4ee4\uff1aset\/get\/decr\/incr\/mget\u7b49\uff1b<\/p>\n

    \u5e94\u7528\u573a\u666f\uff1aString\u662f\u6700\u5e38\u7528\u7684\u4e00\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u666e\u901a\u7684key\/value\u5b58\u50a8\u90fd\u53ef\u4ee5\u5f52\u4e3a\u6b64\u7c7b\uff1b<\/p>\n

    \u5b9e\u73b0\u65b9\u5f0f\uff1aString\u5728redis\u5185\u90e8\u5b58\u50a8\u9ed8\u8ba4\u5c31\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u88abredisObject\u6240\u5f15\u7528\uff0c\u5f53\u9047\u5230incr\u3001decr\u7b49\u64cd\u4f5c\u65f6\u4f1a\u8f6c\u6210\u6570\u503c\u578b\u8fdb\u884c\u8ba1\u7b97\uff0c\u6b64\u65f6redisObject\u7684encoding\u5b57\u6bb5\u4e3aint\u3002<\/p>\n

    2\uff09Hash<\/strong><\/span><\/div>\n

    \u5e38\u7528\u547d\u4ee4\uff1ahget\/hset\/hgetall\u7b49<\/p>\n

    \u5e94\u7528\u573a\u666f\uff1a\u6211\u4eec\u8981\u5b58\u50a8\u4e00\u4e2a\u7528\u6237\u4fe1\u606f\u5bf9\u8c61\u6570\u636e\uff0c\u5176\u4e2d\u5305\u62ec\u7528\u6237ID\u3001\u7528\u6237\u59d3\u540d\u3001\u5e74\u9f84\u548c\u751f\u65e5\uff0c\u901a\u8fc7\u7528\u6237ID\u6211\u4eec\u5e0c\u671b\u83b7\u53d6\u8be5\u7528\u6237\u7684\u59d3\u540d\u6216\u8005\u5e74\u9f84\u6216\u8005\u751f\u65e5\uff1b<\/p>\n

    \u5b9e\u73b0\u65b9\u5f0f\uff1aRedis\u7684Hash\u5b9e\u9645\u662f\u5185\u90e8\u5b58\u50a8\u7684Value\u4e3a\u4e00\u4e2aHashMap\uff0c\u5e76\u63d0\u4f9b\u4e86\u76f4\u63a5\u5b58\u53d6\u8fd9\u4e2aMap\u6210\u5458\u7684\u63a5\u53e3\u3002\u5982\u56fe\u6240\u793a\uff0cKey\u662f\u7528\u6237ID, value\u662f\u4e00\u4e2aMap\u3002\u8fd9\u4e2aMap\u7684key\u662f\u6210\u5458\u7684\u5c5e\u6027\u540d\uff0cvalue\u662f\u5c5e\u6027\u503c\u3002\u8fd9\u6837\u5bf9\u6570\u636e\u7684\u4fee\u6539\u548c\u5b58\u53d6\u90fd\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u5176\u5185\u90e8Map\u7684Key(Redis\u91cc\u79f0\u5185\u90e8Map\u7684key\u4e3afield), \u4e5f\u5c31\u662f\u901a\u8fc7 key(\u7528\u6237ID) + field(\u5c5e\u6027\u6807\u7b7e) \u5c31\u53ef\u4ee5\u64cd\u4f5c\u5bf9\u5e94\u5c5e\u6027\u6570\u636e\u3002\u5f53\u524dHashMap\u7684\u5b9e\u73b0\u6709\u4e24\u79cd\u65b9\u5f0f\uff1a\u5f53HashMap\u7684\u6210\u5458\u6bd4\u8f83\u5c11\u65f6Redis\u4e3a\u4e86\u8282\u7701\u5185\u5b58\u4f1a\u91c7\u7528\u7c7b\u4f3c\u4e00\u7ef4\u6570\u7ec4\u7684\u65b9\u5f0f\u6765\u7d27\u51d1\u5b58\u50a8\uff0c\u800c\u4e0d\u4f1a\u91c7\u7528\u771f\u6b63\u7684HashMap\u7ed3\u6784\uff0c\u8fd9\u65f6\u5bf9\u5e94\u7684value\u7684redisObject\u7684encoding\u4e3azipmap\uff0c\u5f53\u6210\u5458\u6570\u91cf\u589e\u5927\u65f6\u4f1a\u81ea\u52a8\u8f6c\u6210\u771f\u6b63\u7684HashMap,\u6b64\u65f6encoding\u4e3aht\u3002<\/p>\n

    \"\"<\/p>\n

    3\uff09List<\/strong><\/span><\/div>\n

    \u5e38\u7528\u547d\u4ee4\uff1alpush\/rpush\/lpop\/rpop\/lrange\u7b49\uff1b<\/p>\n

    \u5e94\u7528\u573a\u666f\uff1aRedis list\u7684\u5e94\u7528\u573a\u666f\u975e\u5e38\u591a\uff0c\u4e5f\u662fRedis\u6700\u91cd\u8981\u7684\u6570\u636e\u7ed3\u6784\u4e4b\u4e00\uff0c\u6bd4\u5982twitter\u7684\u5173\u6ce8\u5217\u8868\uff0c\u7c89\u4e1d\u5217\u8868\u7b49\u90fd\u53ef\u4ee5\u7528Redis\u7684list\u7ed3\u6784\u6765\u5b9e\u73b0\uff1b<\/p>\n

    \u5b9e\u73b0\u65b9\u5f0f\uff1aRedis list\u7684\u5b9e\u73b0\u4e3a\u4e00\u4e2a\u53cc\u5411\u94fe\u8868\uff0c\u5373\u53ef\u4ee5\u652f\u6301\u53cd\u5411\u67e5\u627e\u548c\u904d\u5386\uff0c\u66f4\u65b9\u4fbf\u64cd\u4f5c\uff0c\u4e0d\u8fc7\u5e26\u6765\u4e86\u90e8\u5206\u989d\u5916\u7684\u5185\u5b58\u5f00\u9500\uff0cRedis\u5185\u90e8\u7684\u5f88\u591a\u5b9e\u73b0\uff0c\u5305\u62ec\u53d1\u9001\u7f13\u51b2\u961f\u5217\u7b49\u4e5f\u90fd\u662f\u7528\u7684\u8fd9\u4e2a\u6570\u636e\u7ed3\u6784\u3002<\/p>\n

    4\uff09Set<\/strong><\/span><\/div>\n

    \u5e38\u7528\u547d\u4ee4\uff1asadd\/spop\/smembers\/sunion\u7b49\uff1b<\/p>\n

    \u5e94\u7528\u573a\u666f\uff1aRedis set\u5bf9\u5916\u63d0\u4f9b\u7684\u529f\u80fd\u4e0elist\u7c7b\u4f3c\u662f\u4e00\u4e2a\u5217\u8868\u7684\u529f\u80fd\uff0c\u7279\u6b8a\u4e4b\u5904\u5728\u4e8eset\u662f\u53ef\u4ee5\u81ea\u52a8\u6392\u91cd\u7684\uff0c\u5f53\u4f60\u9700\u8981\u5b58\u50a8\u4e00\u4e2a\u5217\u8868\u6570\u636e\uff0c\u53c8\u4e0d\u5e0c\u671b\u51fa\u73b0\u91cd\u590d\u6570\u636e\u65f6\uff0cset\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u9009\u62e9\uff0c\u5e76\u4e14set\u63d0\u4f9b\u4e86\u5224\u65ad\u67d0\u4e2a\u6210\u5458\u662f\u5426\u5728\u4e00\u4e2aset\u96c6\u5408\u5185\u7684\u91cd\u8981\u63a5\u53e3\uff0c\u8fd9\u4e2a\u4e5f\u662flist\u6240\u4e0d\u80fd\u63d0\u4f9b\u7684\uff1b<\/p>\n

    \u5b9e\u73b0\u65b9\u5f0f\uff1aset \u7684\u5185\u90e8\u5b9e\u73b0\u662f\u4e00\u4e2a value\u6c38\u8fdc\u4e3anull\u7684HashMap\uff0c\u5b9e\u9645\u5c31\u662f\u901a\u8fc7\u8ba1\u7b97hash\u7684\u65b9\u5f0f\u6765\u5feb\u901f\u6392\u91cd\u7684\uff0c\u8fd9\u4e5f\u662fset\u80fd\u63d0\u4f9b\u5224\u65ad\u4e00\u4e2a\u6210\u5458\u662f\u5426\u5728\u96c6\u5408\u5185\u7684\u539f\u56e0\u3002<\/p>\n

    5\uff09Sorted Set<\/strong><\/span><\/div>\n

    \u5e38\u7528\u547d\u4ee4\uff1azadd\/zrange\/zrem\/zcard\u7b49\uff1b<\/p>\n

    \u5e94\u7528\u573a\u666f\uff1aRedis sorted set\u7684\u4f7f\u7528\u573a\u666f\u4e0eset\u7c7b\u4f3c\uff0c\u533a\u522b\u662fset\u4e0d\u662f\u81ea\u52a8\u6709\u5e8f\u7684\uff0c\u800csorted set\u53ef\u4ee5\u901a\u8fc7\u7528\u6237\u989d\u5916\u63d0\u4f9b\u4e00\u4e2a\u4f18\u5148\u7ea7(score)\u7684\u53c2\u6570\u6765\u4e3a\u6210\u5458\u6392\u5e8f\uff0c\u5e76\u4e14\u662f\u63d2\u5165\u6709\u5e8f\u7684\uff0c\u5373\u81ea\u52a8\u6392\u5e8f\u3002\u5f53\u4f60\u9700\u8981\u4e00\u4e2a\u6709\u5e8f\u7684\u5e76\u4e14\u4e0d\u91cd\u590d\u7684\u96c6\u5408\u5217\u8868\uff0c\u90a3\u4e48\u53ef\u4ee5\u9009\u62e9sorted set\u6570\u636e\u7ed3\u6784\uff0c\u6bd4\u5982twitter \u7684public timeline\u53ef\u4ee5\u4ee5\u53d1\u8868\u65f6\u95f4\u4f5c\u4e3ascore\u6765\u5b58\u50a8\uff0c\u8fd9\u6837\u83b7\u53d6\u65f6\u5c31\u662f\u81ea\u52a8\u6309\u65f6\u95f4\u6392\u597d\u5e8f\u7684\u3002<\/p>\n

    \u5b9e\u73b0\u65b9\u5f0f\uff1aRedis sorted set\u7684\u5185\u90e8\u4f7f\u7528HashMap\u548c\u8df3\u8dc3\u8868(SkipList)\u6765\u4fdd\u8bc1\u6570\u636e\u7684\u5b58\u50a8\u548c\u6709\u5e8f\uff0cHashMap\u91cc\u653e\u7684\u662f\u6210\u5458\u5230score\u7684\u6620\u5c04\uff0c\u800c\u8df3\u8dc3\u8868\u91cc\u5b58\u653e\u7684\u662f\u6240\u6709\u7684\u6210\u5458\uff0c\u6392\u5e8f\u4f9d\u636e\u662fHashMap\u91cc\u5b58\u7684score,\u4f7f\u7528\u8df3\u8dc3\u8868\u7684\u7ed3\u6784\u53ef\u4ee5\u83b7\u5f97\u6bd4\u8f83\u9ad8\u7684\u67e5\u627e\u6548\u7387\uff0c\u5e76\u4e14\u5728\u5b9e\u73b0\u4e0a\u6bd4\u8f83\u7b80\u5355\u3002<\/p>\n

    2\u3001\u5185\u5b58\u7ba1\u7406\u673a\u5236\u4e0d\u540c<\/strong><\/div>\n

    \u5728Redis\u4e2d\uff0c\u5e76\u4e0d\u662f\u6240\u6709\u7684\u6570\u636e\u90fd\u4e00\u76f4\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u7684\u3002\u8fd9\u662f\u548cMemcached\u76f8\u6bd4\u4e00\u4e2a\u6700\u5927\u7684\u533a\u522b\u3002\u5f53\u7269\u7406\u5185\u5b58\u7528\u5b8c\u65f6\uff0cRedis\u53ef\u4ee5\u5c06\u4e00\u4e9b\u5f88\u4e45\u6ca1\u7528\u5230\u7684value\u4ea4\u6362\u5230\u78c1\u76d8\u3002Redis\u53ea\u4f1a\u7f13\u5b58\u6240\u6709\u7684key\u7684\u4fe1\u606f\uff0c\u5982\u679cRedis\u53d1\u73b0\u5185\u5b58\u7684\u4f7f\u7528\u91cf\u8d85\u8fc7\u4e86\u67d0\u4e00\u4e2a\u9600\u503c\uff0c\u5c06\u89e6\u53d1swap\u7684\u64cd\u4f5c\uff0cRedis\u6839\u636e\u201cswappability = age*log(size_in_memory)\u201d\u8ba1\u7b97\u51fa\u54ea\u4e9bkey\u5bf9\u5e94\u7684value\u9700\u8981swap\u5230\u78c1\u76d8\u3002\u7136\u540e\u518d\u5c06\u8fd9\u4e9bkey\u5bf9\u5e94\u7684value\u6301\u4e45\u5316\u5230\u78c1\u76d8\u4e2d\uff0c\u540c\u65f6\u5728\u5185\u5b58\u4e2d\u6e05\u9664\u3002\u8fd9\u79cd\u7279\u6027\u4f7f\u5f97Redis\u53ef\u4ee5\u4fdd\u6301\u8d85\u8fc7\u5176\u673a\u5668\u672c\u8eab\u5185\u5b58\u5927\u5c0f\u7684\u6570\u636e\u3002\u5f53\u7136\uff0c\u673a\u5668\u672c\u8eab\u7684\u5185\u5b58\u5fc5\u987b\u8981\u80fd\u591f\u4fdd\u6301\u6240\u6709\u7684key\uff0c\u6bd5\u7adf\u8fd9\u4e9b\u6570\u636e\u662f\u4e0d\u4f1a\u8fdb\u884cswap\u64cd\u4f5c\u7684\u3002\u540c\u65f6\u7531\u4e8eRedis\u5c06\u5185\u5b58\u4e2d\u7684\u6570\u636eswap\u5230\u78c1\u76d8\u4e2d\u7684\u65f6\u5019\uff0c\u63d0\u4f9b\u670d\u52a1\u7684\u4e3b\u7ebf\u7a0b\u548c\u8fdb\u884cswap\u64cd\u4f5c\u7684\u5b50\u7ebf\u7a0b\u4f1a\u5171\u4eab\u8fd9\u90e8\u5206\u5185\u5b58\uff0c\u6240\u4ee5\u5982\u679c\u66f4\u65b0\u9700\u8981swap\u7684\u6570\u636e\uff0cRedis\u5c06\u963b\u585e\u8fd9\u4e2a\u64cd\u4f5c\uff0c\u76f4\u5230\u5b50\u7ebf\u7a0b\u5b8c\u6210swap\u64cd\u4f5c\u540e\u624d\u53ef\u4ee5\u8fdb\u884c\u4fee\u6539\u3002\u5f53\u4eceRedis\u4e2d\u8bfb\u53d6\u6570\u636e\u7684\u65f6\u5019\uff0c\u5982\u679c\u8bfb\u53d6\u7684key\u5bf9\u5e94\u7684value\u4e0d\u5728\u5185\u5b58\u4e2d\uff0c\u90a3\u4e48Redis\u5c31\u9700\u8981\u4eceswap\u6587\u4ef6\u4e2d\u52a0\u8f7d\u76f8\u5e94\u6570\u636e\uff0c\u7136\u540e\u518d\u8fd4\u56de\u7ed9\u8bf7\u6c42\u65b9\u3002 \u8fd9\u91cc\u5c31\u5b58\u5728\u4e00\u4e2aI\/O\u7ebf\u7a0b\u6c60\u7684\u95ee\u9898\u3002\u5728\u9ed8\u8ba4\u7684\u60c5\u51b5\u4e0b\uff0cRedis\u4f1a\u51fa\u73b0\u963b\u585e\uff0c\u5373\u5b8c\u6210\u6240\u6709\u7684swap\u6587\u4ef6\u52a0\u8f7d\u540e\u624d\u4f1a\u76f8\u5e94\u3002\u8fd9\u79cd\u7b56\u7565\u5728\u5ba2\u6237\u7aef\u7684\u6570\u91cf\u8f83\u5c0f\uff0c\u8fdb\u884c\u6279\u91cf\u64cd\u4f5c\u7684\u65f6\u5019\u6bd4\u8f83\u5408\u9002\u3002\u4f46\u662f\u5982\u679c\u5c06Redis\u5e94\u7528\u5728\u4e00\u4e2a\u5927\u578b\u7684\u7f51\u7ad9\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u8fd9\u663e\u7136\u662f\u65e0\u6cd5\u6ee1\u8db3\u5927\u5e76\u53d1\u7684\u60c5\u51b5\u7684\u3002\u6240\u4ee5Redis\u8fd0\u884c\u6211\u4eec\u8bbe\u7f6eI\/O\u7ebf\u7a0b\u6c60\u7684\u5927\u5c0f\uff0c\u5bf9\u9700\u8981\u4eceswap\u6587\u4ef6\u4e2d\u52a0\u8f7d\u76f8\u5e94\u6570\u636e\u7684\u8bfb\u53d6\u8bf7\u6c42\u8fdb\u884c\u5e76\u53d1\u64cd\u4f5c\uff0c\u51cf\u5c11\u963b\u585e\u7684\u65f6\u95f4\u3002<\/p>\n

    \u5bf9\u4e8e\u50cfRedis\u548cMemcached\u8fd9\u79cd\u57fa\u4e8e\u5185\u5b58\u7684\u6570\u636e\u5e93\u7cfb\u7edf\u6765\u8bf4\uff0c\u5185\u5b58\u7ba1\u7406\u7684\u6548\u7387\u9ad8\u4f4e\u662f\u5f71\u54cd\u7cfb\u7edf\u6027\u80fd\u7684\u5173\u952e\u56e0\u7d20\u3002\u4f20\u7edfC\u8bed\u8a00\u4e2d\u7684malloc\/free\u51fd\u6570\u662f\u6700\u5e38\u7528\u7684\u5206\u914d\u548c\u91ca\u653e\u5185\u5b58\u7684\u65b9\u6cd5\uff0c\u4f46\u662f\u8fd9\u79cd\u65b9\u6cd5\u5b58\u5728\u7740\u5f88\u5927\u7684\u7f3a\u9677\uff1a\u9996\u5148\uff0c\u5bf9\u4e8e\u5f00\u53d1\u4eba\u5458\u6765\u8bf4\u4e0d\u5339\u914d\u7684malloc\u548cfree\u5bb9\u6613\u9020\u6210\u5185\u5b58\u6cc4\u9732\uff1b\u5176\u6b21\u9891\u7e41\u8c03\u7528\u4f1a\u9020\u6210\u5927\u91cf\u5185\u5b58\u788e\u7247\u65e0\u6cd5\u56de\u6536\u91cd\u65b0\u5229\u7528\uff0c\u964d\u4f4e\u5185\u5b58\u5229\u7528\u7387\uff1b\u6700\u540e\u4f5c\u4e3a\u7cfb\u7edf\u8c03\u7528\uff0c\u5176\u7cfb\u7edf\u5f00\u9500\u8fdc\u8fdc\u5927\u4e8e\u4e00\u822c\u51fd\u6570\u8c03\u7528\u3002\u6240\u4ee5\uff0c\u4e3a\u4e86\u63d0\u9ad8\u5185\u5b58\u7684\u7ba1\u7406\u6548\u7387\uff0c\u9ad8\u6548\u7684\u5185\u5b58\u7ba1\u7406\u65b9\u6848\u90fd\u4e0d\u4f1a\u76f4\u63a5\u4f7f\u7528malloc\/free\u8c03\u7528\u3002Redis\u548cMemcached\u5747\u4f7f\u7528\u4e86\u81ea\u8eab\u8bbe\u8ba1\u7684\u5185\u5b58\u7ba1\u7406\u673a\u5236\uff0c\u4f46\u662f\u5b9e\u73b0\u65b9\u6cd5\u5b58\u5728\u5f88\u5927\u7684\u5dee\u5f02\uff0c\u4e0b\u9762\u5c06\u4f1a\u5bf9\u4e24\u8005\u7684\u5185\u5b58\u7ba1\u7406\u673a\u5236\u5206\u522b\u8fdb\u884c\u4ecb\u7ecd\u3002<\/p>\n

    Memcached\u9ed8\u8ba4\u4f7f\u7528Slab Allocation\u673a\u5236\u7ba1\u7406\u5185\u5b58\uff0c\u5176\u4e3b\u8981\u601d\u60f3\u662f\u6309\u7167\u9884\u5148\u89c4\u5b9a\u7684\u5927\u5c0f\uff0c\u5c06\u5206\u914d\u7684\u5185\u5b58\u5206\u5272\u6210\u7279\u5b9a\u957f\u5ea6\u7684\u5757\u4ee5\u5b58\u50a8\u76f8\u5e94\u957f\u5ea6\u7684key-value\u6570\u636e\u8bb0\u5f55\uff0c\u4ee5\u5b8c\u5168\u89e3\u51b3\u5185\u5b58\u788e\u7247\u95ee\u9898\u3002Slab Allocation\u673a\u5236\u53ea\u4e3a\u5b58\u50a8\u5916\u90e8\u6570\u636e\u800c\u8bbe\u8ba1\uff0c\u4e5f\u5c31\u662f\u8bf4\u6240\u6709\u7684key-value\u6570\u636e\u90fd\u5b58\u50a8\u5728Slab Allocation\u7cfb\u7edf\u91cc\uff0c\u800cMemcached\u7684\u5176\u5b83\u5185\u5b58\u8bf7\u6c42\u5219\u901a\u8fc7\u666e\u901a\u7684malloc\/free\u6765\u7533\u8bf7\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u8bf7\u6c42\u7684\u6570\u91cf\u548c\u9891\u7387\u51b3\u5b9a\u4e86\u5b83\u4eec\u4e0d\u4f1a\u5bf9\u6574\u4e2a\u7cfb\u7edf\u7684\u6027\u80fd\u9020\u6210\u5f71\u54cdSlab Allocation\u7684\u539f\u7406\u76f8\u5f53\u7b80\u5355\u3002 \u5982\u56fe\u6240\u793a\uff0c\u5b83\u9996\u5148\u4ece\u64cd\u4f5c\u7cfb\u7edf\u7533\u8bf7\u4e00\u5927\u5757\u5185\u5b58\uff0c\u5e76\u5c06\u5176\u5206\u5272\u6210\u5404\u79cd\u5c3a\u5bf8\u7684\u5757Chunk\uff0c\u5e76\u628a\u5c3a\u5bf8\u76f8\u540c\u7684\u5757\u5206\u6210\u7ec4Slab Class\u3002\u5176\u4e2d\uff0cChunk\u5c31\u662f\u7528\u6765\u5b58\u50a8key-value\u6570\u636e\u7684\u6700\u5c0f\u5355\u4f4d\u3002\u6bcf\u4e2aSlab Class\u7684\u5927\u5c0f\uff0c\u53ef\u4ee5\u5728Memcached\u542f\u52a8\u7684\u65f6\u5019\u901a\u8fc7\u5236\u5b9aGrowth Factor\u6765\u63a7\u5236\u3002\u5047\u5b9a\u56fe\u4e2dGrowth Factor\u7684\u53d6\u503c\u4e3a1.25\uff0c\u5982\u679c\u7b2c\u4e00\u7ec4Chunk\u7684\u5927\u5c0f\u4e3a88\u4e2a\u5b57\u8282\uff0c\u7b2c\u4e8c\u7ec4Chunk\u7684\u5927\u5c0f\u5c31\u4e3a112\u4e2a\u5b57\u8282\uff0c\u4f9d\u6b64\u7c7b\u63a8\u3002<\/p>\n

    \"\"<\/p>\n

    \u5f53Memcached\u63a5\u6536\u5230\u5ba2\u6237\u7aef\u53d1\u9001\u8fc7\u6765\u7684\u6570\u636e\u65f6\u9996\u5148\u4f1a\u6839\u636e\u6536\u5230\u6570\u636e\u7684\u5927\u5c0f\u9009\u62e9\u4e00\u4e2a\u6700\u5408\u9002\u7684Slab Class\uff0c\u7136\u540e\u901a\u8fc7\u67e5\u8be2Memcached\u4fdd\u5b58\u7740\u7684\u8be5Slab Class\u5185\u7a7a\u95f2Chunk\u7684\u5217\u8868\u5c31\u53ef\u4ee5\u627e\u5230\u4e00\u4e2a\u53ef\u7528\u4e8e\u5b58\u50a8\u6570\u636e\u7684Chunk\u3002\u5f53\u4e00\u6761\u6570\u636e\u5e93\u8fc7\u671f\u6216\u8005\u4e22\u5f03\u65f6\uff0c\u8be5\u8bb0\u5f55\u6240\u5360\u7528\u7684Chunk\u5c31\u53ef\u4ee5\u56de\u6536\uff0c\u91cd\u65b0\u6dfb\u52a0\u5230\u7a7a\u95f2\u5217\u8868\u4e2d\u3002<\/p>\n

    \u4ece\u4ee5\u4e0a\u8fc7\u7a0b\u6211\u4eec\u53ef\u4ee5\u770b\u51faMemcached\u7684\u5185\u5b58\u7ba1\u7406\u5236\u6548\u7387\u9ad8\uff0c\u800c\u4e14\u4e0d\u4f1a\u9020\u6210\u5185\u5b58\u788e\u7247\uff0c\u4f46\u662f\u5b83\u6700\u5927\u7684\u7f3a\u70b9\u5c31\u662f\u4f1a\u5bfc\u81f4\u7a7a\u95f4\u6d6a\u8d39\u3002\u56e0\u4e3a\u6bcf\u4e2aChunk\u90fd\u5206\u914d\u4e86\u7279\u5b9a\u957f\u5ea6\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u6240\u4ee5\u53d8\u957f\u6570\u636e\u65e0\u6cd5\u5145\u5206\u5229\u7528\u8fd9\u4e9b\u7a7a\u95f4\u3002\u5982\u56fe \u6240\u793a\uff0c\u5c06100\u4e2a\u5b57\u8282\u7684\u6570\u636e\u7f13\u5b58\u5230128\u4e2a\u5b57\u8282\u7684Chunk\u4e2d\uff0c\u5269\u4f59\u768428\u4e2a\u5b57\u8282\u5c31\u6d6a\u8d39\u6389\u4e86\u3002<\/p>\n

    \"\"<\/p>\n

    Redis\u7684\u5185\u5b58\u7ba1\u7406\u4e3b\u8981\u901a\u8fc7\u6e90\u7801\u4e2dzmalloc.h\u548czmalloc.c\u4e24\u4e2a\u6587\u4ef6\u6765\u5b9e\u73b0\u7684\u3002Redis\u4e3a\u4e86\u65b9\u4fbf\u5185\u5b58\u7684\u7ba1\u7406\uff0c\u5728\u5206\u914d\u4e00\u5757\u5185\u5b58\u4e4b\u540e\uff0c\u4f1a\u5c06\u8fd9\u5757\u5185\u5b58\u7684\u5927\u5c0f\u5b58\u5165\u5185\u5b58\u5757\u7684\u5934\u90e8\u3002\u5982\u56fe\u6240\u793a\uff0creal_ptr\u662fredis\u8c03\u7528malloc\u540e\u8fd4\u56de\u7684\u6307\u9488\u3002redis\u5c06\u5185\u5b58\u5757\u7684\u5927\u5c0fsize\u5b58\u5165\u5934\u90e8\uff0csize\u6240\u5360\u636e\u7684\u5185\u5b58\u5927\u5c0f\u662f\u5df2\u77e5\u7684\uff0c\u4e3asize_t\u7c7b\u578b\u7684\u957f\u5ea6\uff0c\u7136\u540e\u8fd4\u56deret_ptr\u3002\u5f53\u9700\u8981\u91ca\u653e\u5185\u5b58\u7684\u65f6\u5019\uff0cret_ptr\u88ab\u4f20\u7ed9\u5185\u5b58\u7ba1\u7406\u7a0b\u5e8f\u3002\u901a\u8fc7ret_ptr\uff0c\u7a0b\u5e8f\u53ef\u4ee5\u5f88\u5bb9\u6613\u7684\u7b97\u51fareal_ptr\u7684\u503c\uff0c\u7136\u540e\u5c06real_ptr\u4f20\u7ed9free\u91ca\u653e\u5185\u5b58\u3002<\/p>\n

    \"\"<\/p>\n

    Redis\u901a\u8fc7\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4\u6765\u8bb0\u5f55\u6240\u6709\u7684\u5185\u5b58\u5206\u914d\u60c5\u51b5\uff0c\u8fd9\u4e2a\u6570\u7ec4\u7684\u957f\u5ea6\u4e3aZMALLOC_MAX_ALLOC_STAT\u3002\u6570\u7ec4\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\u4ee3\u8868\u5f53\u524d\u7a0b\u5e8f\u6240\u5206\u914d\u7684\u5185\u5b58\u5757\u7684\u4e2a\u6570\uff0c\u4e14\u5185\u5b58\u5757\u7684\u5927\u5c0f\u4e3a\u8be5\u5143\u7d20\u7684\u4e0b\u6807\u3002\u5728\u6e90\u7801\u4e2d\uff0c\u8fd9\u4e2a\u6570\u7ec4\u4e3azmalloc_allocations\u3002zmalloc_allocations[16]\u4ee3\u8868\u5df2\u7ecf\u5206\u914d\u7684\u957f\u5ea6\u4e3a16bytes\u7684\u5185\u5b58\u5757\u7684\u4e2a\u6570\u3002zmalloc.c\u4e2d\u6709\u4e00\u4e2a\u9759\u6001\u53d8\u91cfused_memory\u7528\u6765\u8bb0\u5f55\u5f53\u524d\u5206\u914d\u7684\u5185\u5b58\u603b\u5927\u5c0f\u3002\u6240\u4ee5\uff0c\u603b\u7684\u6765\u770b\uff0cRedis\u91c7\u7528\u7684\u662f\u5305\u88c5\u7684mallc\/free\uff0c\u76f8\u8f83\u4e8eMemcached\u7684\u5185\u5b58\u7ba1\u7406\u65b9\u6cd5\u6765\u8bf4\uff0c\u8981\u7b80\u5355\u5f88\u591a\u3002<\/p>\n

    3\u3001\u6570\u636e\u6301\u4e45\u5316\u652f\u6301<\/strong><\/div>\n

    Redis\u867d\u7136\u662f\u57fa\u4e8e\u5185\u5b58\u7684\u5b58\u50a8\u7cfb\u7edf\uff0c\u4f46\u662f\u5b83\u672c\u8eab\u662f\u652f\u6301\u5185\u5b58\u6570\u636e\u7684\u6301\u4e45\u5316\u7684\uff0c\u800c\u4e14\u63d0\u4f9b\u4e24\u79cd\u4e3b\u8981\u7684\u6301\u4e45\u5316\u7b56\u7565\uff1aRDB\u5feb\u7167\u548cAOF\u65e5\u5fd7\u3002\u800cmemcached\u662f\u4e0d\u652f\u6301\u6570\u636e\u6301\u4e45\u5316\u64cd\u4f5c\u7684\u3002<\/p>\n

    1\uff09RDB\u5feb\u7167<\/strong><\/span><\/div>\n

    Redis\u652f\u6301\u5c06\u5f53\u524d\u6570\u636e\u7684\u5feb\u7167\u5b58\u6210\u4e00\u4e2a\u6570\u636e\u6587\u4ef6\u7684\u6301\u4e45\u5316\u673a\u5236\uff0c\u5373RDB\u5feb\u7167\u3002\u4f46\u662f\u4e00\u4e2a\u6301\u7eed\u5199\u5165\u7684\u6570\u636e\u5e93\u5982\u4f55\u751f\u6210\u5feb\u7167\u5462\uff1fRedis\u501f\u52a9\u4e86fork\u547d\u4ee4\u7684copy on write\u673a\u5236\u3002\u5728\u751f\u6210\u5feb\u7167\u65f6\uff0c\u5c06\u5f53\u524d\u8fdb\u7a0bfork\u51fa\u4e00\u4e2a\u5b50\u8fdb\u7a0b\uff0c\u7136\u540e\u5728\u5b50\u8fdb\u7a0b\u4e2d\u5faa\u73af\u6240\u6709\u7684\u6570\u636e\uff0c\u5c06\u6570\u636e\u5199\u6210\u4e3aRDB\u6587\u4ef6\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7Redis\u7684save\u6307\u4ee4\u6765\u914d\u7f6eRDB\u5feb\u7167\u751f\u6210\u7684\u65f6\u673a\uff0c\u6bd4\u5982\u914d\u7f6e10\u5206\u949f\u5c31\u751f\u6210\u5feb\u7167\uff0c\u4e5f\u53ef\u4ee5\u914d\u7f6e\u67091000\u6b21\u5199\u5165\u5c31\u751f\u6210\u5feb\u7167\uff0c\u4e5f\u53ef\u4ee5\u591a\u4e2a\u89c4\u5219\u4e00\u8d77\u5b9e\u65bd\u3002\u8fd9\u4e9b\u89c4\u5219\u7684\u5b9a\u4e49\u5c31\u5728Redis\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7Redis\u7684CONFIG SET\u547d\u4ee4\u5728Redis\u8fd0\u884c\u65f6\u8bbe\u7f6e\u89c4\u5219\uff0c\u4e0d\u9700\u8981\u91cd\u542fRedis\u3002<\/p>\n

    Redis\u7684RDB\u6587\u4ef6\u4e0d\u4f1a\u574f\u6389\uff0c\u56e0\u4e3a\u5176\u5199\u64cd\u4f5c\u662f\u5728\u4e00\u4e2a\u65b0\u8fdb\u7a0b\u4e2d\u8fdb\u884c\u7684\uff0c\u5f53\u751f\u6210\u4e00\u4e2a\u65b0\u7684RDB\u6587\u4ef6\u65f6\uff0cRedis\u751f\u6210\u7684\u5b50\u8fdb\u7a0b\u4f1a\u5148\u5c06\u6570\u636e\u5199\u5230\u4e00\u4e2a\u4e34\u65f6\u6587\u4ef6\u4e2d\uff0c\u7136\u540e\u901a\u8fc7\u539f\u5b50\u6027rename\u7cfb\u7edf\u8c03\u7528\u5c06\u4e34\u65f6\u6587\u4ef6\u91cd\u547d\u540d\u4e3aRDB\u6587\u4ef6\uff0c\u8fd9\u6837\u5728\u4efb\u4f55\u65f6\u5019\u51fa\u73b0\u6545\u969c\uff0cRedis\u7684RDB\u6587\u4ef6\u90fd\u603b\u662f\u53ef\u7528\u7684\u3002\u540c\u65f6\uff0cRedis\u7684RDB\u6587\u4ef6\u4e5f\u662fRedis\u4e3b\u4ece\u540c\u6b65\u5185\u90e8\u5b9e\u73b0\u4e2d\u7684\u4e00\u73af\u3002RDB\u6709\u4ed6\u7684\u4e0d\u8db3\uff0c\u5c31\u662f\u4e00\u65e6\u6570\u636e\u5e93\u51fa\u73b0\u95ee\u9898\uff0c\u90a3\u4e48\u6211\u4eec\u7684RDB\u6587\u4ef6\u4e2d\u4fdd\u5b58\u7684\u6570\u636e\u5e76\u4e0d\u662f\u5168\u65b0\u7684\uff0c\u4ece\u4e0a\u6b21RDB\u6587\u4ef6\u751f\u6210\u5230Redis\u505c\u673a\u8fd9\u6bb5\u65f6\u95f4\u7684\u6570\u636e\u5168\u90e8\u4e22\u6389\u4e86\u3002\u5728\u67d0\u4e9b\u4e1a\u52a1\u4e0b\uff0c\u8fd9\u662f\u53ef\u4ee5\u5fcd\u53d7\u7684\u3002<\/p>\n

    2\uff09AOF\u65e5\u5fd7<\/strong><\/span><\/div>\n

    AOF\u65e5\u5fd7\u7684\u5168\u79f0\u662fappend only file\uff0c\u5b83\u662f\u4e00\u4e2a\u8ffd\u52a0\u5199\u5165\u7684\u65e5\u5fd7\u6587\u4ef6\u3002\u4e0e\u4e00\u822c\u6570\u636e\u5e93\u7684binlog\u4e0d\u540c\u7684\u662f\uff0cAOF\u6587\u4ef6\u662f\u53ef\u8bc6\u522b\u7684\u7eaf\u6587\u672c\uff0c\u5b83\u7684\u5185\u5bb9\u5c31\u662f\u4e00\u4e2a\u4e2a\u7684Redis\u6807\u51c6\u547d\u4ee4\u3002\u53ea\u6709\u90a3\u4e9b\u4f1a\u5bfc\u81f4\u6570\u636e\u53d1\u751f\u4fee\u6539\u7684\u547d\u4ee4\u624d\u4f1a\u8ffd\u52a0\u5230AOF\u6587\u4ef6\u3002\u6bcf\u4e00\u6761\u4fee\u6539\u6570\u636e\u7684\u547d\u4ee4\u90fd\u751f\u6210\u4e00\u6761\u65e5\u5fd7\uff0cAOF\u6587\u4ef6\u4f1a\u8d8a\u6765\u8d8a\u5927\uff0c\u6240\u4ee5Redis\u53c8\u63d0\u4f9b\u4e86\u4e00\u4e2a\u529f\u80fd\uff0c\u53eb\u505aAOF rewrite\u3002\u5176\u529f\u80fd\u5c31\u662f\u91cd\u65b0\u751f\u6210\u4e00\u4efdAOF\u6587\u4ef6\uff0c\u65b0\u7684AOF\u6587\u4ef6\u4e2d\u4e00\u6761\u8bb0\u5f55\u7684\u64cd\u4f5c\u53ea\u4f1a\u6709\u4e00\u6b21\uff0c\u800c\u4e0d\u50cf\u4e00\u4efd\u8001\u6587\u4ef6\u90a3\u6837\uff0c\u53ef\u80fd\u8bb0\u5f55\u4e86\u5bf9\u540c\u4e00\u4e2a\u503c\u7684\u591a\u6b21\u64cd\u4f5c\u3002\u5176\u751f\u6210\u8fc7\u7a0b\u548cRDB\u7c7b\u4f3c\uff0c\u4e5f\u662ffork\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u76f4\u63a5\u904d\u5386\u6570\u636e\uff0c\u5199\u5165\u65b0\u7684AOF\u4e34\u65f6\u6587\u4ef6\u3002\u5728\u5199\u5165\u65b0\u6587\u4ef6\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6240\u6709\u7684\u5199\u64cd\u4f5c\u65e5\u5fd7\u8fd8\u662f\u4f1a\u5199\u5230\u539f\u6765\u8001\u7684AOF\u6587\u4ef6\u4e2d\uff0c\u540c\u65f6\u8fd8\u4f1a\u8bb0\u5f55\u5728\u5185\u5b58\u7f13\u51b2\u533a\u4e2d\u3002\u5f53\u91cd\u5b8c\u64cd\u4f5c\u5b8c\u6210\u540e\uff0c\u4f1a\u5c06\u6240\u6709\u7f13\u51b2\u533a\u4e2d\u7684\u65e5\u5fd7\u4e00\u6b21\u6027\u5199\u5165\u5230\u4e34\u65f6\u6587\u4ef6\u4e2d\u3002\u7136\u540e\u8c03\u7528\u539f\u5b50\u6027\u7684rename\u547d\u4ee4\u7528\u65b0\u7684AOF\u6587\u4ef6\u53d6\u4ee3\u8001\u7684AOF\u6587\u4ef6\u3002<\/p>\n

    AOF\u662f\u4e00\u4e2a\u5199\u6587\u4ef6\u64cd\u4f5c\uff0c\u5176\u76ee\u7684\u662f\u5c06\u64cd\u4f5c\u65e5\u5fd7\u5199\u5230\u78c1\u76d8\u4e0a\uff0c\u6240\u4ee5\u5b83\u4e5f\u540c\u6837\u4f1a\u9047\u5230\u6211\u4eec\u4e0a\u9762\u8bf4\u7684\u5199\u64cd\u4f5c\u7684\u6d41\u7a0b\u3002\u5728Redis\u4e2d\u5bf9AOF\u8c03\u7528write\u5199\u5165\u540e\uff0c\u901a\u8fc7appendfsync\u9009\u9879\u6765\u63a7\u5236\u8c03\u7528fsync\u5c06\u5176\u5199\u5230\u78c1\u76d8\u4e0a\u7684\u65f6\u95f4\uff0c\u4e0b\u9762appendfsync\u7684\u4e09\u4e2a\u8bbe\u7f6e\u9879\uff0c\u5b89\u5168\u5f3a\u5ea6\u9010\u6e10\u53d8\u5f3a\u3002<\/p>\n