创建时间:1552017671
修改时间: 1552017879
5391-1552017671373Redis 是 C 实现的基于内存并可持久的键值对数据库,在分布式服务中常常被用作缓存。除此之外还可以利用其特点做许多有趣的应用,所以我们不仅需要会用,更需要理解其工作机制。08716087#555555087#ffffffjustify3250-15520176735562431-1552017673557更新记录041604#55555504#ffffffjustify9780-15520176735572016.09.13: 添加配置部分更详细的说明及实战应用部分03116031#555555031#ffffffjustify6345-15520176735572016.07.05: 初稿01416014#555555014#ffffffjustify7199-1552017673557Redis 的具体介绍在官方网站和维基百科都有,这里我们只要记住几个关键词既可:开源、C 语言、网络交互、基于内存、可持久化、键值对、数据库。作者是 Salvatore Sanfilippo,他的博客和 github 主页都放到文末的参考链接里,有兴趣的同学可以去看看。0135160135#5555550135#ffffffjustify5668-1552017673557根据 Redis 主页上的介绍,许多公司都在使用 Redis,比较著名的有 Twitter GitHub Weibo Pinterest Snapchat Craigslist Digg StackOverflow Flickr 等等,想要了解更多的话,可以参考 Who uses Redis?0147160132#555555132147#0593d30132#ffffff132147http://techstacks.io/tech/redisjustify9522-1552017673557也有另一种叫法,称为数据结构服务器,因为保存的 value 可以是字符串(string)、字典(map)、列表(list)、集合(sets)或有序集合(sorted set)。那么键值对存储这么多,到底 Redis 有什么不同之处呢?一是原子性操作,二是在内存中运行。0134160134#5555550134#ffffffjustify6039-1552017673557Redis 脚本使用 Lua 解释器来执行脚本。 Reids 2.6 版本通过内嵌支持 Lua 环境。执行脚本的常用命令为 EVAL。基本语法为 127.0.0.1:6379> EVAL script numkeys key [key ...] arg [arg ...]0731673136130136#555555073#ffffff73136#eeeeeejustify9944-1552017673557基本使用04true042204#55555504#ffffffjustify1.59534-1552017673557安装02true022002#55555502#ffffffjustify1.52010-1552017673557在 Mac 下的安装非常简单,只需要 brew install redis 即可,如果需要开机启动,按照安装完成后的提示输出一条命令即可。然后我们输入 redis-server 应该就能看到如下信息01916193713377616768813889916099#555555019#ffffff1937#eeeeee3776#ffffff7688#eeeeee8899#ffffffjustify9720-1552017673557{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"dawang:~ dawang$ redis-server\n62799:C 29 Jun 09:48:45.735 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf\n62799:M 29 Jun 09:48:45.737 * Increased maximum number of open files to 10032 (it was originally set to 4864).\n _._\n _.-``__ ''-._\n _.-`` `. `_. ''-._ Redis 3.2.0 (00000000/0) 64 bit\n .-`` .-```. ```\\/ _.,_ ''-._\n ( ' , .-` | `, ) Running in standalone mode\n |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379\n | `-._ `._ / _.-' | PID: 62799\n `-._ `-._ `-./ _.-' _.-'\n |`-._`-._ `-.__.-' _.-'_.-'|\n | `-._`-._ _.-'_.-' | http://redis.io\n `-._ `-._`-.__.-'_.-' _.-'\n |`-._`-._ `-.__.-' _.-'_.-'|\n | `-._`-._ _.-'_.-' |\n `-._ `-._`-.__.-'_.-' _.-'\n `-._ `-.__.-' _.-'\n `-._ _.-'\n `-.__.-'\n62799:M 29 Jun 09:48:45.738 # Server started, Redis version 3.2.0\n62799:M 29 Jun 09:48:45.738 * The server is now ready to accept connections on port 6379","inlineStyles":{"font-size":[{"from":0,"to":29,"value":13},{"from":30,"to":191,"value":13},{"from":192,"to":302,"value":13},{"from":303,"to":322,"value":13},{"from":323,"to":347,"value":13},{"from":348,"to":419,"value":13},{"from":420,"to":454,"value":13},{"from":455,"to":521,"value":13},{"from":522,"to":572,"value":13},{"from":573,"to":623,"value":13},{"from":624,"to":658,"value":13},{"from":659,"to":694,"value":13},{"from":695,"to":756,"value":13},{"from":757,"to":791,"value":13},{"from":792,"to":827,"value":13},{"from":828,"to":863,"value":13},{"from":864,"to":898,"value":13},{"from":899,"to":929,"value":13},{"from":930,"to":956,"value":13},{"from":957,"to":979,"value":13},{"from":980,"to":1045,"value":13},{"from":1046,"to":1134,"value":13}],"color":[{"from":0,"to":29,"value":"#4d4d4c"},{"from":30,"to":58,"value":"#4d4d4c"},{"from":58,"to":191,"value":"#8e908c"},{"from":192,"to":289,"value":"#4d4d4c"},{"from":289,"to":292,"value":"#f5871f"},{"from":292,"to":302,"value":"#4d4d4c"},{"from":303,"to":322,"value":"#4d4d4c"},{"from":323,"to":342,"value":"#4d4d4c"},{"from":342,"to":344,"value":"#718c00"},{"from":344,"to":347,"value":"#4d4d4c"},{"from":348,"to":372,"value":"#4d4d4c"},{"from":372,"to":374,"value":"#718c00"},{"from":374,"to":419,"value":"#4d4d4c"},{"from":420,"to":449,"value":"#4d4d4c"},{"from":449,"to":451,"value":"#718c00"},{"from":451,"to":454,"value":"#4d4d4c"},{"from":455,"to":461,"value":"#4d4d4c"},{"from":461,"to":521,"value":"#718c00"},{"from":522,"to":555,"value":"#4d4d4c"},{"from":555,"to":572,"value":"#718c00"},{"from":573,"to":623,"value":"#4d4d4c"},{"from":624,"to":649,"value":"#4d4d4c"},{"from":649,"to":658,"value":"#718c00"},{"from":659,"to":680,"value":"#4d4d4c"},{"from":680,"to":689,"value":"#718c00"},{"from":689,"to":692,"value":"#4d4d4c"},{"from":692,"to":694,"value":"#718c00"},{"from":695,"to":724,"value":"#4d4d4c"},{"from":724,"to":756,"value":"#718c00"},{"from":757,"to":782,"value":"#4d4d4c"},{"from":782,"to":791,"value":"#718c00"},{"from":792,"to":813,"value":"#4d4d4c"},{"from":813,"to":822,"value":"#718c00"},{"from":822,"to":825,"value":"#4d4d4c"},{"from":825,"to":827,"value":"#718c00"},{"from":828,"to":857,"value":"#4d4d4c"},{"from":857,"to":863,"value":"#718c00"},{"from":864,"to":889,"value":"#4d4d4c"},{"from":889,"to":898,"value":"#718c00"},{"from":899,"to":920,"value":"#4d4d4c"},{"from":920,"to":929,"value":"#718c00"},{"from":930,"to":955,"value":"#4d4d4c"},{"from":955,"to":956,"value":"#718c00"},{"from":957,"to":979,"value":"#4d4d4c"},{"from":980,"to":1008,"value":"#4d4d4c"},{"from":1008,"to":1045,"value":"#8e908c"},{"from":1046,"to":1134,"value":"#4d4d4c"}],"back-color":[{"from":0,"to":29,"value":"#f7f7f7"},{"from":30,"to":191,"value":"#f7f7f7"},{"from":192,"to":302,"value":"#f7f7f7"},{"from":303,"to":322,"value":"#f7f7f7"},{"from":323,"to":347,"value":"#f7f7f7"},{"from":348,"to":419,"value":"#f7f7f7"},{"from":420,"to":454,"value":"#f7f7f7"},{"from":455,"to":521,"value":"#f7f7f7"},{"from":522,"to":572,"value":"#f7f7f7"},{"from":573,"to":623,"value":"#f7f7f7"},{"from":624,"to":658,"value":"#f7f7f7"},{"from":659,"to":694,"value":"#f7f7f7"},{"from":695,"to":756,"value":"#f7f7f7"},{"from":757,"to":791,"value":"#f7f7f7"},{"from":792,"to":827,"value":"#f7f7f7"},{"from":828,"to":863,"value":"#f7f7f7"},{"from":864,"to":898,"value":"#f7f7f7"},{"from":899,"to":929,"value":"#f7f7f7"},{"from":930,"to":956,"value":"#f7f7f7"},{"from":957,"to":979,"value":"#f7f7f7"},{"from":980,"to":1045,"value":"#f7f7f7"},{"from":1046,"to":1134,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[621]}
5698-1552017673557我们看到目前 Redis 运行在 standalone 模式(相对于分布式),对应的端口是 6379。至于为什么是 6379,这背后是有故事的,原文在这里(打开之后搜索6379),我简要翻译一下:09816075#5555557589#0593d38998#555555075#ffffff8998#ffffff7589http://oldblog.antirez.com/post/redis-as-LRU-cache.htmljustify9231-15520176735576379 是 MERZ 这个单词在九宫格输入时的按键顺序,那么问题来了,MERZ 又是什么鬼?简单来说来自于一个意大利 showgirl,名字叫做 Alessia Merz,图片这里就不放了。作者日常生活中会创造一些『俚语』,merz 这个词已经用了十年,意思也一直在变化。起初他们 merz 来表示很蠢的事情,比方说『Hey, that’s merz!』,之后意思有些变化,指的是那些有一定技术含量但没什么意义而且还很蠢(stupid)的事儿,或者是那些需要大量技能和耐心才能完成但仍旧很蠢(stupid)的事儿(看出来了吗,核心是 Stupid)。作者举了两个例子,比方说用一台 GPS 和一辆破车大半夜为制作 3D 地图采样,或者在明知道自己不会去买彩票的情况下还是研究大量的彩票信息来找到其『不随机』的证据。总结一下就是有 hack value 的事情,或者是那些为了 hack value 而去做事的人。于是自然而然的,merz 在拨号键盘上对应的数字就成为了 Redis 的端口号。044716074#5555557486#0593d386447#555555074#ffffff86447#ffffff7486http://it.wikipedia.org/wiki/Alessia_Merzjustify4078-1552017673557在 Linux 下除了使用包管理器来安装外,也可以手动安装,这样比较容易进行管理,这里是我自己在使用的安装脚本。编译完成后可以使用 src/redis-server 和 src/redis-cli 进行启动和交互。066166682138285168598139810716041#5555554143#0593d343107#555555041#ffffff4366#ffffff6682#eeeeee8285#ffffff8598#eeeeee98107#ffffff4143https://github.com/wdxtub/wdxtools/blob/master/linux-script/ubuntu-redis-install.shjustify9570-1552017673557除了前面使用过的 redis-server 命令,我们还可以使用 redis-cli 命令来启动 redis 客户端,比如:091692113213316334213426216062#55555509#ffffff921#eeeeee2133#ffffff3342#eeeeee4262#ffffffjustify3147-1552017673557{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"dawang:~ dawang$ redis-cli\n127.0.0.1:6379> set name 'wdxtub'\nOK\n127.0.0.1:6379> get name\n\"wdxtub\"","inlineStyles":{"font-size":[{"from":0,"to":26,"value":13},{"from":27,"to":60,"value":13},{"from":61,"to":63,"value":13},{"from":64,"to":88,"value":13},{"from":89,"to":97,"value":13}],"color":[{"from":0,"to":26,"value":"#4d4d4c"},{"from":27,"to":43,"value":"#4d4d4c"},{"from":43,"to":46,"value":"#f5871f"},{"from":46,"to":52,"value":"#4d4d4c"},{"from":52,"to":60,"value":"#718c00"},{"from":61,"to":63,"value":"#4d4d4c"},{"from":64,"to":88,"value":"#4d4d4c"},{"from":89,"to":97,"value":"#718c00"}],"back-color":[{"from":0,"to":26,"value":"#f7f7f7"},{"from":27,"to":60,"value":"#f7f7f7"},{"from":61,"to":63,"value":"#f7f7f7"},{"from":64,"to":88,"value":"#f7f7f7"},{"from":89,"to":97,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[616]}
5039-1552017673557如果需要在远程 Redis 上执行命令,也可以用 redis-cli 命令,具体的方式为 redis-cli -h host -p port -a password02516253413344516458213082#555555025#ffffff2534#eeeeee3445#ffffff4582#eeeeeejustify2413-1552017673557其他一些工具为(在 src 文件夹中使用 find . -type f -executable):01016101313132116214713474916049#555555010#ffffff1013#eeeeee1321#ffffff2147#eeeeee4749#ffffffjustify4090-1552017673557./redis-check-aof 检查并修复 AOF 文件01713173016030#555555017#eeeeee1730#ffffffjustify2721-1552017673557./redis-sentinel Redis 集群管理01613162716027#555555016#eeeeee1627#ffffffjustify4589-1552017673557./redis-benchmark 性能测试01713172216022#555555017#eeeeee1722#ffffffjustify7426-1552017673557./redis-check-rdb 检查并修复 RDB 文件01713173016030#555555017#eeeeee1730#ffffffjustify7847-1552017673557连接02true022002#55555502#ffffffjustify1.51473-1552017673557基本命令有 5 个,可以覆盖日常使用的大部分场景,比方说心跳检测、切换数据库之类的:04216042#555555042#ffffffjustify1524-1552017673557AUTH password: 验证密码01313131916019#555555013#eeeeee1319#ffffffjustify1676-1552017673557ECHO message: 打印字符串01213121916019#555555012#eeeeee1219#ffffffjustify7996-1552017673557PING: 查看服务是否在运行,如果在运行,就输出 PONG041342616263013030#55555504#eeeeee426#ffffff2630#eeeeeejustify4485-1552017673557QUIT: 关闭当前连接041341216012#55555504#eeeeee412#ffffffjustify3384-1552017673557SELECT index: 选择指定的数据库01213122216022#555555012#eeeeee1222#ffffffjustify3266-1552017673557状态02true022002#55555502#ffffffjustify1.59212-1552017673557我们可以使用 INFO 命令来了解当前 Redis 数据库的基本状态,更多的命令请查阅参考链接中给出的地址,这里不赘述:071671113116016060#55555507#ffffff711#eeeeee1160#ffffffjustify1391-1552017673557{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"# Server\nredis_version:3.2.0\nredis_git_sha1:00000000\nredis_git_dirty:0\nredis_build_id:dd22954a73c7ae64\nredis_mode:standalone\nos:Darwin 15.5.0 x86_64\narch_bits:64\nmultiplexing_api:kqueue\ngcc_version:4.2.1\nprocess_id:882\nrun_id:c1a9de73731957965cf2cb53cf52e5acb93a3705\ntcp_port:6379\nuptime_in_seconds:95465\nuptime_in_days:1\nhz:10\nlru_clock:8070643\nexecutable:/usr/local/opt/redis/bin/redis-server\nconfig_file:/usr/local/etc/redis.conf\n# Clients\nconnected_clients:2\nclient_longest_output_list:0\nclient_biggest_input_buf:0\nblocked_clients:0\n# Memory\nused_memory:1025232\nused_memory_human:1001.20K\nused_memory_rss:892928\nused_memory_rss_human:872.00K\nused_memory_peak:1119232\nused_memory_peak_human:1.07M\ntotal_system_memory:17179869184\ntotal_system_memory_human:16.00G\nused_memory_lua:37888\nused_memory_lua_human:37.00K\nmaxmemory:0\nmaxmemory_human:0B\nmaxmemory_policy:noeviction\nmem_fragmentation_ratio:0.87\nmem_allocator:libc\n# Persistence\nloading:0\nrdb_changes_since_last_save:0\nrdb_bgsave_in_progress:0\nrdb_last_save_time:1467687446\nrdb_last_bgsave_status:ok\nrdb_last_bgsave_time_sec:0\nrdb_current_bgsave_time_sec:-1\naof_enabled:0\naof_rewrite_in_progress:0\naof_rewrite_scheduled:0\naof_last_rewrite_time_sec:-1\naof_current_rewrite_time_sec:-1\naof_last_bgrewrite_status:ok\naof_last_write_status:ok\n# Stats\ntotal_connections_received:5\ntotal_commands_processed:69\ninstantaneous_ops_per_sec:0\ntotal_net_input_bytes:3232\ntotal_net_output_bytes:3374\ninstantaneous_input_kbps:0.00\ninstantaneous_output_kbps:0.00\nrejected_connections:0\nsync_full:0\nsync_partial_ok:0\nsync_partial_err:0\nexpired_keys:0\nevicted_keys:0\nkeyspace_hits:14\nkeyspace_misses:0\npubsub_channels:1\npubsub_patterns:0\nlatest_fork_usec:255\nmigrate_cached_sockets:0\n# Replication\nrole:master\nconnected_slaves:0\nmaster_repl_offset:0\nrepl_backlog_active:0\nrepl_backlog_size:1048576\nrepl_backlog_first_byte_offset:0\nrepl_backlog_histlen:0\n# CPU\nused_cpu_sys:10.67\nused_cpu_user:5.92\nused_cpu_sys_children:0.02\nused_cpu_user_children:0.01\n# Cluster\ncluster_enabled:0\n# Keyspace\ndb0:keys=2,expires=0,avg_ttl=0","inlineStyles":{"font-size":[{"from":0,"to":8,"value":13},{"from":9,"to":28,"value":13},{"from":29,"to":52,"value":13},{"from":53,"to":70,"value":13},{"from":71,"to":102,"value":13},{"from":103,"to":124,"value":13},{"from":125,"to":148,"value":13},{"from":149,"to":161,"value":13},{"from":162,"to":185,"value":13},{"from":186,"to":203,"value":13},{"from":204,"to":218,"value":13},{"from":219,"to":266,"value":13},{"from":267,"to":280,"value":13},{"from":281,"to":304,"value":13},{"from":305,"to":321,"value":13},{"from":322,"to":327,"value":13},{"from":328,"to":345,"value":13},{"from":346,"to":394,"value":13},{"from":395,"to":432,"value":13},{"from":433,"to":442,"value":13},{"from":443,"to":462,"value":13},{"from":463,"to":491,"value":13},{"from":492,"to":518,"value":13},{"from":519,"to":536,"value":13},{"from":537,"to":545,"value":13},{"from":546,"to":565,"value":13},{"from":566,"to":592,"value":13},{"from":593,"to":615,"value":13},{"from":616,"to":645,"value":13},{"from":646,"to":670,"value":13},{"from":671,"to":699,"value":13},{"from":700,"to":731,"value":13},{"from":732,"to":764,"value":13},{"from":765,"to":786,"value":13},{"from":787,"to":815,"value":13},{"from":816,"to":827,"value":13},{"from":828,"to":846,"value":13},{"from":847,"to":874,"value":13},{"from":875,"to":903,"value":13},{"from":904,"to":922,"value":13},{"from":923,"to":936,"value":13},{"from":937,"to":946,"value":13},{"from":947,"to":976,"value":13},{"from":977,"to":1001,"value":13},{"from":1002,"to":1031,"value":13},{"from":1032,"to":1057,"value":13},{"from":1058,"to":1084,"value":13},{"from":1085,"to":1115,"value":13},{"from":1116,"to":1129,"value":13},{"from":1130,"to":1155,"value":13},{"from":1156,"to":1179,"value":13},{"from":1180,"to":1208,"value":13},{"from":1209,"to":1240,"value":13},{"from":1241,"to":1269,"value":13},{"from":1270,"to":1294,"value":13},{"from":1295,"to":1302,"value":13},{"from":1303,"to":1331,"value":13},{"from":1332,"to":1359,"value":13},{"from":1360,"to":1387,"value":13},{"from":1388,"to":1414,"value":13},{"from":1415,"to":1442,"value":13},{"from":1443,"to":1472,"value":13},{"from":1473,"to":1503,"value":13},{"from":1504,"to":1526,"value":13},{"from":1527,"to":1538,"value":13},{"from":1539,"to":1556,"value":13},{"from":1557,"to":1575,"value":13},{"from":1576,"to":1590,"value":13},{"from":1591,"to":1605,"value":13},{"from":1606,"to":1622,"value":13},{"from":1623,"to":1640,"value":13},{"from":1641,"to":1658,"value":13},{"from":1659,"to":1676,"value":13},{"from":1677,"to":1697,"value":13},{"from":1698,"to":1722,"value":13},{"from":1723,"to":1736,"value":13},{"from":1737,"to":1748,"value":13},{"from":1749,"to":1767,"value":13},{"from":1768,"to":1788,"value":13},{"from":1789,"to":1810,"value":13},{"from":1811,"to":1836,"value":13},{"from":1837,"to":1869,"value":13},{"from":1870,"to":1892,"value":13},{"from":1893,"to":1898,"value":13},{"from":1899,"to":1917,"value":13},{"from":1918,"to":1936,"value":13},{"from":1937,"to":1963,"value":13},{"from":1964,"to":1991,"value":13},{"from":1992,"to":2001,"value":13},{"from":2002,"to":2019,"value":13},{"from":2020,"to":2030,"value":13},{"from":2031,"to":2061,"value":13}],"color":[{"from":0,"to":8,"value":"#8e908c"},{"from":9,"to":28,"value":"#4d4d4c"},{"from":29,"to":52,"value":"#4d4d4c"},{"from":53,"to":70,"value":"#4d4d4c"},{"from":71,"to":102,"value":"#4d4d4c"},{"from":103,"to":124,"value":"#4d4d4c"},{"from":125,"to":148,"value":"#4d4d4c"},{"from":149,"to":161,"value":"#4d4d4c"},{"from":162,"to":185,"value":"#4d4d4c"},{"from":186,"to":203,"value":"#4d4d4c"},{"from":204,"to":218,"value":"#4d4d4c"},{"from":219,"to":266,"value":"#4d4d4c"},{"from":267,"to":280,"value":"#4d4d4c"},{"from":281,"to":304,"value":"#4d4d4c"},{"from":305,"to":321,"value":"#4d4d4c"},{"from":322,"to":327,"value":"#4d4d4c"},{"from":328,"to":345,"value":"#4d4d4c"},{"from":346,"to":362,"value":"#4d4d4c"},{"from":362,"to":367,"value":"#f5871f"},{"from":367,"to":394,"value":"#4d4d4c"},{"from":395,"to":412,"value":"#4d4d4c"},{"from":412,"to":417,"value":"#f5871f"},{"from":417,"to":432,"value":"#4d4d4c"},{"from":433,"to":442,"value":"#8e908c"},{"from":443,"to":462,"value":"#4d4d4c"},{"from":463,"to":491,"value":"#4d4d4c"},{"from":492,"to":518,"value":"#4d4d4c"},{"from":519,"to":536,"value":"#4d4d4c"},{"from":537,"to":545,"value":"#8e908c"},{"from":546,"to":565,"value":"#4d4d4c"},{"from":566,"to":592,"value":"#4d4d4c"},{"from":593,"to":615,"value":"#4d4d4c"},{"from":616,"to":645,"value":"#4d4d4c"},{"from":646,"to":670,"value":"#4d4d4c"},{"from":671,"to":699,"value":"#4d4d4c"},{"from":700,"to":731,"value":"#4d4d4c"},{"from":732,"to":764,"value":"#4d4d4c"},{"from":765,"to":786,"value":"#4d4d4c"},{"from":787,"to":815,"value":"#4d4d4c"},{"from":816,"to":827,"value":"#4d4d4c"},{"from":828,"to":846,"value":"#4d4d4c"},{"from":847,"to":874,"value":"#4d4d4c"},{"from":875,"to":903,"value":"#4d4d4c"},{"from":904,"to":922,"value":"#4d4d4c"},{"from":923,"to":936,"value":"#8e908c"},{"from":937,"to":946,"value":"#4d4d4c"},{"from":947,"to":976,"value":"#4d4d4c"},{"from":977,"to":1001,"value":"#4d4d4c"},{"from":1002,"to":1031,"value":"#4d4d4c"},{"from":1032,"to":1057,"value":"#4d4d4c"},{"from":1058,"to":1084,"value":"#4d4d4c"},{"from":1085,"to":1115,"value":"#4d4d4c"},{"from":1116,"to":1129,"value":"#4d4d4c"},{"from":1130,"to":1155,"value":"#4d4d4c"},{"from":1156,"to":1179,"value":"#4d4d4c"},{"from":1180,"to":1208,"value":"#4d4d4c"},{"from":1209,"to":1240,"value":"#4d4d4c"},{"from":1241,"to":1269,"value":"#4d4d4c"},{"from":1270,"to":1294,"value":"#4d4d4c"},{"from":1295,"to":1302,"value":"#8e908c"},{"from":1303,"to":1331,"value":"#4d4d4c"},{"from":1332,"to":1359,"value":"#4d4d4c"},{"from":1360,"to":1387,"value":"#4d4d4c"},{"from":1388,"to":1414,"value":"#4d4d4c"},{"from":1415,"to":1442,"value":"#4d4d4c"},{"from":1443,"to":1472,"value":"#4d4d4c"},{"from":1473,"to":1503,"value":"#4d4d4c"},{"from":1504,"to":1526,"value":"#4d4d4c"},{"from":1527,"to":1538,"value":"#4d4d4c"},{"from":1539,"to":1556,"value":"#4d4d4c"},{"from":1557,"to":1575,"value":"#4d4d4c"},{"from":1576,"to":1590,"value":"#4d4d4c"},{"from":1591,"to":1605,"value":"#4d4d4c"},{"from":1606,"to":1622,"value":"#4d4d4c"},{"from":1623,"to":1640,"value":"#4d4d4c"},{"from":1641,"to":1658,"value":"#4d4d4c"},{"from":1659,"to":1676,"value":"#4d4d4c"},{"from":1677,"to":1697,"value":"#4d4d4c"},{"from":1698,"to":1722,"value":"#4d4d4c"},{"from":1723,"to":1736,"value":"#8e908c"},{"from":1737,"to":1748,"value":"#4d4d4c"},{"from":1749,"to":1767,"value":"#4d4d4c"},{"from":1768,"to":1788,"value":"#4d4d4c"},{"from":1789,"to":1810,"value":"#4d4d4c"},{"from":1811,"to":1836,"value":"#4d4d4c"},{"from":1837,"to":1869,"value":"#4d4d4c"},{"from":1870,"to":1892,"value":"#4d4d4c"},{"from":1893,"to":1898,"value":"#8e908c"},{"from":1899,"to":1917,"value":"#4d4d4c"},{"from":1918,"to":1936,"value":"#4d4d4c"},{"from":1937,"to":1963,"value":"#4d4d4c"},{"from":1964,"to":1991,"value":"#4d4d4c"},{"from":1992,"to":2001,"value":"#8e908c"},{"from":2002,"to":2019,"value":"#4d4d4c"},{"from":2020,"to":2030,"value":"#8e908c"},{"from":2031,"to":2061,"value":"#4d4d4c"}],"back-color":[{"from":0,"to":8,"value":"#f7f7f7"},{"from":9,"to":28,"value":"#f7f7f7"},{"from":29,"to":52,"value":"#f7f7f7"},{"from":53,"to":70,"value":"#f7f7f7"},{"from":71,"to":102,"value":"#f7f7f7"},{"from":103,"to":124,"value":"#f7f7f7"},{"from":125,"to":148,"value":"#f7f7f7"},{"from":149,"to":161,"value":"#f7f7f7"},{"from":162,"to":185,"value":"#f7f7f7"},{"from":186,"to":203,"value":"#f7f7f7"},{"from":204,"to":218,"value":"#f7f7f7"},{"from":219,"to":266,"value":"#f7f7f7"},{"from":267,"to":280,"value":"#f7f7f7"},{"from":281,"to":304,"value":"#f7f7f7"},{"from":305,"to":321,"value":"#f7f7f7"},{"from":322,"to":327,"value":"#f7f7f7"},{"from":328,"to":345,"value":"#f7f7f7"},{"from":346,"to":394,"value":"#f7f7f7"},{"from":395,"to":432,"value":"#f7f7f7"},{"from":433,"to":442,"value":"#f7f7f7"},{"from":443,"to":462,"value":"#f7f7f7"},{"from":463,"to":491,"value":"#f7f7f7"},{"from":492,"to":518,"value":"#f7f7f7"},{"from":519,"to":536,"value":"#f7f7f7"},{"from":537,"to":545,"value":"#f7f7f7"},{"from":546,"to":565,"value":"#f7f7f7"},{"from":566,"to":592,"value":"#f7f7f7"},{"from":593,"to":615,"value":"#f7f7f7"},{"from":616,"to":645,"value":"#f7f7f7"},{"from":646,"to":670,"value":"#f7f7f7"},{"from":671,"to":699,"value":"#f7f7f7"},{"from":700,"to":731,"value":"#f7f7f7"},{"from":732,"to":764,"value":"#f7f7f7"},{"from":765,"to":786,"value":"#f7f7f7"},{"from":787,"to":815,"value":"#f7f7f7"},{"from":816,"to":827,"value":"#f7f7f7"},{"from":828,"to":846,"value":"#f7f7f7"},{"from":847,"to":874,"value":"#f7f7f7"},{"from":875,"to":903,"value":"#f7f7f7"},{"from":904,"to":922,"value":"#f7f7f7"},{"from":923,"to":936,"value":"#f7f7f7"},{"from":937,"to":946,"value":"#f7f7f7"},{"from":947,"to":976,"value":"#f7f7f7"},{"from":977,"to":1001,"value":"#f7f7f7"},{"from":1002,"to":1031,"value":"#f7f7f7"},{"from":1032,"to":1057,"value":"#f7f7f7"},{"from":1058,"to":1084,"value":"#f7f7f7"},{"from":1085,"to":1115,"value":"#f7f7f7"},{"from":1116,"to":1129,"value":"#f7f7f7"},{"from":1130,"to":1155,"value":"#f7f7f7"},{"from":1156,"to":1179,"value":"#f7f7f7"},{"from":1180,"to":1208,"value":"#f7f7f7"},{"from":1209,"to":1240,"value":"#f7f7f7"},{"from":1241,"to":1269,"value":"#f7f7f7"},{"from":1270,"to":1294,"value":"#f7f7f7"},{"from":1295,"to":1302,"value":"#f7f7f7"},{"from":1303,"to":1331,"value":"#f7f7f7"},{"from":1332,"to":1359,"value":"#f7f7f7"},{"from":1360,"to":1387,"value":"#f7f7f7"},{"from":1388,"to":1414,"value":"#f7f7f7"},{"from":1415,"to":1442,"value":"#f7f7f7"},{"from":1443,"to":1472,"value":"#f7f7f7"},{"from":1473,"to":1503,"value":"#f7f7f7"},{"from":1504,"to":1526,"value":"#f7f7f7"},{"from":1527,"to":1538,"value":"#f7f7f7"},{"from":1539,"to":1556,"value":"#f7f7f7"},{"from":1557,"to":1575,"value":"#f7f7f7"},{"from":1576,"to":1590,"value":"#f7f7f7"},{"from":1591,"to":1605,"value":"#f7f7f7"},{"from":1606,"to":1622,"value":"#f7f7f7"},{"from":1623,"to":1640,"value":"#f7f7f7"},{"from":1641,"to":1658,"value":"#f7f7f7"},{"from":1659,"to":1676,"value":"#f7f7f7"},{"from":1677,"to":1697,"value":"#f7f7f7"},{"from":1698,"to":1722,"value":"#f7f7f7"},{"from":1723,"to":1736,"value":"#f7f7f7"},{"from":1737,"to":1748,"value":"#f7f7f7"},{"from":1749,"to":1767,"value":"#f7f7f7"},{"from":1768,"to":1788,"value":"#f7f7f7"},{"from":1789,"to":1810,"value":"#f7f7f7"},{"from":1811,"to":1836,"value":"#f7f7f7"},{"from":1837,"to":1869,"value":"#f7f7f7"},{"from":1870,"to":1892,"value":"#f7f7f7"},{"from":1893,"to":1898,"value":"#f7f7f7"},{"from":1899,"to":1917,"value":"#f7f7f7"},{"from":1918,"to":1936,"value":"#f7f7f7"},{"from":1937,"to":1963,"value":"#f7f7f7"},{"from":1964,"to":1991,"value":"#f7f7f7"},{"from":1992,"to":2001,"value":"#f7f7f7"},{"from":2002,"to":2019,"value":"#f7f7f7"},{"from":2020,"to":2030,"value":"#f7f7f7"},{"from":2031,"to":2061,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[621]}
5344-1552017673557配置02true022002#55555502#ffffffjustify1.52097-1552017673557Redis 的配置文件可以在安装目录下找到,名为 redis.conf,我们来看看都有什么配置02516253513354716047#555555025#ffffff2535#eeeeee3547#ffffffjustify6222-1552017673557{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"127.0.0.1:6379> CONFIG GET *\n 1) \"dbfilename\"\n 2) \"dump.rdb\"\n 3) \"requirepass\"\n 4) \"\"\n 5) \"masterauth\"\n 6) \"\"\n 7) \"unixsocket\"\n 8) \"\"\n 9) \"logfile\"\n 10) \"\"\n 11) \"pidfile\"\n 12) \"/usr/local/var/run/redis.pid\"\n 13) \"maxmemory\"\n 14) \"0\"\n 15) \"maxmemory-samples\"\n 16) \"5\"\n 17) \"timeout\"\n 18) \"0\"\n 19) \"auto-aof-rewrite-percentage\"\n 20) \"100\"\n 21) \"auto-aof-rewrite-min-size\"\n 22) \"67108864\"\n 23) \"hash-max-ziplist-entries\"\n 24) \"512\"\n 25) \"hash-max-ziplist-value\"\n 26) \"64\"\n 27) \"list-max-ziplist-size\"\n 28) \"-2\"\n 29) \"list-compress-depth\"\n 30) \"0\"\n 31) \"set-max-intset-entries\"\n 32) \"512\"\n 33) \"zset-max-ziplist-entries\"\n 34) \"128\"\n 35) \"zset-max-ziplist-value\"\n 36) \"64\"\n 37) \"hll-sparse-max-bytes\"\n 38) \"3000\"\n 39) \"lua-time-limit\"\n 40) \"5000\"\n 41) \"slowlog-log-slower-than\"\n 42) \"10000\"\n 43) \"latency-monitor-threshold\"\n 44) \"0\"\n 45) \"slowlog-max-len\"\n 46) \"128\"\n 47) \"port\"\n 48) \"6379\"\n 49) \"tcp-backlog\"\n 50) \"511\"\n 51) \"databases\"\n 52) \"16\"\n 53) \"repl-ping-slave-period\"\n 54) \"10\"\n 55) \"repl-timeout\"\n 56) \"60\"\n 57) \"repl-backlog-size\"\n 58) \"1048576\"\n 59) \"repl-backlog-ttl\"\n 60) \"3600\"\n 61) \"maxclients\"\n 62) \"10000\"\n 63) \"watchdog-period\"\n 64) \"0\"\n 65) \"slave-priority\"\n 66) \"100\"\n 67) \"min-slaves-to-write\"\n 68) \"0\"\n 69) \"min-slaves-max-lag\"\n 70) \"10\"\n 71) \"hz\"\n 72) \"10\"\n 73) \"cluster-node-timeout\"\n 74) \"15000\"\n 75) \"cluster-migration-barrier\"\n 76) \"1\"\n 77) \"cluster-slave-validity-factor\"\n 78) \"10\"\n 79) \"repl-diskless-sync-delay\"\n 80) \"5\"\n 81) \"tcp-keepalive\"\n 82) \"0\"\n 83) \"cluster-require-full-coverage\"\n 84) \"yes\"\n 85) \"no-appendfsync-on-rewrite\"\n 86) \"no\"\n 87) \"slave-serve-stale-data\"\n 88) \"yes\"\n 89) \"slave-read-only\"\n 90) \"yes\"\n 91) \"stop-writes-on-bgsave-error\"\n 92) \"yes\"\n 93) \"daemonize\"\n 94) \"no\"\n 95) \"rdbcompression\"\n 96) \"yes\"\n 97) \"rdbchecksum\"\n 98) \"yes\"\n 99) \"activerehashing\"\n100) \"yes\"\n101) \"protected-mode\"\n102) \"yes\"\n103) \"repl-disable-tcp-nodelay\"\n104) \"no\"\n105) \"repl-diskless-sync\"\n106) \"no\"\n107) \"aof-rewrite-incremental-fsync\"\n108) \"yes\"\n109) \"aof-load-truncated\"\n110) \"yes\"\n111) \"maxmemory-policy\"\n112) \"noeviction\"\n113) \"loglevel\"\n114) \"notice\"\n115) \"supervised\"\n116) \"no\"\n117) \"appendfsync\"\n118) \"everysec\"\n119) \"syslog-facility\"\n120) \"local0\"\n121) \"appendonly\"\n122) \"no\"\n123) \"dir\"\n124) \"/usr/local/var/db/redis\"\n125) \"save\"\n126) \"900 1 300 10 60 10000\"\n127) \"client-output-buffer-limit\"\n128) \"normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60\"\n129) \"unixsocketperm\"\n130) \"0\"\n131) \"slaveof\"\n132) \"\"\n133) \"notify-keyspace-events\"\n134) \"\"\n135) \"bind\"\n136) \"127.0.0.1\"","inlineStyles":{"font-size":[{"from":0,"to":28,"value":13},{"from":29,"to":46,"value":13},{"from":47,"to":62,"value":13},{"from":63,"to":81,"value":13},{"from":82,"to":89,"value":13},{"from":90,"to":107,"value":13},{"from":108,"to":115,"value":13},{"from":116,"to":133,"value":13},{"from":134,"to":141,"value":13},{"from":142,"to":156,"value":13},{"from":157,"to":164,"value":13},{"from":165,"to":179,"value":13},{"from":180,"to":215,"value":13},{"from":216,"to":232,"value":13},{"from":233,"to":241,"value":13},{"from":242,"to":266,"value":13},{"from":267,"to":275,"value":13},{"from":276,"to":290,"value":13},{"from":291,"to":299,"value":13},{"from":300,"to":334,"value":13},{"from":335,"to":345,"value":13},{"from":346,"to":378,"value":13},{"from":379,"to":394,"value":13},{"from":395,"to":426,"value":13},{"from":427,"to":437,"value":13},{"from":438,"to":467,"value":13},{"from":468,"to":477,"value":13},{"from":478,"to":506,"value":13},{"from":507,"to":516,"value":13},{"from":517,"to":543,"value":13},{"from":544,"to":552,"value":13},{"from":553,"to":582,"value":13},{"from":583,"to":593,"value":13},{"from":594,"to":625,"value":13},{"from":626,"to":636,"value":13},{"from":637,"to":666,"value":13},{"from":667,"to":676,"value":13},{"from":677,"to":704,"value":13},{"from":705,"to":716,"value":13},{"from":717,"to":738,"value":13},{"from":739,"to":750,"value":13},{"from":751,"to":781,"value":13},{"from":782,"to":794,"value":13},{"from":795,"to":827,"value":13},{"from":828,"to":836,"value":13},{"from":837,"to":859,"value":13},{"from":860,"to":870,"value":13},{"from":871,"to":882,"value":13},{"from":883,"to":894,"value":13},{"from":895,"to":913,"value":13},{"from":914,"to":924,"value":13},{"from":925,"to":941,"value":13},{"from":942,"to":951,"value":13},{"from":952,"to":981,"value":13},{"from":982,"to":991,"value":13},{"from":992,"to":1011,"value":13},{"from":1012,"to":1021,"value":13},{"from":1022,"to":1046,"value":13},{"from":1047,"to":1061,"value":13},{"from":1062,"to":1085,"value":13},{"from":1086,"to":1097,"value":13},{"from":1098,"to":1115,"value":13},{"from":1116,"to":1128,"value":13},{"from":1129,"to":1151,"value":13},{"from":1152,"to":1160,"value":13},{"from":1161,"to":1182,"value":13},{"from":1183,"to":1193,"value":13},{"from":1194,"to":1220,"value":13},{"from":1221,"to":1229,"value":13},{"from":1230,"to":1255,"value":13},{"from":1256,"to":1265,"value":13},{"from":1266,"to":1275,"value":13},{"from":1276,"to":1285,"value":13},{"from":1286,"to":1313,"value":13},{"from":1314,"to":1326,"value":13},{"from":1327,"to":1359,"value":13},{"from":1360,"to":1368,"value":13},{"from":1369,"to":1405,"value":13},{"from":1406,"to":1415,"value":13},{"from":1416,"to":1447,"value":13},{"from":1448,"to":1456,"value":13},{"from":1457,"to":1477,"value":13},{"from":1478,"to":1486,"value":13},{"from":1487,"to":1523,"value":13},{"from":1524,"to":1534,"value":13},{"from":1535,"to":1567,"value":13},{"from":1568,"to":1577,"value":13},{"from":1578,"to":1607,"value":13},{"from":1608,"to":1618,"value":13},{"from":1619,"to":1641,"value":13},{"from":1642,"to":1652,"value":13},{"from":1653,"to":1687,"value":13},{"from":1688,"to":1698,"value":13},{"from":1699,"to":1715,"value":13},{"from":1716,"to":1725,"value":13},{"from":1726,"to":1747,"value":13},{"from":1748,"to":1758,"value":13},{"from":1759,"to":1777,"value":13},{"from":1778,"to":1788,"value":13},{"from":1789,"to":1811,"value":13},{"from":1812,"to":1822,"value":13},{"from":1823,"to":1844,"value":13},{"from":1845,"to":1855,"value":13},{"from":1856,"to":1887,"value":13},{"from":1888,"to":1897,"value":13},{"from":1898,"to":1923,"value":13},{"from":1924,"to":1933,"value":13},{"from":1934,"to":1970,"value":13},{"from":1971,"to":1981,"value":13},{"from":1982,"to":2007,"value":13},{"from":2008,"to":2018,"value":13},{"from":2019,"to":2042,"value":13},{"from":2043,"to":2060,"value":13},{"from":2061,"to":2076,"value":13},{"from":2077,"to":2090,"value":13},{"from":2091,"to":2108,"value":13},{"from":2109,"to":2118,"value":13},{"from":2119,"to":2137,"value":13},{"from":2138,"to":2153,"value":13},{"from":2154,"to":2176,"value":13},{"from":2177,"to":2190,"value":13},{"from":2191,"to":2208,"value":13},{"from":2209,"to":2218,"value":13},{"from":2219,"to":2229,"value":13},{"from":2230,"to":2260,"value":13},{"from":2261,"to":2272,"value":13},{"from":2273,"to":2301,"value":13},{"from":2302,"to":2335,"value":13},{"from":2336,"to":2410,"value":13},{"from":2411,"to":2432,"value":13},{"from":2433,"to":2441,"value":13},{"from":2442,"to":2456,"value":13},{"from":2457,"to":2464,"value":13},{"from":2465,"to":2494,"value":13},{"from":2495,"to":2502,"value":13},{"from":2503,"to":2514,"value":13},{"from":2515,"to":2531,"value":13}],"color":[{"from":0,"to":28,"value":"#4d4d4c"},{"from":29,"to":34,"value":"#4d4d4c"},{"from":34,"to":46,"value":"#718c00"},{"from":47,"to":52,"value":"#4d4d4c"},{"from":52,"to":62,"value":"#718c00"},{"from":63,"to":68,"value":"#4d4d4c"},{"from":68,"to":81,"value":"#718c00"},{"from":82,"to":87,"value":"#4d4d4c"},{"from":87,"to":89,"value":"#718c00"},{"from":90,"to":95,"value":"#4d4d4c"},{"from":95,"to":107,"value":"#718c00"},{"from":108,"to":113,"value":"#4d4d4c"},{"from":113,"to":115,"value":"#718c00"},{"from":116,"to":121,"value":"#4d4d4c"},{"from":121,"to":133,"value":"#718c00"},{"from":134,"to":139,"value":"#4d4d4c"},{"from":139,"to":141,"value":"#718c00"},{"from":142,"to":147,"value":"#4d4d4c"},{"from":147,"to":156,"value":"#718c00"},{"from":157,"to":162,"value":"#4d4d4c"},{"from":162,"to":164,"value":"#718c00"},{"from":165,"to":170,"value":"#4d4d4c"},{"from":170,"to":179,"value":"#718c00"},{"from":180,"to":185,"value":"#4d4d4c"},{"from":185,"to":215,"value":"#718c00"},{"from":216,"to":221,"value":"#4d4d4c"},{"from":221,"to":232,"value":"#718c00"},{"from":233,"to":238,"value":"#4d4d4c"},{"from":238,"to":241,"value":"#718c00"},{"from":242,"to":247,"value":"#4d4d4c"},{"from":247,"to":266,"value":"#718c00"},{"from":267,"to":272,"value":"#4d4d4c"},{"from":272,"to":275,"value":"#718c00"},{"from":276,"to":281,"value":"#4d4d4c"},{"from":281,"to":290,"value":"#718c00"},{"from":291,"to":296,"value":"#4d4d4c"},{"from":296,"to":299,"value":"#718c00"},{"from":300,"to":305,"value":"#4d4d4c"},{"from":305,"to":334,"value":"#718c00"},{"from":335,"to":340,"value":"#4d4d4c"},{"from":340,"to":345,"value":"#718c00"},{"from":346,"to":351,"value":"#4d4d4c"},{"from":351,"to":378,"value":"#718c00"},{"from":379,"to":384,"value":"#4d4d4c"},{"from":384,"to":394,"value":"#718c00"},{"from":395,"to":400,"value":"#4d4d4c"},{"from":400,"to":426,"value":"#718c00"},{"from":427,"to":432,"value":"#4d4d4c"},{"from":432,"to":437,"value":"#718c00"},{"from":438,"to":443,"value":"#4d4d4c"},{"from":443,"to":467,"value":"#718c00"},{"from":468,"to":473,"value":"#4d4d4c"},{"from":473,"to":477,"value":"#718c00"},{"from":478,"to":483,"value":"#4d4d4c"},{"from":483,"to":506,"value":"#718c00"},{"from":507,"to":512,"value":"#4d4d4c"},{"from":512,"to":516,"value":"#718c00"},{"from":517,"to":522,"value":"#4d4d4c"},{"from":522,"to":543,"value":"#718c00"},{"from":544,"to":549,"value":"#4d4d4c"},{"from":549,"to":552,"value":"#718c00"},{"from":553,"to":558,"value":"#4d4d4c"},{"from":558,"to":582,"value":"#718c00"},{"from":583,"to":588,"value":"#4d4d4c"},{"from":588,"to":593,"value":"#718c00"},{"from":594,"to":599,"value":"#4d4d4c"},{"from":599,"to":625,"value":"#718c00"},{"from":626,"to":631,"value":"#4d4d4c"},{"from":631,"to":636,"value":"#718c00"},{"from":637,"to":642,"value":"#4d4d4c"},{"from":642,"to":666,"value":"#718c00"},{"from":667,"to":672,"value":"#4d4d4c"},{"from":672,"to":676,"value":"#718c00"},{"from":677,"to":682,"value":"#4d4d4c"},{"from":682,"to":704,"value":"#718c00"},{"from":705,"to":710,"value":"#4d4d4c"},{"from":710,"to":716,"value":"#718c00"},{"from":717,"to":722,"value":"#4d4d4c"},{"from":722,"to":738,"value":"#718c00"},{"from":739,"to":744,"value":"#4d4d4c"},{"from":744,"to":750,"value":"#718c00"},{"from":751,"to":756,"value":"#4d4d4c"},{"from":756,"to":781,"value":"#718c00"},{"from":782,"to":787,"value":"#4d4d4c"},{"from":787,"to":794,"value":"#718c00"},{"from":795,"to":800,"value":"#4d4d4c"},{"from":800,"to":827,"value":"#718c00"},{"from":828,"to":833,"value":"#4d4d4c"},{"from":833,"to":836,"value":"#718c00"},{"from":837,"to":842,"value":"#4d4d4c"},{"from":842,"to":859,"value":"#718c00"},{"from":860,"to":865,"value":"#4d4d4c"},{"from":865,"to":870,"value":"#718c00"},{"from":871,"to":876,"value":"#4d4d4c"},{"from":876,"to":882,"value":"#718c00"},{"from":883,"to":888,"value":"#4d4d4c"},{"from":888,"to":894,"value":"#718c00"},{"from":895,"to":900,"value":"#4d4d4c"},{"from":900,"to":913,"value":"#718c00"},{"from":914,"to":919,"value":"#4d4d4c"},{"from":919,"to":924,"value":"#718c00"},{"from":925,"to":930,"value":"#4d4d4c"},{"from":930,"to":941,"value":"#718c00"},{"from":942,"to":947,"value":"#4d4d4c"},{"from":947,"to":951,"value":"#718c00"},{"from":952,"to":957,"value":"#4d4d4c"},{"from":957,"to":981,"value":"#718c00"},{"from":982,"to":987,"value":"#4d4d4c"},{"from":987,"to":991,"value":"#718c00"},{"from":992,"to":997,"value":"#4d4d4c"},{"from":997,"to":1011,"value":"#718c00"},{"from":1012,"to":1017,"value":"#4d4d4c"},{"from":1017,"to":1021,"value":"#718c00"},{"from":1022,"to":1027,"value":"#4d4d4c"},{"from":1027,"to":1046,"value":"#718c00"},{"from":1047,"to":1052,"value":"#4d4d4c"},{"from":1052,"to":1061,"value":"#718c00"},{"from":1062,"to":1067,"value":"#4d4d4c"},{"from":1067,"to":1085,"value":"#718c00"},{"from":1086,"to":1091,"value":"#4d4d4c"},{"from":1091,"to":1097,"value":"#718c00"},{"from":1098,"to":1103,"value":"#4d4d4c"},{"from":1103,"to":1115,"value":"#718c00"},{"from":1116,"to":1121,"value":"#4d4d4c"},{"from":1121,"to":1128,"value":"#718c00"},{"from":1129,"to":1134,"value":"#4d4d4c"},{"from":1134,"to":1151,"value":"#718c00"},{"from":1152,"to":1157,"value":"#4d4d4c"},{"from":1157,"to":1160,"value":"#718c00"},{"from":1161,"to":1166,"value":"#4d4d4c"},{"from":1166,"to":1182,"value":"#718c00"},{"from":1183,"to":1188,"value":"#4d4d4c"},{"from":1188,"to":1193,"value":"#718c00"},{"from":1194,"to":1199,"value":"#4d4d4c"},{"from":1199,"to":1220,"value":"#718c00"},{"from":1221,"to":1226,"value":"#4d4d4c"},{"from":1226,"to":1229,"value":"#718c00"},{"from":1230,"to":1235,"value":"#4d4d4c"},{"from":1235,"to":1255,"value":"#718c00"},{"from":1256,"to":1261,"value":"#4d4d4c"},{"from":1261,"to":1265,"value":"#718c00"},{"from":1266,"to":1271,"value":"#4d4d4c"},{"from":1271,"to":1275,"value":"#718c00"},{"from":1276,"to":1281,"value":"#4d4d4c"},{"from":1281,"to":1285,"value":"#718c00"},{"from":1286,"to":1291,"value":"#4d4d4c"},{"from":1291,"to":1313,"value":"#718c00"},{"from":1314,"to":1319,"value":"#4d4d4c"},{"from":1319,"to":1326,"value":"#718c00"},{"from":1327,"to":1332,"value":"#4d4d4c"},{"from":1332,"to":1359,"value":"#718c00"},{"from":1360,"to":1365,"value":"#4d4d4c"},{"from":1365,"to":1368,"value":"#718c00"},{"from":1369,"to":1374,"value":"#4d4d4c"},{"from":1374,"to":1405,"value":"#718c00"},{"from":1406,"to":1411,"value":"#4d4d4c"},{"from":1411,"to":1415,"value":"#718c00"},{"from":1416,"to":1421,"value":"#4d4d4c"},{"from":1421,"to":1447,"value":"#718c00"},{"from":1448,"to":1453,"value":"#4d4d4c"},{"from":1453,"to":1456,"value":"#718c00"},{"from":1457,"to":1462,"value":"#4d4d4c"},{"from":1462,"to":1477,"value":"#718c00"},{"from":1478,"to":1483,"value":"#4d4d4c"},{"from":1483,"to":1486,"value":"#718c00"},{"from":1487,"to":1492,"value":"#4d4d4c"},{"from":1492,"to":1523,"value":"#718c00"},{"from":1524,"to":1529,"value":"#4d4d4c"},{"from":1529,"to":1534,"value":"#718c00"},{"from":1535,"to":1540,"value":"#4d4d4c"},{"from":1540,"to":1567,"value":"#718c00"},{"from":1568,"to":1573,"value":"#4d4d4c"},{"from":1573,"to":1577,"value":"#718c00"},{"from":1578,"to":1583,"value":"#4d4d4c"},{"from":1583,"to":1607,"value":"#718c00"},{"from":1608,"to":1613,"value":"#4d4d4c"},{"from":1613,"to":1618,"value":"#718c00"},{"from":1619,"to":1624,"value":"#4d4d4c"},{"from":1624,"to":1641,"value":"#718c00"},{"from":1642,"to":1647,"value":"#4d4d4c"},{"from":1647,"to":1652,"value":"#718c00"},{"from":1653,"to":1658,"value":"#4d4d4c"},{"from":1658,"to":1687,"value":"#718c00"},{"from":1688,"to":1693,"value":"#4d4d4c"},{"from":1693,"to":1698,"value":"#718c00"},{"from":1699,"to":1704,"value":"#4d4d4c"},{"from":1704,"to":1715,"value":"#718c00"},{"from":1716,"to":1721,"value":"#4d4d4c"},{"from":1721,"to":1725,"value":"#718c00"},{"from":1726,"to":1731,"value":"#4d4d4c"},{"from":1731,"to":1747,"value":"#718c00"},{"from":1748,"to":1753,"value":"#4d4d4c"},{"from":1753,"to":1758,"value":"#718c00"},{"from":1759,"to":1764,"value":"#4d4d4c"},{"from":1764,"to":1777,"value":"#718c00"},{"from":1778,"to":1783,"value":"#4d4d4c"},{"from":1783,"to":1788,"value":"#718c00"},{"from":1789,"to":1794,"value":"#4d4d4c"},{"from":1794,"to":1811,"value":"#718c00"},{"from":1812,"to":1817,"value":"#4d4d4c"},{"from":1817,"to":1822,"value":"#718c00"},{"from":1823,"to":1828,"value":"#4d4d4c"},{"from":1828,"to":1844,"value":"#718c00"},{"from":1845,"to":1850,"value":"#4d4d4c"},{"from":1850,"to":1855,"value":"#718c00"},{"from":1856,"to":1861,"value":"#4d4d4c"},{"from":1861,"to":1887,"value":"#718c00"},{"from":1888,"to":1893,"value":"#4d4d4c"},{"from":1893,"to":1897,"value":"#718c00"},{"from":1898,"to":1903,"value":"#4d4d4c"},{"from":1903,"to":1923,"value":"#718c00"},{"from":1924,"to":1929,"value":"#4d4d4c"},{"from":1929,"to":1933,"value":"#718c00"},{"from":1934,"to":1939,"value":"#4d4d4c"},{"from":1939,"to":1970,"value":"#718c00"},{"from":1971,"to":1976,"value":"#4d4d4c"},{"from":1976,"to":1981,"value":"#718c00"},{"from":1982,"to":1987,"value":"#4d4d4c"},{"from":1987,"to":2007,"value":"#718c00"},{"from":2008,"to":2013,"value":"#4d4d4c"},{"from":2013,"to":2018,"value":"#718c00"},{"from":2019,"to":2024,"value":"#4d4d4c"},{"from":2024,"to":2042,"value":"#718c00"},{"from":2043,"to":2048,"value":"#4d4d4c"},{"from":2048,"to":2060,"value":"#718c00"},{"from":2061,"to":2066,"value":"#4d4d4c"},{"from":2066,"to":2076,"value":"#718c00"},{"from":2077,"to":2082,"value":"#4d4d4c"},{"from":2082,"to":2090,"value":"#718c00"},{"from":2091,"to":2096,"value":"#4d4d4c"},{"from":2096,"to":2108,"value":"#718c00"},{"from":2109,"to":2114,"value":"#4d4d4c"},{"from":2114,"to":2118,"value":"#718c00"},{"from":2119,"to":2124,"value":"#4d4d4c"},{"from":2124,"to":2137,"value":"#718c00"},{"from":2138,"to":2143,"value":"#4d4d4c"},{"from":2143,"to":2153,"value":"#718c00"},{"from":2154,"to":2159,"value":"#4d4d4c"},{"from":2159,"to":2176,"value":"#718c00"},{"from":2177,"to":2182,"value":"#4d4d4c"},{"from":2182,"to":2190,"value":"#718c00"},{"from":2191,"to":2196,"value":"#4d4d4c"},{"from":2196,"to":2208,"value":"#718c00"},{"from":2209,"to":2214,"value":"#4d4d4c"},{"from":2214,"to":2218,"value":"#718c00"},{"from":2219,"to":2224,"value":"#4d4d4c"},{"from":2224,"to":2229,"value":"#718c00"},{"from":2230,"to":2235,"value":"#4d4d4c"},{"from":2235,"to":2260,"value":"#718c00"},{"from":2261,"to":2266,"value":"#4d4d4c"},{"from":2266,"to":2272,"value":"#718c00"},{"from":2273,"to":2278,"value":"#4d4d4c"},{"from":2278,"to":2301,"value":"#718c00"},{"from":2302,"to":2307,"value":"#4d4d4c"},{"from":2307,"to":2335,"value":"#718c00"},{"from":2336,"to":2341,"value":"#4d4d4c"},{"from":2341,"to":2410,"value":"#718c00"},{"from":2411,"to":2416,"value":"#4d4d4c"},{"from":2416,"to":2432,"value":"#718c00"},{"from":2433,"to":2438,"value":"#4d4d4c"},{"from":2438,"to":2441,"value":"#718c00"},{"from":2442,"to":2447,"value":"#4d4d4c"},{"from":2447,"to":2456,"value":"#718c00"},{"from":2457,"to":2462,"value":"#4d4d4c"},{"from":2462,"to":2464,"value":"#718c00"},{"from":2465,"to":2470,"value":"#4d4d4c"},{"from":2470,"to":2494,"value":"#718c00"},{"from":2495,"to":2500,"value":"#4d4d4c"},{"from":2500,"to":2502,"value":"#718c00"},{"from":2503,"to":2508,"value":"#4d4d4c"},{"from":2508,"to":2514,"value":"#718c00"},{"from":2515,"to":2520,"value":"#4d4d4c"},{"from":2520,"to":2531,"value":"#718c00"}],"back-color":[{"from":0,"to":28,"value":"#f7f7f7"},{"from":29,"to":46,"value":"#f7f7f7"},{"from":47,"to":62,"value":"#f7f7f7"},{"from":63,"to":81,"value":"#f7f7f7"},{"from":82,"to":89,"value":"#f7f7f7"},{"from":90,"to":107,"value":"#f7f7f7"},{"from":108,"to":115,"value":"#f7f7f7"},{"from":116,"to":133,"value":"#f7f7f7"},{"from":134,"to":141,"value":"#f7f7f7"},{"from":142,"to":156,"value":"#f7f7f7"},{"from":157,"to":164,"value":"#f7f7f7"},{"from":165,"to":179,"value":"#f7f7f7"},{"from":180,"to":215,"value":"#f7f7f7"},{"from":216,"to":232,"value":"#f7f7f7"},{"from":233,"to":241,"value":"#f7f7f7"},{"from":242,"to":266,"value":"#f7f7f7"},{"from":267,"to":275,"value":"#f7f7f7"},{"from":276,"to":290,"value":"#f7f7f7"},{"from":291,"to":299,"value":"#f7f7f7"},{"from":300,"to":334,"value":"#f7f7f7"},{"from":335,"to":345,"value":"#f7f7f7"},{"from":346,"to":378,"value":"#f7f7f7"},{"from":379,"to":394,"value":"#f7f7f7"},{"from":395,"to":426,"value":"#f7f7f7"},{"from":427,"to":437,"value":"#f7f7f7"},{"from":438,"to":467,"value":"#f7f7f7"},{"from":468,"to":477,"value":"#f7f7f7"},{"from":478,"to":506,"value":"#f7f7f7"},{"from":507,"to":516,"value":"#f7f7f7"},{"from":517,"to":543,"value":"#f7f7f7"},{"from":544,"to":552,"value":"#f7f7f7"},{"from":553,"to":582,"value":"#f7f7f7"},{"from":583,"to":593,"value":"#f7f7f7"},{"from":594,"to":625,"value":"#f7f7f7"},{"from":626,"to":636,"value":"#f7f7f7"},{"from":637,"to":666,"value":"#f7f7f7"},{"from":667,"to":676,"value":"#f7f7f7"},{"from":677,"to":704,"value":"#f7f7f7"},{"from":705,"to":716,"value":"#f7f7f7"},{"from":717,"to":738,"value":"#f7f7f7"},{"from":739,"to":750,"value":"#f7f7f7"},{"from":751,"to":781,"value":"#f7f7f7"},{"from":782,"to":794,"value":"#f7f7f7"},{"from":795,"to":827,"value":"#f7f7f7"},{"from":828,"to":836,"value":"#f7f7f7"},{"from":837,"to":859,"value":"#f7f7f7"},{"from":860,"to":870,"value":"#f7f7f7"},{"from":871,"to":882,"value":"#f7f7f7"},{"from":883,"to":894,"value":"#f7f7f7"},{"from":895,"to":913,"value":"#f7f7f7"},{"from":914,"to":924,"value":"#f7f7f7"},{"from":925,"to":941,"value":"#f7f7f7"},{"from":942,"to":951,"value":"#f7f7f7"},{"from":952,"to":981,"value":"#f7f7f7"},{"from":982,"to":991,"value":"#f7f7f7"},{"from":992,"to":1011,"value":"#f7f7f7"},{"from":1012,"to":1021,"value":"#f7f7f7"},{"from":1022,"to":1046,"value":"#f7f7f7"},{"from":1047,"to":1061,"value":"#f7f7f7"},{"from":1062,"to":1085,"value":"#f7f7f7"},{"from":1086,"to":1097,"value":"#f7f7f7"},{"from":1098,"to":1115,"value":"#f7f7f7"},{"from":1116,"to":1128,"value":"#f7f7f7"},{"from":1129,"to":1151,"value":"#f7f7f7"},{"from":1152,"to":1160,"value":"#f7f7f7"},{"from":1161,"to":1182,"value":"#f7f7f7"},{"from":1183,"to":1193,"value":"#f7f7f7"},{"from":1194,"to":1220,"value":"#f7f7f7"},{"from":1221,"to":1229,"value":"#f7f7f7"},{"from":1230,"to":1255,"value":"#f7f7f7"},{"from":1256,"to":1265,"value":"#f7f7f7"},{"from":1266,"to":1275,"value":"#f7f7f7"},{"from":1276,"to":1285,"value":"#f7f7f7"},{"from":1286,"to":1313,"value":"#f7f7f7"},{"from":1314,"to":1326,"value":"#f7f7f7"},{"from":1327,"to":1359,"value":"#f7f7f7"},{"from":1360,"to":1368,"value":"#f7f7f7"},{"from":1369,"to":1405,"value":"#f7f7f7"},{"from":1406,"to":1415,"value":"#f7f7f7"},{"from":1416,"to":1447,"value":"#f7f7f7"},{"from":1448,"to":1456,"value":"#f7f7f7"},{"from":1457,"to":1477,"value":"#f7f7f7"},{"from":1478,"to":1486,"value":"#f7f7f7"},{"from":1487,"to":1523,"value":"#f7f7f7"},{"from":1524,"to":1534,"value":"#f7f7f7"},{"from":1535,"to":1567,"value":"#f7f7f7"},{"from":1568,"to":1577,"value":"#f7f7f7"},{"from":1578,"to":1607,"value":"#f7f7f7"},{"from":1608,"to":1618,"value":"#f7f7f7"},{"from":1619,"to":1641,"value":"#f7f7f7"},{"from":1642,"to":1652,"value":"#f7f7f7"},{"from":1653,"to":1687,"value":"#f7f7f7"},{"from":1688,"to":1698,"value":"#f7f7f7"},{"from":1699,"to":1715,"value":"#f7f7f7"},{"from":1716,"to":1725,"value":"#f7f7f7"},{"from":1726,"to":1747,"value":"#f7f7f7"},{"from":1748,"to":1758,"value":"#f7f7f7"},{"from":1759,"to":1777,"value":"#f7f7f7"},{"from":1778,"to":1788,"value":"#f7f7f7"},{"from":1789,"to":1811,"value":"#f7f7f7"},{"from":1812,"to":1822,"value":"#f7f7f7"},{"from":1823,"to":1844,"value":"#f7f7f7"},{"from":1845,"to":1855,"value":"#f7f7f7"},{"from":1856,"to":1887,"value":"#f7f7f7"},{"from":1888,"to":1897,"value":"#f7f7f7"},{"from":1898,"to":1923,"value":"#f7f7f7"},{"from":1924,"to":1933,"value":"#f7f7f7"},{"from":1934,"to":1970,"value":"#f7f7f7"},{"from":1971,"to":1981,"value":"#f7f7f7"},{"from":1982,"to":2007,"value":"#f7f7f7"},{"from":2008,"to":2018,"value":"#f7f7f7"},{"from":2019,"to":2042,"value":"#f7f7f7"},{"from":2043,"to":2060,"value":"#f7f7f7"},{"from":2061,"to":2076,"value":"#f7f7f7"},{"from":2077,"to":2090,"value":"#f7f7f7"},{"from":2091,"to":2108,"value":"#f7f7f7"},{"from":2109,"to":2118,"value":"#f7f7f7"},{"from":2119,"to":2137,"value":"#f7f7f7"},{"from":2138,"to":2153,"value":"#f7f7f7"},{"from":2154,"to":2176,"value":"#f7f7f7"},{"from":2177,"to":2190,"value":"#f7f7f7"},{"from":2191,"to":2208,"value":"#f7f7f7"},{"from":2209,"to":2218,"value":"#f7f7f7"},{"from":2219,"to":2229,"value":"#f7f7f7"},{"from":2230,"to":2260,"value":"#f7f7f7"},{"from":2261,"to":2272,"value":"#f7f7f7"},{"from":2273,"to":2301,"value":"#f7f7f7"},{"from":2302,"to":2335,"value":"#f7f7f7"},{"from":2336,"to":2410,"value":"#f7f7f7"},{"from":2411,"to":2432,"value":"#f7f7f7"},{"from":2433,"to":2441,"value":"#f7f7f7"},{"from":2442,"to":2456,"value":"#f7f7f7"},{"from":2457,"to":2464,"value":"#f7f7f7"},{"from":2465,"to":2494,"value":"#f7f7f7"},{"from":2495,"to":2502,"value":"#f7f7f7"},{"from":2503,"to":2514,"value":"#f7f7f7"},{"from":2515,"to":2531,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[620]}
4148-1552017673557具体解释041604#55555504#ffffffjustify7482-1552017673557Redis 默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程daemonize no04316435513055#555555043#ffffff4355#eeeeeejustify6637-1552017673557当 Redis 以守护进程方式运行时,Redis 默认会把 pid 写入 /var/run/redis.pid 文件,可以通过 pidfile 指定 pidfile /var/run/redis.pid0371637551355641664711371751675101130101#555555037#ffffff3755#eeeeee5564#ffffff6471#eeeeee7175#ffffff75101#eeeeeejustify9374-1552017673557指定 Redis 监听端口,默认端口为 6379 port 6379,如果端口设置为 0 的话,redis 便不监听端口了。此时可以通过 unix socket 方式来和外部通信,比如 /unixsocket /tmp/redis.sock, unixsocketperm 75502516253413349316931201312012216122140130140#555555025#ffffff2534#eeeeee3493#ffffff93120#eeeeee120122#ffffff122140#eeeeeejustify8340-1552017673557绑定的主机地址 bind 127.0.0.1081682213022#55555508#ffffff822#eeeeeejustify0080-1552017673557当客户端闲置多长时间后关闭连接,如果指定为 0,表示关闭该功能 timeout 30003216324313043#555555032#ffffff3243#eeeeeejustify4180-1552017673557TCP 连接保活策略,可以通过 tcp-keepalive 配置项来进行设置,单位为秒,假如设置为 60 秒,则 server 端会每 60 秒向连接空闲的客户端发起一次ACK请求,以检查客户端是否已经挂掉,对于无响应的客户端则会关闭其连接。所以关闭一个连接最长需要120秒的时间。如果设置为0,则不会进行保活检测:tcp-keepalive 0015816158173130173#5555550158#ffffff158173#eeeeeejustify9081-1552017673557指定日志记录级别,Redis 总共支持四个级别:debug、verbose、notice、warning,默认为 verbose, loglevel verbose06616668213082#555555066#ffffff6682#eeeeeejustify9452-1552017673557日志记录方式,默认为标准输出,如果配置 Redis 为守护进程方式运行,而这里又配置为日志记录方式为标准输出,则日志将会发送给 /dev/null, logfile stdout07516758913089#555555075#ffffff7589#eeeeeejustify1750-1552017673557设置数据库的数量,默认数据库为 0,可以使用 SELECT <dbid> 命令在连接上指定数据库 id, databases 16,这16个数据库的编号将是0到15。默认的数据库是编号为0的数据库。用户可以使用select 来选择相应的数据库。0231623361336531653651365122160122#555555023#ffffff2336#eeeeee3653#ffffff5365#eeeeee65122#ffffffjustify8643-1552017673557指定在多长时间内,有多少次更新操作,就将数据同步到数据文件(快照),可以多个条件配合 save <seconds> <changes>Redis默认配置文件中提供了三个条件:save 900 1, save 300 10, save 60 10000, 分别表示 900 秒(15 分钟)内有 1 个更改,300 秒(5 分钟)内有 10 个更改以及 60 秒内有 10000 个更改。0431643671367871687971397991699110131101121611212513125193160193#555555043#ffffff4367#eeeeee6787#ffffff8797#eeeeee9799#ffffff99110#eeeeee110112#ffffff112125#eeeeee125193#ffffffjustify1627-1552017673557如果你想禁用RDB持久化的策略,只要不设置任何save指令就可以,或者给save传入一个空字符串参数也可以达到相同效果 save ""06016606713067#555555060#ffffff6067#eeeeeejustify2759-1552017673557如果用户开启了RDB快照功能,那么在redis持久化数据到磁盘时如果出现失败,默认情况下,redis会停止接受所有的写请求。这样做的好处在于可以让用户很明确的知道内存中的数据和磁盘上的数据已经存在不一致了。如果redis不顾这种不一致,一意孤行的继续接收写请求,就可能会引起一些灾难性的后果。如果下一次RDB持久化成功,redis会自动恢复接受写请求。0176160176#5555550176#ffffffjustify5916-1552017673557如果你不在乎这种数据不一致或者有其他的手段发现和控制这种不一致的话,你完全可以关闭这个功能,以便在快照写入失败时,也能确保 redis 继续接受新的写请求: stop-writes-on-bgsave-error yes0791679110130110#555555079#ffffff79110#eeeeeejustify4217-1552017673557指定存储至本地数据库时是否压缩数据,默认为 yes,Redis 采用 LZF 压缩,如果为了节省 CPU 时间,可以关闭该选项,但会导致数据库文件变的巨大 rdbcompression yes07816789613096#555555078#ffffff7896#eeeeeejustify3217-1552017673558在存储快照后,我们还可以让 redis 使用 CRC64 算法来进行数据校验,但是这样做会增加大约 10% 的性能消耗,如果你希望获取到最大的性能提升,可以关闭此功能 rdbchecksum yes08416849913099#555555084#ffffff8499#eeeeeejustify7611-1552017673558设置快照文件的名称,默认值为 dump.rdb, dbfilename dump.rdb02516254413044#555555025#ffffff2544#eeeeeejustify1078-1552017673558设置快照文件的存放位置 dir ./01216121813018#555555012#ffffff1218#eeeeeejustify4038-1552017673558通过 slaveof 配置项可以控制某一个redis作为另一个redis的从服务器,通过指定IP和端口来定位到主redis的位置。一般情况下,我们会建议用户为从redis设置一个不同频率的快照持久化的周期,或者为从redis配置一个不同的服务端口等等。设置当本机为 slave 服务时,设置 master 服务的IP地址及端口,在 Redis 启动时,它会自动从 master 进行数据同步 slaveof <masterip> <masterport>019616196227130227#5555550196#ffffff196227#eeeeeejustify1278-1552017673558当 master 服务设置了密码保护时,slave 服务连接 master 的密码 masterauth <master-password>04216427013070#555555042#ffffff4270#eeeeeejustify1018-1552017673558设置 Redis 连接密码,如果配置了连接密码,客户端在连接 Redis 时需要通过 AUTH <password> 命令提供密码,默认关闭 requirepass foobared04316435813587116719113091#555555043#ffffff4358#eeeeee5871#ffffff7191#eeeeeejustify3818-1552017673558当从 redis 失去了与主 redis 的连接,或者主从同步正在进行中时,redis 该如何处理外部发来的访问请求呢?这里,从 redis 可以有两种选择:如果 slave-serve-stale-data设置为yes(默认),则从 redis 仍会继续响应客户端的读写请求。如果slave-serve-stale-data设置为no,则从 redis 会对客户端的请求返回“SYNC with master in progress”,当然也有例外,当客户端发来 INFO 请求和 SLAVEOF 请求,从 redis 还是会进行处理。0269160269#5555550269#ffffffjustify6687-1552017673558你可以控制一个从 redis 是否可以接受写请求。将数据直接写入从 redis,一般只适用于那些生命周期非常短的数据,因为在主从同步时,这些临时数据就会被清理掉。自从 redis2.6 版本之后,默认从 redis 为只读 slave-read-only yes011216112131130131#5555550112#ffffff112131#eeeeeejustify5570-1552017673558只读的从 redis 并不适合直接暴露给不可信的客户端。为了尽量降低风险,可以使用 rename-command 指令来将一些可能有破坏力的命令重命名,避免外部直接调用 rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c520851685147130147#555555085#ffffff85147#eeeeeejustify1916-1552017673558我们甚至可以禁用掉CONFIG命令,那就是把CONFIG的名字改成一个空字符串 rename-command CONFIG "" 但需要注意的是,如果你使用AOF方式进行数据持久化,或者需要与从redis进行通信,那么更改指令的名字可能会引起一些问题。0401640641364126160126#555555040#ffffff4064#eeeeee64126#ffffffjustify9215-1552017673558从 redis 会周期性的向主 redis 发出 PING 包。默认是10秒 repl-ping-slave-period 1003916396413064#555555039#ffffff3964#eeeeeejustify7071-1552017673558在主从同步时,可能在这些情况下会有超时发生:1.以从redis的角度来看,当有大规模IO传输时。2.以从redis的角度来看,当数据传输或PING时,主redis超时。3.以主redis的角度来看,在回复从redis的PING时,从redis超时。用户可以设置上述超时的时限,不过要确保这个时限比 repl-ping-slave-period的值要大,否则每次主 redis 都会认为从 redis 超时 repl-timeout 600149161491711317120316203218130218#5555550149#ffffff149171#eeeeee171203#ffffff203218#eeeeeejustify5789-1552017673558我们可以控制在主从同步时是否禁用 TCP_NODELAY。如果开启 TCP_NODELAY,那么主 redis 会使用更少的 TCP 包和更少的带宽来向从 redis 传输数据。但是这可能会增加一些同步的延迟,大概会达到40毫秒左右。如果你关闭了 TCP_NODELAY,那么数据同步的延迟时间会降低,但是会消耗更多的带宽 repl-disable-tcp-nodelay no0171617281328341634451345124161241351313516216162189130189#555555017#ffffff1728#eeeeee2834#ffffff3445#eeeeee45124#ffffff124135#eeeeee135162#ffffff162189#eeeeeejustify2541-1552017673558我们还可以设置同步队列长度。队列长度(backlog)是主 redis 中的一个缓冲区,在与从 redis 断开连接期间,主 redis 会用这个缓冲区来缓存应该发给从 redis 的数据。这样的话,当从 redis 重新连接上之后,就不必重新全量同步数据,只需要同步这部分增量数据即可 repl-backlog-size 1mb014416144165130165#5555550144#ffffff144165#eeeeeejustify6342-1552017673558如果主 redis 等了一段时间之后,还是无法连接到从 redis,那么缓冲队列中的数据将被清理掉。我们可以设置主 redis 要等待的时间长度。如果设置为 0,则表示永远不清理。默认是 1 个小时 repl-backlog-ttl 3600010016100121130121#5555550100#ffffff100121#eeeeeejustify7424-1552017673558我们可以给众多的从redis设置优先级,在主redis持续工作不正常的情况,优先级高的从redis将会升级为主redis。而编号越小,优先级越高。比如一个主redis有三个从redis,优先级编号分别为10、100、25,那么编号为10的从redis将会被首先选中升级为主redis。当优先级被设置为0时,这个从redis将永远也不会被选中。默认的优先级为100 slave-priority 100018216182200130200#5555550182#ffffff182200#eeeeeejustify5232-1552017673558假如主 redis 发现有超过 M 个从 redis 的连接延时大于 N 秒,那么主 redis 就停止接受外来的写请求。这是因为从 redis 一般会每秒钟都向主 redis 发出 PING,而主 redis 会记录每一个从 redis 最近一次发来 PING 的时间点,所以主 redis 能够了解每一个从 redis 的运行情况 min-slaves-to-write 3,min-slaves-max-lag 100168161681891318919016190211130211#5555550168#ffffff168189#eeeeee189190#ffffff190211#eeeeeejustify5324-1552017673558设置同一时间最大客户端连接数,默认无限制,Redis 可以同时打开的客户端连接数为Redis 进程可以打开的最大文件描述符数,如果设置 maxclients 0,表示不作限制。当客户端连接数到达限制时,Redis 会关闭新的连接并向客户端返回 max number of clients reached 错误信息 maxclients 128015716157171130171#5555550157#ffffff157171#eeeeeejustify9431-1552017673558指定 Redis 最大内存限制,Redis 在启动时会把数据加载到内存中,达到最大内存后,Redis 会先尝试清除已到期或即将到期的 Key,当此方法处理后,仍然到达最大内存设置,将无法再进行写入操作,但仍然可以进行读取操作。Redis 新的 vm 机制,会把 Key 存放内存,Value 会存放在 swap 区, maxmemory <bytes>015916159176130176#5555550159#ffffff159176#eeeeeejustify5330-1552017673558需要注意的一点是,如果你的redis是主redis(说明你的redis有从redis),那么在设置内存使用上限时,需要在系统中留出一些内存空间给同步队列缓存,只有在你设置的是“不移除”的情况下,才不用考虑这个因素。0107160107#5555550107#ffffffjustify8325-1552017673558对于内存移除规则来说,redis提供了多达6种的移除规则。他们是:03316033#555555033#ffffffjustify7766-1552017673558volatile-lru:使用LRU算法移除过期集合中的key03116031#555555031#ffffffjustify8120-1552017673558allkeys-lru:使用LRU算法移除key02416024#555555024#ffffffjustify3660-1552017673558volatile-random:在过期集合中移除随机的key03016030#555555030#ffffffjustify1370-1552017673558allkeys-random:移除随机的key02316023#555555023#ffffffjustify7236-1552017673558volatile-ttl:移除那些TTL值最小的key,即那些最近才过期的key。04116041#555555041#ffffffjustify9165-1552017673558noeviction:不进行移除。针对写操作,只是返回错误信息。03216032#555555032#ffffffjustify4770-1552017673558无论使用上述哪一种移除规则,如果没有合适的key可以移除的话,redis都会针对写请求返回错误信息。05016050#555555050#ffffffjustify5817-1552017673558LRU算法和最小TTL算法都并非是精确的算法,而是估算值。所以你可以设置样本的大小。假如redis默认会检查三个key并选择其中LRU的那个,那么你可以改变这个key样本的数量 maxmemory-samples 30891689108130108#555555089#ffffff89108#eeeeeejustify7776-1552017673558指定是否在每次更新操作后进行日志记录,Redis 在默认情况下是异步的把数据写入磁盘,如果不开启,可能会在断电时导致一段时间内的数据丢失。因为 redis 本身同步数据文件是按上面 save 条件来同步的,所以有的数据会在一段时间内只存在于内存中。默认为 no, appendonly no013216132145130145#5555550132#ffffff132145#eeeeeejustify3837-1552017673558指定更新日志文件名,默认为 appendonly.aof, appendfilename appendonly.aof03016305913059#555555030#ffffff3059#eeeeeejustify6467-1552017673558指定更新日志条件,共有3个可选值:01716017#555555017#ffffffjustify3036-1552017673558no:表示等操作系统进行数据缓存同步到磁盘(快)02416024#555555024#ffffffjustify8072-1552017673558always:表示每次更新操作后手动调用fsync()将数据写到磁盘(慢,安全)04016040#555555040#ffffffjustify1864-1552017673558everysec:表示每秒同步一次(折衷,默认值)appendfsync everysec02516254513045#555555025#ffffff2545#eeeeeejustify6258-1552017673558指定是否启用虚拟内存机制,默认值为 no,简单的介绍一下,VM 机制将数据分页存放,由Redi s将访问量较少的页即冷数据 swap 到磁盘上,访问多的页面由磁盘自动换出到内存中 vm-enabled no0901690103130103#555555090#ffffff90103#eeeeeejustify9025-1552017673558虚拟内存文件路径,默认值为 /tmp/redis.swap,不可多个 Redis 实例共享 vm-swap-file /tmp/redis.swap01416142913294616467413074#555555014#ffffff1429#eeeeee2946#ffffff4674#eeeeeejustify7165-1552017673558将所有大于 vm-max-memory 的数据存入虚拟内存,无论 vm-max-memory 设置多小,所有索引数据都是内存存储的(Redis 的索引数据 就是 keys),也就是说,当 vm-max-memory 设置为 0 的时候,其实是所有 value 都存在于磁盘。默认值为 0, vm-max-memory 0014516145160130160#5555550145#ffffff145160#eeeeeejustify4511-1552017673558Redis swap 文件分成了很多的 page,一个对象可以保存在多个 page 上面,但一个 page 上不能被多个对象共享,vm-page-size 是要根据存储的 数据大小来设定的,作者建议如果存储很多小对象,page 大小最好设置为 32 或者 64bytes;如果存储很大大对象,则可以使用更大的 page,如果不确定,就使用默认值 vm-page-size 32017316173188130188#5555550173#ffffff173188#eeeeeejustify7693-1552017673558设置 swap 文件中的 page 数量,由于页表(一种表示页面空闲或使用的 bitmap)是在放在内存中的,在磁盘上每 8 个 pages 将消耗 1byte 的内存。vm-pages 1342177280851685103130103#555555085#ffffff85103#eeeeeejustify8767-1552017673558设置访问 swap 文件的线程数,最好不要超过机器的核数,如果设置为 0,那么所有对 swap 文件的操作都是串行的,可能会造成比较长时间的延迟。默认值为 4, vm-max-threads 408116819713097#555555081#ffffff8197#eeeeeejustify8539-1552017673558设置在向客户端应答时,是否把较小的包合并为一个包发送,默认为开启 glueoutputbuf yes03316335013050#555555033#ffffff3350#eeeeeejustify8467-1552017673558指定在超过一定的数量或者最大的元素超过某一临界值时,采用一种特殊的哈希算法, hash-max-zipmap-entries 64, hash-max-zipmap-value 51203916396513656716679213092#555555039#ffffff3965#eeeeee6567#ffffff6792#eeeeeejustify3745-1552017673558指定是否激活重置哈希,默认为开启(后面在介绍Redis的哈希算法时具体介绍)activerehashing yes03816385713057#555555038#ffffff3857#eeeeeejustify2283-1552017673558指定包含其它的配置文件,可以在同一主机上多个 Redis 实例之间使用同一份配置文件,而同时各个实例又拥有自己的特定配置文件 include /path/to/local.conf06316639013090#555555063#ffffff6390#eeeeeejustify4096-1552017673558lua脚本的最大运行时间是需要被严格限制的,要注意单位是毫秒 lua-time-limit 5000。如果此值设置为0或负数,则既不会有报错也不会有时间限制03116315013507816078#555555031#ffffff3150#eeeeee5078#ffffffjustify8070-1552017673558数据结构04true042204#55555504#ffffffjustify1.57332-1552017673558Redis 中的 value 支持五种数据类型: strings, lists, sets, sorted sets, hashes。关于 key 的设计,有几点需要注意:08616086#555555086#ffffffjustify1262-1552017673558key 不要太长,尽量不要超过 1024 字节,这不仅消耗内存,而且会降低查找的效率;04316043#555555043#ffffffjustify5383-1552017673558key 也不要太短,否则可读性会降低;01916019#555555019#ffffffjustify1780-1552017673558在一个项目中,key 最好使用统一的命名模式,例如 user:10000:passwd02616264313043#555555026#ffffff2643#eeeeeejustify6198-1552017673558另外本文只是一个基本的指南,不会涵盖太多的命令,具体请参考 Redis 的官方文档。04216042#555555042#ffffffjustify9660-1552017673558Strings07true072007#55555507#ffffffjustify1.56480-1552017673558有人说,如果只使用 redis 中的字符串类型,且不使用 redis 的持久化功能,那么,redis 就和 memcache 非常非常的像了。我们可以做一些基本的尝试:08416084#555555084#ffffffjustify2098-1552017673558{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"127.0.0.1:6379> set visitcount \"2\"\nOK\n127.0.0.1:6379> get visitcount\n\"2\"\n127.0.0.1:6379> incr visitcount\n(integer) 3\n127.0.0.1:6379> get visitcount\n\"3\"","inlineStyles":{"font-size":[{"from":0,"to":34,"value":13},{"from":35,"to":37,"value":13},{"from":38,"to":68,"value":13},{"from":69,"to":72,"value":13},{"from":73,"to":104,"value":13},{"from":105,"to":116,"value":13},{"from":117,"to":147,"value":13},{"from":148,"to":151,"value":13}],"color":[{"from":0,"to":16,"value":"#4d4d4c"},{"from":16,"to":19,"value":"#f5871f"},{"from":19,"to":31,"value":"#4d4d4c"},{"from":31,"to":34,"value":"#718c00"},{"from":35,"to":37,"value":"#4d4d4c"},{"from":38,"to":68,"value":"#4d4d4c"},{"from":69,"to":72,"value":"#718c00"},{"from":73,"to":104,"value":"#4d4d4c"},{"from":105,"to":106,"value":"#4d4d4c"},{"from":106,"to":113,"value":"#f5871f"},{"from":113,"to":116,"value":"#4d4d4c"},{"from":117,"to":147,"value":"#4d4d4c"},{"from":148,"to":151,"value":"#718c00"}],"back-color":[{"from":0,"to":34,"value":"#f7f7f7"},{"from":35,"to":37,"value":"#f7f7f7"},{"from":38,"to":68,"value":"#f7f7f7"},{"from":69,"to":72,"value":"#f7f7f7"},{"from":73,"to":104,"value":"#f7f7f7"},{"from":105,"to":116,"value":"#f7f7f7"},{"from":117,"to":147,"value":"#f7f7f7"},{"from":148,"to":151,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[613]}
6560-1552017673558在遇到数值操作的时候,redis 会将字符串类型转换成数值,但是如果不是数值会怎么样呢?我们来试试看:05116051#555555051#ffffffjustify5229-1552017673558{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"127.0.0.1:6379> set test \"test\"\nOK\n127.0.0.1:6379> get test\n\"test\"\n127.0.0.1:6379> incr test\n(error) ERR value is not an integer or out of range","inlineStyles":{"font-size":[{"from":0,"to":31,"value":13},{"from":32,"to":34,"value":13},{"from":35,"to":59,"value":13},{"from":60,"to":66,"value":13},{"from":67,"to":92,"value":13},{"from":93,"to":144,"value":13}],"color":[{"from":0,"to":16,"value":"#4d4d4c"},{"from":16,"to":19,"value":"#f5871f"},{"from":19,"to":20,"value":"#4d4d4c"},{"from":20,"to":24,"value":"#f5871f"},{"from":24,"to":25,"value":"#4d4d4c"},{"from":25,"to":31,"value":"#718c00"},{"from":32,"to":34,"value":"#4d4d4c"},{"from":35,"to":55,"value":"#4d4d4c"},{"from":55,"to":59,"value":"#f5871f"},{"from":60,"to":66,"value":"#718c00"},{"from":67,"to":88,"value":"#4d4d4c"},{"from":88,"to":92,"value":"#f5871f"},{"from":93,"to":121,"value":"#4d4d4c"},{"from":121,"to":128,"value":"#f5871f"},{"from":128,"to":144,"value":"#4d4d4c"}],"back-color":[{"from":0,"to":31,"value":"#f7f7f7"},{"from":32,"to":34,"value":"#f7f7f7"},{"from":35,"to":59,"value":"#f7f7f7"},{"from":60,"to":66,"value":"#f7f7f7"},{"from":67,"to":92,"value":"#f7f7f7"},{"from":93,"to":144,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[615]}
7339-1552017673558Redis 中的数值操作指令有一个很好的特性是原子性,很多网站都利用 redis 的这个特性来做技术统计05216052#555555052#ffffffjustify4325-1552017673558Lists05true052005#55555505#ffffffjustify1.53750-1552017673558Redis 中的 list 的底层实现不是数组而是链表,这就使得在头尾插入新元素的复杂度是常数级别的,但定位元素的时候如果 list 的大小比较大的话就会很耗时。lists 的常用操作包括LPUSH、RPUSH、LRANGE 等。我们可以用 LPUSH 在 lists 的左侧插入一个新元素,用 RPUSH 在 lists 的右侧插入一个新元素,用 LRANGE 命令从 lists 中指定一个范围来提取元素。简单来试一下:0212160212#5555550212#ffffffjustify9033-1552017673558{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"127.0.0.1:6379> lpush onelist 1\n(integer) 1\n127.0.0.1:6379> lpush onelist 2\n(integer) 2\n127.0.0.1:6379> rpush onelist 0\n(integer) 3\n127.0.0.1:6379> rpush onelist 5\n(integer) 4\n127.0.0.1:6379> lrange onelist 0 -1\n1) \"2\"\n2) \"1\"\n3) \"0\"\n4) \"5\"","inlineStyles":{"font-size":[{"from":0,"to":31,"value":13},{"from":32,"to":43,"value":13},{"from":44,"to":75,"value":13},{"from":76,"to":87,"value":13},{"from":88,"to":119,"value":13},{"from":120,"to":131,"value":13},{"from":132,"to":163,"value":13},{"from":164,"to":175,"value":13},{"from":176,"to":211,"value":13},{"from":212,"to":218,"value":13},{"from":219,"to":225,"value":13},{"from":226,"to":232,"value":13},{"from":233,"to":239,"value":13}],"color":[{"from":0,"to":31,"value":"#4d4d4c"},{"from":32,"to":33,"value":"#4d4d4c"},{"from":33,"to":40,"value":"#f5871f"},{"from":40,"to":43,"value":"#4d4d4c"},{"from":44,"to":75,"value":"#4d4d4c"},{"from":76,"to":77,"value":"#4d4d4c"},{"from":77,"to":84,"value":"#f5871f"},{"from":84,"to":87,"value":"#4d4d4c"},{"from":88,"to":119,"value":"#4d4d4c"},{"from":120,"to":121,"value":"#4d4d4c"},{"from":121,"to":128,"value":"#f5871f"},{"from":128,"to":131,"value":"#4d4d4c"},{"from":132,"to":163,"value":"#4d4d4c"},{"from":164,"to":165,"value":"#4d4d4c"},{"from":165,"to":172,"value":"#f5871f"},{"from":172,"to":175,"value":"#4d4d4c"},{"from":176,"to":211,"value":"#4d4d4c"},{"from":212,"to":215,"value":"#4d4d4c"},{"from":215,"to":218,"value":"#718c00"},{"from":219,"to":222,"value":"#4d4d4c"},{"from":222,"to":225,"value":"#718c00"},{"from":226,"to":229,"value":"#4d4d4c"},{"from":229,"to":232,"value":"#718c00"},{"from":233,"to":236,"value":"#4d4d4c"},{"from":236,"to":239,"value":"#718c00"}],"back-color":[{"from":0,"to":31,"value":"#f7f7f7"},{"from":32,"to":43,"value":"#f7f7f7"},{"from":44,"to":75,"value":"#f7f7f7"},{"from":76,"to":87,"value":"#f7f7f7"},{"from":88,"to":119,"value":"#f7f7f7"},{"from":120,"to":131,"value":"#f7f7f7"},{"from":132,"to":163,"value":"#f7f7f7"},{"from":164,"to":175,"value":"#f7f7f7"},{"from":176,"to":211,"value":"#f7f7f7"},{"from":212,"to":218,"value":"#f7f7f7"},{"from":219,"to":225,"value":"#f7f7f7"},{"from":226,"to":232,"value":"#f7f7f7"},{"from":233,"to":239,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[618]}
3047-1552017673558lists 的应用相当广泛,随便举几个例子:02216022#555555022#ffffffjustify1518-1552017673558我们可以利用 lists 来实现一个消息队列,而且可以确保先后顺序,不必像 MySQL 那样还需要通过 ORDER BY 来进行排序06616066#555555066#ffffffjustify1380-1552017673558利用 LRANGE 还可以很方便的实现分页的功能02416024#555555024#ffffffjustify7029-1552017673558在博客系统中,每片博文的评论也可以存入一个单独的 list 中03116031#555555031#ffffffjustify8070-1552017673558Sets04true042004#55555504#ffffffjustify1.55038-1552017673558Redis 中的集合是无序集合,基本的操作对应于集合的操作,比方说添加、删除、交并差集等等,例如:04916049#555555049#ffffffjustify3482-1552017673558{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"127.0.0.1:6379> sadd oneset 1\n(integer) 1\n127.0.0.1:6379> sadd oneset 2\n(integer) 1\n127.0.0.1:6379> smembers oneset\n1) \"1\"\n2) \"2\"\n127.0.0.1:6379> sismember oneset 1\n(integer) 1\n127.0.0.1:6379> sismember oneset 2\n(integer) 1\n127.0.0.1:6379> sismember oneset 3\n(integer) 0\n127.0.0.1:6379> sadd twoset 1\n(integer) 1\n127.0.0.1:6379> sadd twoset 3\n(integer) 1\n127.0.0.1:6379> sunion oneset twoset\n1) \"1\"\n2) \"2\"\n3) \"3\"","inlineStyles":{"font-size":[{"from":0,"to":29,"value":13},{"from":30,"to":41,"value":13},{"from":42,"to":71,"value":13},{"from":72,"to":83,"value":13},{"from":84,"to":115,"value":13},{"from":116,"to":122,"value":13},{"from":123,"to":129,"value":13},{"from":130,"to":164,"value":13},{"from":165,"to":176,"value":13},{"from":177,"to":211,"value":13},{"from":212,"to":223,"value":13},{"from":224,"to":258,"value":13},{"from":259,"to":270,"value":13},{"from":271,"to":300,"value":13},{"from":301,"to":312,"value":13},{"from":313,"to":342,"value":13},{"from":343,"to":354,"value":13},{"from":355,"to":391,"value":13},{"from":392,"to":398,"value":13},{"from":399,"to":405,"value":13},{"from":406,"to":412,"value":13}],"color":[{"from":0,"to":29,"value":"#4d4d4c"},{"from":30,"to":31,"value":"#4d4d4c"},{"from":31,"to":38,"value":"#f5871f"},{"from":38,"to":41,"value":"#4d4d4c"},{"from":42,"to":71,"value":"#4d4d4c"},{"from":72,"to":73,"value":"#4d4d4c"},{"from":73,"to":80,"value":"#f5871f"},{"from":80,"to":83,"value":"#4d4d4c"},{"from":84,"to":115,"value":"#4d4d4c"},{"from":116,"to":119,"value":"#4d4d4c"},{"from":119,"to":122,"value":"#718c00"},{"from":123,"to":126,"value":"#4d4d4c"},{"from":126,"to":129,"value":"#718c00"},{"from":130,"to":164,"value":"#4d4d4c"},{"from":165,"to":166,"value":"#4d4d4c"},{"from":166,"to":173,"value":"#f5871f"},{"from":173,"to":176,"value":"#4d4d4c"},{"from":177,"to":211,"value":"#4d4d4c"},{"from":212,"to":213,"value":"#4d4d4c"},{"from":213,"to":220,"value":"#f5871f"},{"from":220,"to":223,"value":"#4d4d4c"},{"from":224,"to":258,"value":"#4d4d4c"},{"from":259,"to":260,"value":"#4d4d4c"},{"from":260,"to":267,"value":"#f5871f"},{"from":267,"to":270,"value":"#4d4d4c"},{"from":271,"to":300,"value":"#4d4d4c"},{"from":301,"to":302,"value":"#4d4d4c"},{"from":302,"to":309,"value":"#f5871f"},{"from":309,"to":312,"value":"#4d4d4c"},{"from":313,"to":342,"value":"#4d4d4c"},{"from":343,"to":344,"value":"#4d4d4c"},{"from":344,"to":351,"value":"#f5871f"},{"from":351,"to":354,"value":"#4d4d4c"},{"from":355,"to":391,"value":"#4d4d4c"},{"from":392,"to":395,"value":"#4d4d4c"},{"from":395,"to":398,"value":"#718c00"},{"from":399,"to":402,"value":"#4d4d4c"},{"from":402,"to":405,"value":"#718c00"},{"from":406,"to":409,"value":"#4d4d4c"},{"from":409,"to":412,"value":"#718c00"}],"back-color":[{"from":0,"to":29,"value":"#f7f7f7"},{"from":30,"to":41,"value":"#f7f7f7"},{"from":42,"to":71,"value":"#f7f7f7"},{"from":72,"to":83,"value":"#f7f7f7"},{"from":84,"to":115,"value":"#f7f7f7"},{"from":116,"to":122,"value":"#f7f7f7"},{"from":123,"to":129,"value":"#f7f7f7"},{"from":130,"to":164,"value":"#f7f7f7"},{"from":165,"to":176,"value":"#f7f7f7"},{"from":177,"to":211,"value":"#f7f7f7"},{"from":212,"to":223,"value":"#f7f7f7"},{"from":224,"to":258,"value":"#f7f7f7"},{"from":259,"to":270,"value":"#f7f7f7"},{"from":271,"to":300,"value":"#f7f7f7"},{"from":301,"to":312,"value":"#f7f7f7"},{"from":313,"to":342,"value":"#f7f7f7"},{"from":343,"to":354,"value":"#f7f7f7"},{"from":355,"to":391,"value":"#f7f7f7"},{"from":392,"to":398,"value":"#f7f7f7"},{"from":399,"to":405,"value":"#f7f7f7"},{"from":406,"to":412,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[620]}
4460-1552017673558集合的常见应用场景也很多,比方说文章的标签;群聊中的成员等等。03116031#555555031#ffffffjustify7772-1552017673558Sorted Sets011true01120011#555555011#ffffffjustify1.55573-1552017673559顾名思义,就是把无序的集合弄有序了,每个元素会关联一个分数 score,也就是排序的依据。因为关于有序集合的相关操作都是以 z 开头的,所以通常我们把有序集合称为 zsets。还是来看看具体的例子:09916099#555555099#ffffffjustify1424-1552017673559{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"127.0.0.1:6379> zadd onezset 1 wdxtub.com\n(integer) 1\n127.0.0.1:6379> zadd onezset 2 wdxtub.com/about\n(integer) 1\n127.0.0.1:6379> zadd onezset 0 wdxtub.com/life\n(integer) 1\n127.0.0.1:6379> zrange onezset 0 -1\n1) \"wdxtub.com/life\"\n2) \"wdxtub.com\"\n3) \"wdxtub.com/about\"\n127.0.0.1:6379> zrange onezset 0 -1 withscores\n1) \"wdxtub.com/life\"\n2) \"0\"\n3) \"wdxtub.com\"\n4) \"1\"\n5) \"wdxtub.com/about\"\n6) \"2\"","inlineStyles":{"font-size":[{"from":0,"to":41,"value":13},{"from":42,"to":53,"value":13},{"from":54,"to":101,"value":13},{"from":102,"to":113,"value":13},{"from":114,"to":160,"value":13},{"from":161,"to":172,"value":13},{"from":173,"to":208,"value":13},{"from":209,"to":229,"value":13},{"from":230,"to":245,"value":13},{"from":246,"to":267,"value":13},{"from":268,"to":314,"value":13},{"from":315,"to":335,"value":13},{"from":336,"to":342,"value":13},{"from":343,"to":358,"value":13},{"from":359,"to":365,"value":13},{"from":366,"to":387,"value":13},{"from":388,"to":394,"value":13}],"color":[{"from":0,"to":41,"value":"#4d4d4c"},{"from":42,"to":43,"value":"#4d4d4c"},{"from":43,"to":50,"value":"#f5871f"},{"from":50,"to":53,"value":"#4d4d4c"},{"from":54,"to":101,"value":"#4d4d4c"},{"from":102,"to":103,"value":"#4d4d4c"},{"from":103,"to":110,"value":"#f5871f"},{"from":110,"to":113,"value":"#4d4d4c"},{"from":114,"to":160,"value":"#4d4d4c"},{"from":161,"to":162,"value":"#4d4d4c"},{"from":162,"to":169,"value":"#f5871f"},{"from":169,"to":172,"value":"#4d4d4c"},{"from":173,"to":208,"value":"#4d4d4c"},{"from":209,"to":212,"value":"#4d4d4c"},{"from":212,"to":229,"value":"#718c00"},{"from":230,"to":233,"value":"#4d4d4c"},{"from":233,"to":245,"value":"#718c00"},{"from":246,"to":249,"value":"#4d4d4c"},{"from":249,"to":267,"value":"#718c00"},{"from":268,"to":314,"value":"#4d4d4c"},{"from":315,"to":318,"value":"#4d4d4c"},{"from":318,"to":335,"value":"#718c00"},{"from":336,"to":339,"value":"#4d4d4c"},{"from":339,"to":342,"value":"#718c00"},{"from":343,"to":346,"value":"#4d4d4c"},{"from":346,"to":358,"value":"#718c00"},{"from":359,"to":362,"value":"#4d4d4c"},{"from":362,"to":365,"value":"#718c00"},{"from":366,"to":369,"value":"#4d4d4c"},{"from":369,"to":387,"value":"#718c00"},{"from":388,"to":391,"value":"#4d4d4c"},{"from":391,"to":394,"value":"#718c00"}],"back-color":[{"from":0,"to":41,"value":"#f7f7f7"},{"from":42,"to":53,"value":"#f7f7f7"},{"from":54,"to":101,"value":"#f7f7f7"},{"from":102,"to":113,"value":"#f7f7f7"},{"from":114,"to":160,"value":"#f7f7f7"},{"from":161,"to":172,"value":"#f7f7f7"},{"from":173,"to":208,"value":"#f7f7f7"},{"from":209,"to":229,"value":"#f7f7f7"},{"from":230,"to":245,"value":"#f7f7f7"},{"from":246,"to":267,"value":"#f7f7f7"},{"from":268,"to":314,"value":"#f7f7f7"},{"from":315,"to":335,"value":"#f7f7f7"},{"from":336,"to":342,"value":"#f7f7f7"},{"from":343,"to":358,"value":"#f7f7f7"},{"from":359,"to":365,"value":"#f7f7f7"},{"from":366,"to":387,"value":"#f7f7f7"},{"from":388,"to":394,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[621]}
7065-1552017673559Hashes06true062006#55555506#ffffffjustify1.59120-1552017673559哈希是 Redis 2.0 之后才增加支持的数据结构,简单来说就是一个字典,直接看具体例子就很好懂了:05116051#555555051#ffffffjustify8027-1552017673559{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"127.0.0.1:6379> HMSET user:dawang username wdxtub password wdxtub.com age 26\nOK\n127.0.0.1:6379> HGETALL user:dawang\n1) \"username\"\n2) \"wdxtub\"\n3) \"password\"\n4) \"wdxtub.com\"\n5) \"age\"\n6) \"26\"\n127.0.0.1:6379> HSET user:dawang age 36\n(integer) 0\n127.0.0.1:6379> HGETALL user:dawang\n1) \"username\"\n2) \"wdxtub\"\n3) \"password\"\n4) \"wdxtub.com\"\n5) \"age\"\n6) \"36\"","inlineStyles":{"font-size":[{"from":0,"to":76,"value":13},{"from":77,"to":79,"value":13},{"from":80,"to":115,"value":13},{"from":116,"to":129,"value":13},{"from":130,"to":141,"value":13},{"from":142,"to":155,"value":13},{"from":156,"to":171,"value":13},{"from":172,"to":180,"value":13},{"from":181,"to":188,"value":13},{"from":189,"to":228,"value":13},{"from":229,"to":240,"value":13},{"from":241,"to":276,"value":13},{"from":277,"to":290,"value":13},{"from":291,"to":302,"value":13},{"from":303,"to":316,"value":13},{"from":317,"to":332,"value":13},{"from":333,"to":341,"value":13},{"from":342,"to":349,"value":13}],"color":[{"from":0,"to":76,"value":"#4d4d4c"},{"from":77,"to":79,"value":"#4d4d4c"},{"from":80,"to":115,"value":"#4d4d4c"},{"from":116,"to":119,"value":"#4d4d4c"},{"from":119,"to":129,"value":"#718c00"},{"from":130,"to":133,"value":"#4d4d4c"},{"from":133,"to":141,"value":"#718c00"},{"from":142,"to":145,"value":"#4d4d4c"},{"from":145,"to":155,"value":"#718c00"},{"from":156,"to":159,"value":"#4d4d4c"},{"from":159,"to":171,"value":"#718c00"},{"from":172,"to":175,"value":"#4d4d4c"},{"from":175,"to":180,"value":"#718c00"},{"from":181,"to":184,"value":"#4d4d4c"},{"from":184,"to":188,"value":"#718c00"},{"from":189,"to":228,"value":"#4d4d4c"},{"from":229,"to":230,"value":"#4d4d4c"},{"from":230,"to":237,"value":"#f5871f"},{"from":237,"to":240,"value":"#4d4d4c"},{"from":241,"to":276,"value":"#4d4d4c"},{"from":277,"to":280,"value":"#4d4d4c"},{"from":280,"to":290,"value":"#718c00"},{"from":291,"to":294,"value":"#4d4d4c"},{"from":294,"to":302,"value":"#718c00"},{"from":303,"to":306,"value":"#4d4d4c"},{"from":306,"to":316,"value":"#718c00"},{"from":317,"to":320,"value":"#4d4d4c"},{"from":320,"to":332,"value":"#718c00"},{"from":333,"to":336,"value":"#4d4d4c"},{"from":336,"to":341,"value":"#718c00"},{"from":342,"to":345,"value":"#4d4d4c"},{"from":345,"to":349,"value":"#718c00"}],"back-color":[{"from":0,"to":76,"value":"#f7f7f7"},{"from":77,"to":79,"value":"#f7f7f7"},{"from":80,"to":115,"value":"#f7f7f7"},{"from":116,"to":129,"value":"#f7f7f7"},{"from":130,"to":141,"value":"#f7f7f7"},{"from":142,"to":155,"value":"#f7f7f7"},{"from":156,"to":171,"value":"#f7f7f7"},{"from":172,"to":180,"value":"#f7f7f7"},{"from":181,"to":188,"value":"#f7f7f7"},{"from":189,"to":228,"value":"#f7f7f7"},{"from":229,"to":240,"value":"#f7f7f7"},{"from":241,"to":276,"value":"#f7f7f7"},{"from":277,"to":290,"value":"#f7f7f7"},{"from":291,"to":302,"value":"#f7f7f7"},{"from":303,"to":316,"value":"#f7f7f7"},{"from":317,"to":332,"value":"#f7f7f7"},{"from":333,"to":341,"value":"#f7f7f7"},{"from":342,"to":349,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[621]}
9520-1552017673559HyperLogLog011true01120011#555555011#ffffffjustify1.58188-1552017673559Redis 2.8.9 版本中添加了这个新的结构,命名也很有趣,走 ABB 的套路,比如范冰冰高圆圆李思思就是这么个意思。这个结构是用来做基数统计的,基数统计是什么,来看两个例子:1) 数据集 {1, 3, 5, 7, 5, 7, 8}, 那么这个数据集的基数集为 {1, 3, 5 ,7, 8}, 基数(不重复元素)为 5。2) 一个网站有很多访客记录,因为每个人不一定只访问一次,如果我想知道独立访客的人数的话,就需要计算一个基数,这时候就可以用 HyperLogLog。好处在于即使数据量非常大,计算所需的空间是小而固定的。每个 HyperLogLog 的键只占用 12KB 的内存,但是可以计算 264 个不同的基数。具体怎么实现的我还没有看源码,但估计跟 bloomfilter 的思路是一样的。简单举个例子:030216302303183033041330430518305360160360#5555550360#ffffffjustify6910-1552017673559{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"127.0.0.1:6379> PFADD wdxtub life\n(integer) 1\n127.0.0.1:6379> PFADD wdxtub about\n(integer) 1\n127.0.0.1:6379> PFADD wdxtub progress\n(integer) 1\n127.0.0.1:6379> PFADD wdxtub life\n(integer) 0\n127.0.0.1:6379> PFCOUNT wdxtub\n(integer) 3","inlineStyles":{"font-size":[{"from":0,"to":33,"value":13},{"from":34,"to":45,"value":13},{"from":46,"to":80,"value":13},{"from":81,"to":92,"value":13},{"from":93,"to":130,"value":13},{"from":131,"to":142,"value":13},{"from":143,"to":176,"value":13},{"from":177,"to":188,"value":13},{"from":189,"to":219,"value":13},{"from":220,"to":231,"value":13}],"color":[{"from":0,"to":33,"value":"#4d4d4c"},{"from":34,"to":35,"value":"#4d4d4c"},{"from":35,"to":42,"value":"#f5871f"},{"from":42,"to":45,"value":"#4d4d4c"},{"from":46,"to":80,"value":"#4d4d4c"},{"from":81,"to":82,"value":"#4d4d4c"},{"from":82,"to":89,"value":"#f5871f"},{"from":89,"to":92,"value":"#4d4d4c"},{"from":93,"to":130,"value":"#4d4d4c"},{"from":131,"to":132,"value":"#4d4d4c"},{"from":132,"to":139,"value":"#f5871f"},{"from":139,"to":142,"value":"#4d4d4c"},{"from":143,"to":176,"value":"#4d4d4c"},{"from":177,"to":178,"value":"#4d4d4c"},{"from":178,"to":185,"value":"#f5871f"},{"from":185,"to":188,"value":"#4d4d4c"},{"from":189,"to":219,"value":"#4d4d4c"},{"from":220,"to":221,"value":"#4d4d4c"},{"from":221,"to":228,"value":"#f5871f"},{"from":228,"to":231,"value":"#4d4d4c"}],"back-color":[{"from":0,"to":33,"value":"#f7f7f7"},{"from":34,"to":45,"value":"#f7f7f7"},{"from":46,"to":80,"value":"#f7f7f7"},{"from":81,"to":92,"value":"#f7f7f7"},{"from":93,"to":130,"value":"#f7f7f7"},{"from":131,"to":142,"value":"#f7f7f7"},{"from":143,"to":176,"value":"#f7f7f7"},{"from":177,"to":188,"value":"#f7f7f7"},{"from":189,"to":219,"value":"#f7f7f7"},{"from":220,"to":231,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[617]}
2812-1552017673559因为内部设计的算法,会尽量避免出现碰撞,所以在例子中大概不会出现统计不准的情况,不过在数据量变大之后,统计数值就不再是准确值。06316063#555555063#ffffffjustify8026-1552017673559持久化03true032203#55555503#ffffffjustify1.53835-1552017673559虽然是内存数据库,一般来说为了保险起见,还是会有一些持久化的机制,Redis 采用了其中两种方式,一是 RDB(Redis DataBase),也就是存数据,另一种是 AOF(Append Only File),也就是存操作。当然,即使是 Redis 本身提供的,我们也可以选择用还是不用,如果两种都不用的化,Redis 就和 memcache 差不多了。0178160178#5555550178#ffffffjustify5070-1552017673559具体的命令也很简单,直接 SAVE 即可,会在安装目录中创建 dump.rdb 文件。恢复数据时,只需要将备份文件移动到 redis 安装目录并启动 redis 即可,具体目录在哪里可以通过 CONFIG GET dir 来查看,比方说在我的机器上:013161317131796169611013110125160125#555555013#ffffff1317#eeeeee1796#ffffff96110#eeeeee110125#ffffffjustify9494-1552017673559{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"127.0.0.1:6379> CONFIG GET dir\n1) \"dir\"\n2) \"/usr/local/var/db/redis\"","inlineStyles":{"font-size":[{"from":0,"to":30,"value":13},{"from":31,"to":39,"value":13},{"from":40,"to":68,"value":13}],"color":[{"from":0,"to":30,"value":"#4d4d4c"},{"from":31,"to":34,"value":"#4d4d4c"},{"from":34,"to":39,"value":"#718c00"},{"from":40,"to":43,"value":"#4d4d4c"},{"from":43,"to":68,"value":"#718c00"}],"back-color":[{"from":0,"to":30,"value":"#f7f7f7"},{"from":31,"to":39,"value":"#f7f7f7"},{"from":40,"to":68,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[619]}
9489-1552017673559如果用 BGSAVE 的话,就是在后台进行备份,不会阻塞进程。041641013103116031#55555504#ffffff410#eeeeee1031#ffffffjustify5641-1552017673559RDB03true032003#55555503#ffffffjustify1.53744-1552017673559本段内容来自 Linux大棚版redis入门教程0241607#555555724#0593d307#ffffff724http://roclinux.cn/?p=3196justify2074-1552017673559RDB 方式,是将 redis 某一时刻的数据持久化到磁盘中,是一种快照式的持久化方法。04416044#555555044#ffffffjustify3233-1552017673559Redis 在进行数据持久化的过程中,会先将数据写入到一个临时文件中,待持久化过程都结束了,才会用这个临时文件替换上次持久化好的文件。正是这种特性,让我们可以随时来进行备份,因为快照文件总是完整可用的。0101160101#5555550101#ffffffjustify1161-1552017673559对于 RDB 方式,redis 会单独创建(fork)一个子进程来进行持久化,而主进程是不会进行任何IO操作的,这样就确保了redis极高的性能。07316073#555555073#ffffffjustify8337-1552017673559如果需要进行大规模数据的恢复,且对于数据恢复的完整性不是非常敏感,那 RDB 方式要比 AOF 方式更加的高效。05616056#555555056#ffffffjustify1783-1552017673559虽然 RDB 有不少优点,但它的缺点也是不容忽视的。如果你对数据的完整性非常敏感,那么 RDB 方式就不太适合你,因为即使你每 5 分钟都持久化一次,当 redis 故障时,仍然会有近 5 分钟的数据丢失。所以,redis 还提供了另一种持久化方式,那就是 AOF。0133160133#5555550133#ffffffjustify5181-1552017673559AOF03true032003#55555503#ffffffjustify1.58292-1552017673559本段内容来自 Linux大棚版redis入门教程0241607#555555724#0593d307#ffffff724http://roclinux.cn/?p=3196justify3346-1552017673559AOF,英文是 Append Only File,即只允许追加不允许改写的文件。如前面介绍的,AOF 方式是将执行过的写指令记录下来,在数据恢复时按照从前到后的顺序再将指令都执行一遍,就这么简单。09816098#555555098#ffffffjustify4925-1552017673559我们通过配置 redis.conf 中的 appendonly yes 就可以打开 AOF 功能。如果有写操作(如SET等),redis 就会被追加到 AOF 文件的末尾。071671713172116213513358616086#55555507#ffffff717#eeeeee1721#ffffff2135#eeeeee3586#ffffffjustify6655-1552017673559默认的 AOF 持久化策略是每秒钟 fsync 一次(fsync 是指把缓存中的写指令记录到磁盘中),因为在这种情况下,redis 仍然可以保持很好的处理性能,即使 redis 故障,也只会丢失最近 1 秒钟的数据。0108160108#5555550108#ffffffjustify3222-1552017673559如果在追加日志时,恰好遇到磁盘空间满、inode 满或断电等情况导致日志写入不完整,也没有关系,redis 提供了 redis-check-aof 工具,可以用来进行日志修复。08816088#555555088#ffffffjustify9036-1552017673559因为采用了追加方式,如果不做任何处理的话,AOF 文件会变得越来越大,为此,redis 提供了 AOF 文件重写(rewrite)机制,即当 AOF 文件的大小超过所设定的阈值时,redis 就会启动 AOF 文件的内容压缩,只保留可以恢复数据的最小指令集。举个例子或许更形象,假如我们调用了 100 次INCR指令,在 AOF 文件中就要存储 100 条指令,但这明显是很低效的,完全可以把这 100 条指令合并成一条 SET 指令,这就是重写机制的原理。0229160229#5555550229#ffffffjustify4020-1552017673559在进行 AOF 重写时,仍然是采用先写临时文件,全部完成后再替换的流程,所以断电、磁盘满等问题都不会影响 AOF 文件的可用性,这点大家可以放心。07316073#555555073#ffffffjustify9188-1552017673559AOF方式的另一个好处,我们通过一个“场景再现”来说明。某同学在操作 redis 时,不小心执行了 FLUSHALL,导致 redis 内存中的数据全部被清空了,这是很悲剧的事情。不过这也不是世界末日,只要 redis 配置了 AOF 持久化方式,且 AOF 文件还没有被重写(rewrite),我们就可以用最快的速度暂停 redis 并编辑 AOF 文件,将最后一行的 FLUSHALL 命令删除,然后重启 redis,就可以恢复 redis 的所有数据到 FLUSHALL 之前的状态了。是不是很神奇,这就是 AOF 持久化方式的好处之一。但是如果 AOF 文件已经被重写了,那就无法通过这种方法来恢复数据了。0307160307#5555550307#ffffffjustify3974-1552017673559虽然优点多多,但 AOF 方式也同样存在缺陷,比如在同样数据规模的情况下,AOF 文件要比 RDB 文件的体积大。而且,AOF 方式的恢复速度也要慢于 RDB 方式。08316083#555555083#ffffffjustify1073-1552017673559如果你直接执行 BGREWRITEAOF 命令,那么 redis 会生成一个全新的 AOF 文件,其中便包括了可以恢复现有数据的最少的命令集。07116071#555555071#ffffffjustify5527-1552017673559如果运气比较差,AOF 文件出现了被写坏的情况,也不必过分担忧,redis 并不会贸然加载这个有问题的 AOF 文件,而是报错退出。这时可以通过以下步骤来修复出错的文件:08516085#555555085#ffffffjustify6629-1552017673559备份被写坏的 AOF 文件01316013#555555013#ffffffjustify2210-1552017673559运行 redis-check-aof –fix 进行修复031632313232816028#55555503#ffffff323#eeeeee2328#ffffffjustify8773-1552017673559用 diff -u 来看下两个文件的差异,确认问题点0216291392616026#55555502#ffffff29#eeeeee926#ffffffjustify2652-1552017673559重启 redis,加载修复后的 AOF 文件02216022#555555022#ffffffjustify3954-1552017673559AOF 重写的内部运行原理,我们有必要了解一下。在重写即将开始之际,redis 会创建(fork)一个“重写子进程”,这个子进程会首先读取现有的 AOF 文件,并将其包含的指令进行分析压缩并写入到一个临时文件中。0106160106#5555550106#ffffffjustify7120-1552017673559与此同时,主工作进程会将新接收到的写指令一边累积到内存缓冲区中,一边继续写入到原有的 AOF 文件中,这样做是保证原有的 AOF 文件的可用性,避免在重写过程中出现意外。08516085#555555085#ffffffjustify7584-1552017673559当“重写子进程”完成重写工作后,它会给父进程发一个信号,父进程收到信号后就会将内存中缓存的写指令追加到新 AOF 文件中。06116061#555555061#ffffffjustify5594-1552017673559当追加结束后,redis 就会用新 AOF 文件来代替旧 AOF 文件,之后再有新的写指令,就都会追加到新的 AOF 文件中了。06416064#555555064#ffffffjustify6333-1552017673559我们应该选择RDB还是AOF,官方的建议是两个同时使用。这样可以提供更可靠的持久化方案。04416044#555555044#ffffffjustify8231-1552017673559增强功能04true042204#55555504#ffffffjustify1.57174-1552017673559主从同步04true042004#55555504#ffffffjustify1.51070-1552017673559本段内容大部分来自 Linux大棚版redis入门教程02716010#5555551027#0593d3010#ffffff1027http://roclinux.cn/?p=3196justify9137-1552017673559像 MySQL 一样,redis 是支持主从同步的,而且也支持一主多从以及多级从结构。主从结构,一是为了纯粹的冗余备份,二是为了提升读性能,比如很消耗性能的 SORT 就可以由从服务器来承担。在具体的实践中,可能还需要考虑到具体的法律法规原因,单纯的主从结构没有办法应对多机房跨国可能带来的数据存储问题,这里需要特别注意一下0162160162#5555550162#ffffffjustify6255-1552017673559redis 的主从同步是异步进行的,这意味着主从同步不会影响主逻辑,也不会降低 redis 的处理性能。主从架构中,可以考虑关闭主服务器的数据持久化功能,只让从服务器进行持久化,这样可以提高主服务器的处理性能。0105160105#5555550105#ffffffjustify7097-1552017673559在主从架构中,从服务器通常被设置为只读模式,这样可以避免从服务器的数据被误修改。但是从服务器仍然可以接受 CONFIG 等指令,所以还是不应该将从服务器直接暴露到不安全的网络环境中。如果必须如此,那可以考虑给重要指令进行重命名,来避免命令被外人误执行。0126160126#5555550126#ffffffjustify3988-1552017673559具体的同步原理也值得了解一下:01516015#555555015#ffffffjustify4446-1552017673559从服务器会向主服务器发出 SYNC 指令,当主服务器接到此命令后,就会调用 BGSAVE 指令来创建一个子进程专门进行数据持久化工作,也就是将主服务器的数据写入 RDB 文件中。在数据持久化期间,主服务器将执行的写指令都缓存在内存中。0117160117#5555550117#ffffffjustify5026-1552017673559在 BGSAVE 指令执行完成后,主服务器会将持久化好的 RDB 文件发送给从服务器,从服务器接到此文件后会将其存储到磁盘上,然后再将其读取到内存中。这个动作完成后,主服务器会将这段时间缓存的写指令再以 redis 协议的格式发送给从服务器。0121160121#5555550121#ffffffjustify7375-1552017673559另外,要说的一点是,即使有多个从服务器同时发来 SYNC 指令,主服务器也只会执行一次BGSAVE,然后把持久化好的 RDB 文件发给多个下游。在 redis2.8 版本之前,如果从服务器与主服务器因某些原因断开连接的话,都会进行一次主从之间的全量的数据同步;而在 2.8 版本之后,redis 支持了效率更高的增量同步策略,这大大降低了连接断开的恢复成本。0179160179#5555550179#ffffffjustify8752-1552017673559主服务器会在内存中维护一个缓冲区,缓冲区中存储着将要发给从服务器的内容。从服务器在与主服务器出现网络瞬断之后,从服务器会尝试再次与主服务器连接,一旦连接成功,从服务器就会把“希望同步的主服务器ID”和“希望请求的数据的偏移位置(replication offset)”发送出去。主服务器接收到这样的同步请求后,首先会验证主服务器ID是否和自己的ID匹配,其次会检查“请求的偏移位置”是否存在于自己的缓冲区中,如果两者都满足的话,主服务器就会向从服务器发送增量内容。0232160232#5555550232#ffffffjustify2054-1552017673559事务处理04true042004#55555504#ffffffjustify1.52160-1552017673559本段内容大部分来自 Linux大棚版redis入门教程02716010#5555551027#0593d3010#ffffff1027http://roclinux.cn/?p=3196justify2790-1552017673559数据库原理中很重要的一个概念是『事务』,简单来说就是把一系列动作看做一个整体,如果其中一个出了问题,应该把状态恢复到执行该整体之前的状态。在 Redis 中,MULTI、EXEC、DISCARD、WATCH 这四个指令是事务处理的基础。0118160118#5555550118#ffffffjustify2462-1552017673559MULTI用来组装一个事务;01416014#555555014#ffffffjustify2010-1552017673559EXEC用来执行一个事务;01316013#555555013#ffffffjustify6038-1552017673559DISCARD用来取消一个事务;01616016#555555016#ffffffjustify4773-1552017673559WATCH用来监视一些key,一旦这些key在事务执行之前被改变,则取消事务的执行。04216042#555555042#ffffffjustify4851-1552017673559举个例子:051605#55555505#ffffffjustify9643-1552017673559{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"127.0.0.1:6379> set oneid 2\nOK\n127.0.0.1:6379> MULTI\nOK\n127.0.0.1:6379> INCR oneid\nQUEUED\n127.0.0.1:6379> INCR oneid\nQUEUED\n127.0.0.1:6379> INCR oneid\nQUEUED\n127.0.0.1:6379> PING\nQUEUED\n127.0.0.1:6379> EXEC\n1) (integer) 3\n2) (integer) 4\n3) (integer) 5\n4) PONG","inlineStyles":{"font-size":[{"from":0,"to":27,"value":13},{"from":28,"to":30,"value":13},{"from":31,"to":52,"value":13},{"from":53,"to":55,"value":13},{"from":56,"to":82,"value":13},{"from":83,"to":89,"value":13},{"from":90,"to":116,"value":13},{"from":117,"to":123,"value":13},{"from":124,"to":150,"value":13},{"from":151,"to":157,"value":13},{"from":158,"to":178,"value":13},{"from":179,"to":185,"value":13},{"from":186,"to":206,"value":13},{"from":207,"to":221,"value":13},{"from":222,"to":236,"value":13},{"from":237,"to":251,"value":13},{"from":252,"to":259,"value":13}],"color":[{"from":0,"to":16,"value":"#4d4d4c"},{"from":16,"to":19,"value":"#f5871f"},{"from":19,"to":27,"value":"#4d4d4c"},{"from":28,"to":30,"value":"#4d4d4c"},{"from":31,"to":52,"value":"#4d4d4c"},{"from":53,"to":55,"value":"#4d4d4c"},{"from":56,"to":82,"value":"#4d4d4c"},{"from":83,"to":89,"value":"#4d4d4c"},{"from":90,"to":116,"value":"#4d4d4c"},{"from":117,"to":123,"value":"#4d4d4c"},{"from":124,"to":150,"value":"#4d4d4c"},{"from":151,"to":157,"value":"#4d4d4c"},{"from":158,"to":178,"value":"#4d4d4c"},{"from":179,"to":185,"value":"#4d4d4c"},{"from":186,"to":206,"value":"#4d4d4c"},{"from":207,"to":211,"value":"#4d4d4c"},{"from":211,"to":218,"value":"#f5871f"},{"from":218,"to":221,"value":"#4d4d4c"},{"from":222,"to":226,"value":"#4d4d4c"},{"from":226,"to":233,"value":"#f5871f"},{"from":233,"to":236,"value":"#4d4d4c"},{"from":237,"to":241,"value":"#4d4d4c"},{"from":241,"to":248,"value":"#f5871f"},{"from":248,"to":251,"value":"#4d4d4c"},{"from":252,"to":259,"value":"#4d4d4c"}],"back-color":[{"from":0,"to":27,"value":"#f7f7f7"},{"from":28,"to":30,"value":"#f7f7f7"},{"from":31,"to":52,"value":"#f7f7f7"},{"from":53,"to":55,"value":"#f7f7f7"},{"from":56,"to":82,"value":"#f7f7f7"},{"from":83,"to":89,"value":"#f7f7f7"},{"from":90,"to":116,"value":"#f7f7f7"},{"from":117,"to":123,"value":"#f7f7f7"},{"from":124,"to":150,"value":"#f7f7f7"},{"from":151,"to":157,"value":"#f7f7f7"},{"from":158,"to":178,"value":"#f7f7f7"},{"from":179,"to":185,"value":"#f7f7f7"},{"from":186,"to":206,"value":"#f7f7f7"},{"from":207,"to":221,"value":"#f7f7f7"},{"from":222,"to":236,"value":"#f7f7f7"},{"from":237,"to":251,"value":"#f7f7f7"},{"from":252,"to":259,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[619]}
2394-1552017673559在上面的例子中,我们看到了 QUEUED 的字样,这表示我们在用 MULTI 组装事务时,每一个命令都会进入到内存队列中缓存起来,如果出现 QUEUED 则表示我们这个命令成功插入了缓存队列,在将来执行 EXEC 时,这些被 QUEUED 的命令都会被组装成一个事务来执行。0137160137#5555550137#ffffffjustify2476-1552017673559对于事务的执行来说,如果 redis 开启了 AOF 持久化的话,那么一旦事务被成功执行,事务中的命令就会通过 write 命令一次性写到磁盘中去,如果在向磁盘中写的过程中恰好出现断电、硬件故障等问题,那么就可能出现只有部分命令进行了 AOF 持久化,这时 AOF 文件就会出现不完整的情况,这时,我们可以使用 redis-check-aof 工具来修复这一问题,这个工具会将 AOF 文件中不完整的信息移除,确保 AOF 文件完整可用。0219160219#5555550219#ffffffjustify8149-1552017673559然后我们来说说 WATCH 这个指令,它可以帮我们实现类似于“乐观锁”的效果,即CAS(check and set)。WATCH本身的作用是“监视key是否被改动过”,而且支持同时监视多个key,只要还没真正触发事务,WATCH都会尽职尽责的监视,一旦发现某个key被修改了,在执行EXEC时就会返回nil,表示事务无法触发。例如:0166160166#5555550166#ffffffjustify2017-1552017673559{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"127.0.0.1:6379> set name wdxtub\nOK\n127.0.0.1:6379> watch name\nOK\n127.0.0.1:6379> set name wdxtub.com\nOK\n127.0.0.1:6379> multi\nOK\n127.0.0.1:6379> set name wdxtub.com/about\nQUEUED\n127.0.0.1:6379> get name\nQUEUED\n127.0.0.1:6379> exec\n(nil)","inlineStyles":{"font-size":[{"from":0,"to":31,"value":13},{"from":32,"to":34,"value":13},{"from":35,"to":61,"value":13},{"from":62,"to":64,"value":13},{"from":65,"to":100,"value":13},{"from":101,"to":103,"value":13},{"from":104,"to":125,"value":13},{"from":126,"to":128,"value":13},{"from":129,"to":170,"value":13},{"from":171,"to":177,"value":13},{"from":178,"to":202,"value":13},{"from":203,"to":209,"value":13},{"from":210,"to":230,"value":13},{"from":231,"to":236,"value":13}],"color":[{"from":0,"to":16,"value":"#4d4d4c"},{"from":16,"to":19,"value":"#f5871f"},{"from":19,"to":31,"value":"#4d4d4c"},{"from":32,"to":34,"value":"#4d4d4c"},{"from":35,"to":61,"value":"#4d4d4c"},{"from":62,"to":64,"value":"#4d4d4c"},{"from":65,"to":81,"value":"#4d4d4c"},{"from":81,"to":84,"value":"#f5871f"},{"from":84,"to":100,"value":"#4d4d4c"},{"from":101,"to":103,"value":"#4d4d4c"},{"from":104,"to":125,"value":"#4d4d4c"},{"from":126,"to":128,"value":"#4d4d4c"},{"from":129,"to":145,"value":"#4d4d4c"},{"from":145,"to":148,"value":"#f5871f"},{"from":148,"to":170,"value":"#4d4d4c"},{"from":171,"to":177,"value":"#4d4d4c"},{"from":178,"to":202,"value":"#4d4d4c"},{"from":203,"to":209,"value":"#4d4d4c"},{"from":210,"to":226,"value":"#4d4d4c"},{"from":226,"to":230,"value":"#f5871f"},{"from":231,"to":236,"value":"#4d4d4c"}],"back-color":[{"from":0,"to":31,"value":"#f7f7f7"},{"from":32,"to":34,"value":"#f7f7f7"},{"from":35,"to":61,"value":"#f7f7f7"},{"from":62,"to":64,"value":"#f7f7f7"},{"from":65,"to":100,"value":"#f7f7f7"},{"from":101,"to":103,"value":"#f7f7f7"},{"from":104,"to":125,"value":"#f7f7f7"},{"from":126,"to":128,"value":"#f7f7f7"},{"from":129,"to":170,"value":"#f7f7f7"},{"from":171,"to":177,"value":"#f7f7f7"},{"from":178,"to":202,"value":"#f7f7f7"},{"from":203,"to":209,"value":"#f7f7f7"},{"from":210,"to":230,"value":"#f7f7f7"},{"from":231,"to":236,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[621]}
4916-1552017673559因为 name 在 exec 之前被改变了,可以认为这个值是脏(dirty) 的,于是之后的操作很可能是危险且没有意义的,自然就不会执行了。07016070#555555070#ffffffjustify8014-1552017673559发布订阅04true042004#55555504#ffffffjustify1.51152-1552017673559Redis 的发布/订阅(pub/sub) 是一种消息通信模型,Redis 客户端可以订阅任意数量的频道,一旦某频道接收到消息时,订阅它的客户端便会收到消息。这里我们需要两个终端来完成这次实验,在终端 1 中做如下操作:0110160110#5555550110#ffffffjustify6076-1552017673559{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"127.0.0.1:6379> SUBSCRIBE wdxtubBlog\nReading messages... (press Ctrl-C to quit)\n1) \"subscribe\"\n2) \"wdxtubBlog\"\n3) (integer) 1","inlineStyles":{"font-size":[{"from":0,"to":36,"value":13},{"from":37,"to":79,"value":13},{"from":80,"to":94,"value":13},{"from":95,"to":110,"value":13},{"from":111,"to":125,"value":13}],"color":[{"from":0,"to":33,"value":"#4d4d4c"},{"from":33,"to":36,"value":"#f5871f"},{"from":37,"to":79,"value":"#4d4d4c"},{"from":80,"to":83,"value":"#4d4d4c"},{"from":83,"to":94,"value":"#718c00"},{"from":95,"to":98,"value":"#4d4d4c"},{"from":98,"to":110,"value":"#718c00"},{"from":111,"to":115,"value":"#4d4d4c"},{"from":115,"to":122,"value":"#f5871f"},{"from":122,"to":125,"value":"#4d4d4c"}],"back-color":[{"from":0,"to":36,"value":"#f7f7f7"},{"from":37,"to":79,"value":"#f7f7f7"},{"from":80,"to":94,"value":"#f7f7f7"},{"from":95,"to":110,"value":"#f7f7f7"},{"from":111,"to":125,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[621]}
4341-1552017673559然后在终端 2 中向该频道发送消息01716017#555555017#ffffffjustify9079-1552017673559{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"127.0.0.1:6379> PUBLISH wdxtubBlog \"new post updated!\"\n(integer) 1\n127.0.0.1:6379> PUBLISH wdxtubBlog \"visit wdxtub.com for more!\"\n(integer) 1","inlineStyles":{"font-size":[{"from":0,"to":54,"value":13},{"from":55,"to":66,"value":13},{"from":67,"to":130,"value":13},{"from":131,"to":142,"value":13}],"color":[{"from":0,"to":31,"value":"#4d4d4c"},{"from":31,"to":34,"value":"#f5871f"},{"from":34,"to":35,"value":"#4d4d4c"},{"from":35,"to":54,"value":"#718c00"},{"from":55,"to":56,"value":"#4d4d4c"},{"from":56,"to":63,"value":"#f5871f"},{"from":63,"to":66,"value":"#4d4d4c"},{"from":67,"to":98,"value":"#4d4d4c"},{"from":98,"to":101,"value":"#f5871f"},{"from":101,"to":102,"value":"#4d4d4c"},{"from":102,"to":130,"value":"#718c00"},{"from":131,"to":132,"value":"#4d4d4c"},{"from":132,"to":139,"value":"#f5871f"},{"from":139,"to":142,"value":"#4d4d4c"}],"back-color":[{"from":0,"to":54,"value":"#f7f7f7"},{"from":55,"to":66,"value":"#f7f7f7"},{"from":67,"to":130,"value":"#f7f7f7"},{"from":131,"to":142,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[619]}
7729-1552017673559然后我们在终端 1 中就可以看到对应的消息:02216022#555555022#ffffffjustify2842-1552017673559{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"127.0.0.1:6379> SUBSCRIBE wdxtubBlog\nReading messages... (press Ctrl-C to quit)\n1) \"subscribe\"\n2) \"wdxtubBlog\"\n3) (integer) 1\n1) \"message\"\n2) \"wdxtubBlog\"\n3) \"new post updated!\"\n1) \"message\"\n2) \"wdxtubBlog\"\n3) \"visit wdxtub.com for more!\"","inlineStyles":{"font-size":[{"from":0,"to":36,"value":13},{"from":37,"to":79,"value":13},{"from":80,"to":94,"value":13},{"from":95,"to":110,"value":13},{"from":111,"to":125,"value":13},{"from":126,"to":138,"value":13},{"from":139,"to":154,"value":13},{"from":155,"to":177,"value":13},{"from":178,"to":190,"value":13},{"from":191,"to":206,"value":13},{"from":207,"to":238,"value":13}],"color":[{"from":0,"to":33,"value":"#4d4d4c"},{"from":33,"to":36,"value":"#f5871f"},{"from":37,"to":79,"value":"#4d4d4c"},{"from":80,"to":83,"value":"#4d4d4c"},{"from":83,"to":94,"value":"#718c00"},{"from":95,"to":98,"value":"#4d4d4c"},{"from":98,"to":110,"value":"#718c00"},{"from":111,"to":115,"value":"#4d4d4c"},{"from":115,"to":122,"value":"#f5871f"},{"from":122,"to":125,"value":"#4d4d4c"},{"from":126,"to":129,"value":"#4d4d4c"},{"from":129,"to":138,"value":"#718c00"},{"from":139,"to":142,"value":"#4d4d4c"},{"from":142,"to":154,"value":"#718c00"},{"from":155,"to":158,"value":"#4d4d4c"},{"from":158,"to":177,"value":"#718c00"},{"from":178,"to":181,"value":"#4d4d4c"},{"from":181,"to":190,"value":"#718c00"},{"from":191,"to":194,"value":"#4d4d4c"},{"from":194,"to":206,"value":"#718c00"},{"from":207,"to":210,"value":"#4d4d4c"},{"from":210,"to":238,"value":"#718c00"}],"back-color":[{"from":0,"to":36,"value":"#f7f7f7"},{"from":37,"to":79,"value":"#f7f7f7"},{"from":80,"to":94,"value":"#f7f7f7"},{"from":95,"to":110,"value":"#f7f7f7"},{"from":111,"to":125,"value":"#f7f7f7"},{"from":126,"to":138,"value":"#f7f7f7"},{"from":139,"to":154,"value":"#f7f7f7"},{"from":155,"to":177,"value":"#f7f7f7"},{"from":178,"to":190,"value":"#f7f7f7"},{"from":191,"to":206,"value":"#f7f7f7"},{"from":207,"to":238,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[618]}
6736-1552017673559性能测试04true042004#55555504#ffffffjustify1.54479-1552017673559在配置好 Redis 后,我们可以通过自带的性能测试来查看 Redis 在这台服务器上的表现,据此决定是否应该进行配置和服务调整,例如:06816068#555555068#ffffffjustify5953-1552017673559{"cells":[{"textAlign":"left","verticalAlign":"middle","wrap":true,"backColor":"rgb(249, 249, 249)","value":"dawang:~ dawang$ redis-benchmark -n 100000\n====== PING_INLINE ======\n 100000 requests completed in 1.26 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n99.75% <= 1 milliseconds\n100.00% <= 1 milliseconds\n79302.14 requests per second\n====== PING_BULK ======\n 100000 requests completed in 1.27 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n99.81% <= 1 milliseconds\n100.00% <= 1 milliseconds\n78988.94 requests per second\n====== SET ======\n 100000 requests completed in 1.30 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n99.37% <= 1 milliseconds\n99.93% <= 2 milliseconds\n99.96% <= 3 milliseconds\n100.00% <= 3 milliseconds\n76687.12 requests per second\n====== GET ======\n 100000 requests completed in 1.28 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n99.71% <= 1 milliseconds\n100.00% <= 1 milliseconds\n78125.00 requests per second\n====== INCR ======\n 100000 requests completed in 1.26 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n99.68% <= 1 milliseconds\n100.00% <= 1 milliseconds\n79554.50 requests per second\n====== LPUSH ======\n 100000 requests completed in 1.25 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n99.64% <= 1 milliseconds\n99.99% <= 2 milliseconds\n100.00% <= 2 milliseconds\n80000.00 requests per second\n====== RPUSH ======\n 100000 requests completed in 1.27 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n99.51% <= 1 milliseconds\n99.96% <= 2 milliseconds\n99.99% <= 3 milliseconds\n100.00% <= 3 milliseconds\n78926.60 requests per second\n====== LPOP ======\n 100000 requests completed in 1.27 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n99.81% <= 1 milliseconds\n100.00% <= 1 milliseconds\n78926.60 requests per second\n====== RPOP ======\n 100000 requests completed in 1.27 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n99.59% <= 1 milliseconds\n100.00% <= 1 milliseconds\n78431.38 requests per second\n====== SADD ======\n 100000 requests completed in 1.25 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n99.87% <= 1 milliseconds\n100.00% <= 1 milliseconds\n80000.00 requests per second\n====== SPOP ======\n 100000 requests completed in 1.25 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n99.81% <= 1 milliseconds\n100.00% <= 1 milliseconds\n79744.82 requests per second\n====== LPUSH (needed to benchmark LRANGE) ======\n 100000 requests completed in 1.27 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n99.49% <= 1 milliseconds\n100.00% <= 1 milliseconds\n78492.93 requests per second\n====== LRANGE_100 (first 100 elements) ======\n 100000 requests completed in 5.58 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n0.96% <= 1 milliseconds\n96.58% <= 2 milliseconds\n99.50% <= 3 milliseconds\n99.79% <= 4 milliseconds\n99.89% <= 5 milliseconds\n99.93% <= 6 milliseconds\n99.95% <= 7 milliseconds\n99.97% <= 8 milliseconds\n99.97% <= 9 milliseconds\n99.98% <= 10 milliseconds\n99.98% <= 29 milliseconds\n99.99% <= 30 milliseconds\n100.00% <= 30 milliseconds\n17927.57 requests per second\n====== LRANGE_300 (first 300 elements) ======\n 100000 requests completed in 10.84 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n0.01% <= 1 milliseconds\n0.11% <= 2 milliseconds\n89.47% <= 3 milliseconds\n99.59% <= 4 milliseconds\n99.95% <= 5 milliseconds\n100.00% <= 5 milliseconds\n9222.54 requests per second\n====== LRANGE_500 (first 450 elements) ======\n 100000 requests completed in 15.23 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n0.01% <= 1 milliseconds\n0.07% <= 2 milliseconds\n1.48% <= 3 milliseconds\n78.19% <= 4 milliseconds\n98.97% <= 5 milliseconds\n99.76% <= 6 milliseconds\n99.89% <= 7 milliseconds\n99.93% <= 8 milliseconds\n99.96% <= 9 milliseconds\n99.97% <= 10 milliseconds\n99.98% <= 11 milliseconds\n99.99% <= 12 milliseconds\n100.00% <= 13 milliseconds\n100.00% <= 14 milliseconds\n100.00% <= 15 milliseconds\n100.00% <= 15 milliseconds\n6564.26 requests per second\n====== LRANGE_600 (first 600 elements) ======\n 100000 requests completed in 19.84 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n0.00% <= 1 milliseconds\n0.00% <= 2 milliseconds\n0.07% <= 3 milliseconds\n0.77% <= 4 milliseconds\n68.46% <= 5 milliseconds\n98.20% <= 6 milliseconds\n99.64% <= 7 milliseconds\n99.85% <= 8 milliseconds\n99.96% <= 9 milliseconds\n99.99% <= 10 milliseconds\n100.00% <= 10 milliseconds\n5039.31 requests per second\n====== MSET (10 keys) ======\n 100000 requests completed in 1.71 seconds\n 50 parallel clients\n 3 bytes payload\n keep alive: 1\n83.56% <= 1 milliseconds\n100.00% <= 2 milliseconds\n100.00% <= 2 milliseconds\n58343.06 requests per second","inlineStyles":{"font-size":[{"from":0,"to":42,"value":13},{"from":43,"to":68,"value":13},{"from":69,"to":112,"value":13},{"from":113,"to":134,"value":13},{"from":135,"to":152,"value":13},{"from":153,"to":168,"value":13},{"from":169,"to":193,"value":13},{"from":194,"to":219,"value":13},{"from":220,"to":248,"value":13},{"from":249,"to":272,"value":13},{"from":273,"to":316,"value":13},{"from":317,"to":338,"value":13},{"from":339,"to":356,"value":13},{"from":357,"to":372,"value":13},{"from":373,"to":397,"value":13},{"from":398,"to":423,"value":13},{"from":424,"to":452,"value":13},{"from":453,"to":470,"value":13},{"from":471,"to":514,"value":13},{"from":515,"to":536,"value":13},{"from":537,"to":554,"value":13},{"from":555,"to":570,"value":13},{"from":571,"to":595,"value":13},{"from":596,"to":620,"value":13},{"from":621,"to":645,"value":13},{"from":646,"to":671,"value":13},{"from":672,"to":700,"value":13},{"from":701,"to":718,"value":13},{"from":719,"to":762,"value":13},{"from":763,"to":784,"value":13},{"from":785,"to":802,"value":13},{"from":803,"to":818,"value":13},{"from":819,"to":843,"value":13},{"from":844,"to":869,"value":13},{"from":870,"to":898,"value":13},{"from":899,"to":917,"value":13},{"from":918,"to":961,"value":13},{"from":962,"to":983,"value":13},{"from":984,"to":1001,"value":13},{"from":1002,"to":1017,"value":13},{"from":1018,"to":1042,"value":13},{"from":1043,"to":1068,"value":13},{"from":1069,"to":1097,"value":13},{"from":1098,"to":1117,"value":13},{"from":1118,"to":1161,"value":13},{"from":1162,"to":1183,"value":13},{"from":1184,"to":1201,"value":13},{"from":1202,"to":1217,"value":13},{"from":1218,"to":1242,"value":13},{"from":1243,"to":1267,"value":13},{"from":1268,"to":1293,"value":13},{"from":1294,"to":1322,"value":13},{"from":1323,"to":1342,"value":13},{"from":1343,"to":1386,"value":13},{"from":1387,"to":1408,"value":13},{"from":1409,"to":1426,"value":13},{"from":1427,"to":1442,"value":13},{"from":1443,"to":1467,"value":13},{"from":1468,"to":1492,"value":13},{"from":1493,"to":1517,"value":13},{"from":1518,"to":1543,"value":13},{"from":1544,"to":1572,"value":13},{"from":1573,"to":1591,"value":13},{"from":1592,"to":1635,"value":13},{"from":1636,"to":1657,"value":13},{"from":1658,"to":1675,"value":13},{"from":1676,"to":1691,"value":13},{"from":1692,"to":1716,"value":13},{"from":1717,"to":1742,"value":13},{"from":1743,"to":1771,"value":13},{"from":1772,"to":1790,"value":13},{"from":1791,"to":1834,"value":13},{"from":1835,"to":1856,"value":13},{"from":1857,"to":1874,"value":13},{"from":1875,"to":1890,"value":13},{"from":1891,"to":1915,"value":13},{"from":1916,"to":1941,"value":13},{"from":1942,"to":1970,"value":13},{"from":1971,"to":1989,"value":13},{"from":1990,"to":2033,"value":13},{"from":2034,"to":2055,"value":13},{"from":2056,"to":2073,"value":13},{"from":2074,"to":2089,"value":13},{"from":2090,"to":2114,"value":13},{"from":2115,"to":2140,"value":13},{"from":2141,"to":2169,"value":13},{"from":2170,"to":2188,"value":13},{"from":2189,"to":2232,"value":13},{"from":2233,"to":2254,"value":13},{"from":2255,"to":2272,"value":13},{"from":2273,"to":2288,"value":13},{"from":2289,"to":2313,"value":13},{"from":2314,"to":2339,"value":13},{"from":2340,"to":2368,"value":13},{"from":2369,"to":2417,"value":13},{"from":2418,"to":2461,"value":13},{"from":2462,"to":2483,"value":13},{"from":2484,"to":2501,"value":13},{"from":2502,"to":2517,"value":13},{"from":2518,"to":2542,"value":13},{"from":2543,"to":2568,"value":13},{"from":2569,"to":2597,"value":13},{"from":2598,"to":2643,"value":13},{"from":2644,"to":2687,"value":13},{"from":2688,"to":2709,"value":13},{"from":2710,"to":2727,"value":13},{"from":2728,"to":2743,"value":13},{"from":2744,"to":2767,"value":13},{"from":2768,"to":2792,"value":13},{"from":2793,"to":2817,"value":13},{"from":2818,"to":2842,"value":13},{"from":2843,"to":2867,"value":13},{"from":2868,"to":2892,"value":13},{"from":2893,"to":2917,"value":13},{"from":2918,"to":2942,"value":13},{"from":2943,"to":2967,"value":13},{"from":2968,"to":2993,"value":13},{"from":2994,"to":3019,"value":13},{"from":3020,"to":3045,"value":13},{"from":3046,"to":3072,"value":13},{"from":3073,"to":3101,"value":13},{"from":3102,"to":3147,"value":13},{"from":3148,"to":3192,"value":13},{"from":3193,"to":3214,"value":13},{"from":3215,"to":3232,"value":13},{"from":3233,"to":3248,"value":13},{"from":3249,"to":3272,"value":13},{"from":3273,"to":3296,"value":13},{"from":3297,"to":3321,"value":13},{"from":3322,"to":3346,"value":13},{"from":3347,"to":3371,"value":13},{"from":3372,"to":3397,"value":13},{"from":3398,"to":3425,"value":13},{"from":3426,"to":3471,"value":13},{"from":3472,"to":3516,"value":13},{"from":3517,"to":3538,"value":13},{"from":3539,"to":3556,"value":13},{"from":3557,"to":3572,"value":13},{"from":3573,"to":3596,"value":13},{"from":3597,"to":3620,"value":13},{"from":3621,"to":3644,"value":13},{"from":3645,"to":3669,"value":13},{"from":3670,"to":3694,"value":13},{"from":3695,"to":3719,"value":13},{"from":3720,"to":3744,"value":13},{"from":3745,"to":3769,"value":13},{"from":3770,"to":3794,"value":13},{"from":3795,"to":3820,"value":13},{"from":3821,"to":3846,"value":13},{"from":3847,"to":3872,"value":13},{"from":3873,"to":3899,"value":13},{"from":3900,"to":3926,"value":13},{"from":3927,"to":3953,"value":13},{"from":3954,"to":3980,"value":13},{"from":3981,"to":4008,"value":13},{"from":4009,"to":4054,"value":13},{"from":4055,"to":4099,"value":13},{"from":4100,"to":4121,"value":13},{"from":4122,"to":4139,"value":13},{"from":4140,"to":4155,"value":13},{"from":4156,"to":4179,"value":13},{"from":4180,"to":4203,"value":13},{"from":4204,"to":4227,"value":13},{"from":4228,"to":4251,"value":13},{"from":4252,"to":4276,"value":13},{"from":4277,"to":4301,"value":13},{"from":4302,"to":4326,"value":13},{"from":4327,"to":4351,"value":13},{"from":4352,"to":4376,"value":13},{"from":4377,"to":4402,"value":13},{"from":4403,"to":4429,"value":13},{"from":4430,"to":4457,"value":13},{"from":4458,"to":4486,"value":13},{"from":4487,"to":4530,"value":13},{"from":4531,"to":4552,"value":13},{"from":4553,"to":4570,"value":13},{"from":4571,"to":4586,"value":13},{"from":4587,"to":4611,"value":13},{"from":4612,"to":4637,"value":13},{"from":4638,"to":4663,"value":13},{"from":4664,"to":4692,"value":13}],"color":[{"from":0,"to":42,"value":"#4d4d4c"},{"from":43,"to":68,"value":"#4d4d4c"},{"from":69,"to":97,"value":"#4d4d4c"},{"from":97,"to":99,"value":"#8959a8"},{"from":99,"to":112,"value":"#4d4d4c"},{"from":113,"to":134,"value":"#4d4d4c"},{"from":135,"to":152,"value":"#4d4d4c"},{"from":153,"to":168,"value":"#4d4d4c"},{"from":169,"to":193,"value":"#4d4d4c"},{"from":194,"to":219,"value":"#4d4d4c"},{"from":220,"to":248,"value":"#4d4d4c"},{"from":249,"to":272,"value":"#4d4d4c"},{"from":273,"to":301,"value":"#4d4d4c"},{"from":301,"to":303,"value":"#8959a8"},{"from":303,"to":316,"value":"#4d4d4c"},{"from":317,"to":338,"value":"#4d4d4c"},{"from":339,"to":356,"value":"#4d4d4c"},{"from":357,"to":372,"value":"#4d4d4c"},{"from":373,"to":397,"value":"#4d4d4c"},{"from":398,"to":423,"value":"#4d4d4c"},{"from":424,"to":452,"value":"#4d4d4c"},{"from":453,"to":470,"value":"#4d4d4c"},{"from":471,"to":499,"value":"#4d4d4c"},{"from":499,"to":501,"value":"#8959a8"},{"from":501,"to":514,"value":"#4d4d4c"},{"from":515,"to":536,"value":"#4d4d4c"},{"from":537,"to":554,"value":"#4d4d4c"},{"from":555,"to":570,"value":"#4d4d4c"},{"from":571,"to":595,"value":"#4d4d4c"},{"from":596,"to":620,"value":"#4d4d4c"},{"from":621,"to":645,"value":"#4d4d4c"},{"from":646,"to":671,"value":"#4d4d4c"},{"from":672,"to":700,"value":"#4d4d4c"},{"from":701,"to":718,"value":"#4d4d4c"},{"from":719,"to":747,"value":"#4d4d4c"},{"from":747,"to":749,"value":"#8959a8"},{"from":749,"to":762,"value":"#4d4d4c"},{"from":763,"to":784,"value":"#4d4d4c"},{"from":785,"to":802,"value":"#4d4d4c"},{"from":803,"to":818,"value":"#4d4d4c"},{"from":819,"to":843,"value":"#4d4d4c"},{"from":844,"to":869,"value":"#4d4d4c"},{"from":870,"to":898,"value":"#4d4d4c"},{"from":899,"to":917,"value":"#4d4d4c"},{"from":918,"to":946,"value":"#4d4d4c"},{"from":946,"to":948,"value":"#8959a8"},{"from":948,"to":961,"value":"#4d4d4c"},{"from":962,"to":983,"value":"#4d4d4c"},{"from":984,"to":1001,"value":"#4d4d4c"},{"from":1002,"to":1017,"value":"#4d4d4c"},{"from":1018,"to":1042,"value":"#4d4d4c"},{"from":1043,"to":1068,"value":"#4d4d4c"},{"from":1069,"to":1097,"value":"#4d4d4c"},{"from":1098,"to":1117,"value":"#4d4d4c"},{"from":1118,"to":1146,"value":"#4d4d4c"},{"from":1146,"to":1148,"value":"#8959a8"},{"from":1148,"to":1161,"value":"#4d4d4c"},{"from":1162,"to":1183,"value":"#4d4d4c"},{"from":1184,"to":1201,"value":"#4d4d4c"},{"from":1202,"to":1217,"value":"#4d4d4c"},{"from":1218,"to":1242,"value":"#4d4d4c"},{"from":1243,"to":1267,"value":"#4d4d4c"},{"from":1268,"to":1293,"value":"#4d4d4c"},{"from":1294,"to":1322,"value":"#4d4d4c"},{"from":1323,"to":1342,"value":"#4d4d4c"},{"from":1343,"to":1371,"value":"#4d4d4c"},{"from":1371,"to":1373,"value":"#8959a8"},{"from":1373,"to":1386,"value":"#4d4d4c"},{"from":1387,"to":1408,"value":"#4d4d4c"},{"from":1409,"to":1426,"value":"#4d4d4c"},{"from":1427,"to":1442,"value":"#4d4d4c"},{"from":1443,"to":1467,"value":"#4d4d4c"},{"from":1468,"to":1492,"value":"#4d4d4c"},{"from":1493,"to":1517,"value":"#4d4d4c"},{"from":1518,"to":1543,"value":"#4d4d4c"},{"from":1544,"to":1572,"value":"#4d4d4c"},{"from":1573,"to":1591,"value":"#4d4d4c"},{"from":1592,"to":1620,"value":"#4d4d4c"},{"from":1620,"to":1622,"value":"#8959a8"},{"from":1622,"to":1635,"value":"#4d4d4c"},{"from":1636,"to":1657,"value":"#4d4d4c"},{"from":1658,"to":1675,"value":"#4d4d4c"},{"from":1676,"to":1691,"value":"#4d4d4c"},{"from":1692,"to":1716,"value":"#4d4d4c"},{"from":1717,"to":1742,"value":"#4d4d4c"},{"from":1743,"to":1771,"value":"#4d4d4c"},{"from":1772,"to":1790,"value":"#4d4d4c"},{"from":1791,"to":1819,"value":"#4d4d4c"},{"from":1819,"to":1821,"value":"#8959a8"},{"from":1821,"to":1834,"value":"#4d4d4c"},{"from":1835,"to":1856,"value":"#4d4d4c"},{"from":1857,"to":1874,"value":"#4d4d4c"},{"from":1875,"to":1890,"value":"#4d4d4c"},{"from":1891,"to":1915,"value":"#4d4d4c"},{"from":1916,"to":1941,"value":"#4d4d4c"},{"from":1942,"to":1970,"value":"#4d4d4c"},{"from":1971,"to":1989,"value":"#4d4d4c"},{"from":1990,"to":2018,"value":"#4d4d4c"},{"from":2018,"to":2020,"value":"#8959a8"},{"from":2020,"to":2033,"value":"#4d4d4c"},{"from":2034,"to":2055,"value":"#4d4d4c"},{"from":2056,"to":2073,"value":"#4d4d4c"},{"from":2074,"to":2089,"value":"#4d4d4c"},{"from":2090,"to":2114,"value":"#4d4d4c"},{"from":2115,"to":2140,"value":"#4d4d4c"},{"from":2141,"to":2169,"value":"#4d4d4c"},{"from":2170,"to":2188,"value":"#4d4d4c"},{"from":2189,"to":2217,"value":"#4d4d4c"},{"from":2217,"to":2219,"value":"#8959a8"},{"from":2219,"to":2232,"value":"#4d4d4c"},{"from":2233,"to":2254,"value":"#4d4d4c"},{"from":2255,"to":2272,"value":"#4d4d4c"},{"from":2273,"to":2288,"value":"#4d4d4c"},{"from":2289,"to":2313,"value":"#4d4d4c"},{"from":2314,"to":2339,"value":"#4d4d4c"},{"from":2340,"to":2368,"value":"#4d4d4c"},{"from":2369,"to":2417,"value":"#4d4d4c"},{"from":2418,"to":2446,"value":"#4d4d4c"},{"from":2446,"to":2448,"value":"#8959a8"},{"from":2448,"to":2461,"value":"#4d4d4c"},{"from":2462,"to":2483,"value":"#4d4d4c"},{"from":2484,"to":2501,"value":"#4d4d4c"},{"from":2502,"to":2517,"value":"#4d4d4c"},{"from":2518,"to":2542,"value":"#4d4d4c"},{"from":2543,"to":2568,"value":"#4d4d4c"},{"from":2569,"to":2597,"value":"#4d4d4c"},{"from":2598,"to":2643,"value":"#4d4d4c"},{"from":2644,"to":2672,"value":"#4d4d4c"},{"from":2672,"to":2674,"value":"#8959a8"},{"from":2674,"to":2687,"value":"#4d4d4c"},{"from":2688,"to":2709,"value":"#4d4d4c"},{"from":2710,"to":2727,"value":"#4d4d4c"},{"from":2728,"to":2743,"value":"#4d4d4c"},{"from":2744,"to":2767,"value":"#4d4d4c"},{"from":2768,"to":2792,"value":"#4d4d4c"},{"from":2793,"to":2817,"value":"#4d4d4c"},{"from":2818,"to":2842,"value":"#4d4d4c"},{"from":2843,"to":2867,"value":"#4d4d4c"},{"from":2868,"to":2892,"value":"#4d4d4c"},{"from":2893,"to":2917,"value":"#4d4d4c"},{"from":2918,"to":2942,"value":"#4d4d4c"},{"from":2943,"to":2967,"value":"#4d4d4c"},{"from":2968,"to":2993,"value":"#4d4d4c"},{"from":2994,"to":3019,"value":"#4d4d4c"},{"from":3020,"to":3045,"value":"#4d4d4c"},{"from":3046,"to":3072,"value":"#4d4d4c"},{"from":3073,"to":3101,"value":"#4d4d4c"},{"from":3102,"to":3147,"value":"#4d4d4c"},{"from":3148,"to":3176,"value":"#4d4d4c"},{"from":3176,"to":3178,"value":"#8959a8"},{"from":3178,"to":3192,"value":"#4d4d4c"},{"from":3193,"to":3214,"value":"#4d4d4c"},{"from":3215,"to":3232,"value":"#4d4d4c"},{"from":3233,"to":3248,"value":"#4d4d4c"},{"from":3249,"to":3272,"value":"#4d4d4c"},{"from":3273,"to":3296,"value":"#4d4d4c"},{"from":3297,"to":3321,"value":"#4d4d4c"},{"from":3322,"to":3346,"value":"#4d4d4c"},{"from":3347,"to":3371,"value":"#4d4d4c"},{"from":3372,"to":3397,"value":"#4d4d4c"},{"from":3398,"to":3425,"value":"#4d4d4c"},{"from":3426,"to":3471,"value":"#4d4d4c"},{"from":3472,"to":3500,"value":"#4d4d4c"},{"from":3500,"to":3502,"value":"#8959a8"},{"from":3502,"to":3516,"value":"#4d4d4c"},{"from":3517,"to":3538,"value":"#4d4d4c"},{"from":3539,"to":3556,"value":"#4d4d4c"},{"from":3557,"to":3572,"value":"#4d4d4c"},{"from":3573,"to":3596,"value":"#4d4d4c"},{"from":3597,"to":3620,"value":"#4d4d4c"},{"from":3621,"to":3644,"value":"#4d4d4c"},{"from":3645,"to":3669,"value":"#4d4d4c"},{"from":3670,"to":3694,"value":"#4d4d4c"},{"from":3695,"to":3719,"value":"#4d4d4c"},{"from":3720,"to":3744,"value":"#4d4d4c"},{"from":3745,"to":3769,"value":"#4d4d4c"},{"from":3770,"to":3794,"value":"#4d4d4c"},{"from":3795,"to":3820,"value":"#4d4d4c"},{"from":3821,"to":3846,"value":"#4d4d4c"},{"from":3847,"to":3872,"value":"#4d4d4c"},{"from":3873,"to":3899,"value":"#4d4d4c"},{"from":3900,"to":3926,"value":"#4d4d4c"},{"from":3927,"to":3953,"value":"#4d4d4c"},{"from":3954,"to":3980,"value":"#4d4d4c"},{"from":3981,"to":4008,"value":"#4d4d4c"},{"from":4009,"to":4054,"value":"#4d4d4c"},{"from":4055,"to":4083,"value":"#4d4d4c"},{"from":4083,"to":4085,"value":"#8959a8"},{"from":4085,"to":4099,"value":"#4d4d4c"},{"from":4100,"to":4121,"value":"#4d4d4c"},{"from":4122,"to":4139,"value":"#4d4d4c"},{"from":4140,"to":4155,"value":"#4d4d4c"},{"from":4156,"to":4179,"value":"#4d4d4c"},{"from":4180,"to":4203,"value":"#4d4d4c"},{"from":4204,"to":4227,"value":"#4d4d4c"},{"from":4228,"to":4251,"value":"#4d4d4c"},{"from":4252,"to":4276,"value":"#4d4d4c"},{"from":4277,"to":4301,"value":"#4d4d4c"},{"from":4302,"to":4326,"value":"#4d4d4c"},{"from":4327,"to":4351,"value":"#4d4d4c"},{"from":4352,"to":4376,"value":"#4d4d4c"},{"from":4377,"to":4402,"value":"#4d4d4c"},{"from":4403,"to":4429,"value":"#4d4d4c"},{"from":4430,"to":4457,"value":"#4d4d4c"},{"from":4458,"to":4486,"value":"#4d4d4c"},{"from":4487,"to":4515,"value":"#4d4d4c"},{"from":4515,"to":4517,"value":"#8959a8"},{"from":4517,"to":4530,"value":"#4d4d4c"},{"from":4531,"to":4552,"value":"#4d4d4c"},{"from":4553,"to":4570,"value":"#4d4d4c"},{"from":4571,"to":4586,"value":"#4d4d4c"},{"from":4587,"to":4611,"value":"#4d4d4c"},{"from":4612,"to":4637,"value":"#4d4d4c"},{"from":4638,"to":4663,"value":"#4d4d4c"},{"from":4664,"to":4692,"value":"#4d4d4c"}],"back-color":[{"from":0,"to":42,"value":"#f7f7f7"},{"from":43,"to":68,"value":"#f7f7f7"},{"from":69,"to":112,"value":"#f7f7f7"},{"from":113,"to":134,"value":"#f7f7f7"},{"from":135,"to":152,"value":"#f7f7f7"},{"from":153,"to":168,"value":"#f7f7f7"},{"from":169,"to":193,"value":"#f7f7f7"},{"from":194,"to":219,"value":"#f7f7f7"},{"from":220,"to":248,"value":"#f7f7f7"},{"from":249,"to":272,"value":"#f7f7f7"},{"from":273,"to":316,"value":"#f7f7f7"},{"from":317,"to":338,"value":"#f7f7f7"},{"from":339,"to":356,"value":"#f7f7f7"},{"from":357,"to":372,"value":"#f7f7f7"},{"from":373,"to":397,"value":"#f7f7f7"},{"from":398,"to":423,"value":"#f7f7f7"},{"from":424,"to":452,"value":"#f7f7f7"},{"from":453,"to":470,"value":"#f7f7f7"},{"from":471,"to":514,"value":"#f7f7f7"},{"from":515,"to":536,"value":"#f7f7f7"},{"from":537,"to":554,"value":"#f7f7f7"},{"from":555,"to":570,"value":"#f7f7f7"},{"from":571,"to":595,"value":"#f7f7f7"},{"from":596,"to":620,"value":"#f7f7f7"},{"from":621,"to":645,"value":"#f7f7f7"},{"from":646,"to":671,"value":"#f7f7f7"},{"from":672,"to":700,"value":"#f7f7f7"},{"from":701,"to":718,"value":"#f7f7f7"},{"from":719,"to":762,"value":"#f7f7f7"},{"from":763,"to":784,"value":"#f7f7f7"},{"from":785,"to":802,"value":"#f7f7f7"},{"from":803,"to":818,"value":"#f7f7f7"},{"from":819,"to":843,"value":"#f7f7f7"},{"from":844,"to":869,"value":"#f7f7f7"},{"from":870,"to":898,"value":"#f7f7f7"},{"from":899,"to":917,"value":"#f7f7f7"},{"from":918,"to":961,"value":"#f7f7f7"},{"from":962,"to":983,"value":"#f7f7f7"},{"from":984,"to":1001,"value":"#f7f7f7"},{"from":1002,"to":1017,"value":"#f7f7f7"},{"from":1018,"to":1042,"value":"#f7f7f7"},{"from":1043,"to":1068,"value":"#f7f7f7"},{"from":1069,"to":1097,"value":"#f7f7f7"},{"from":1098,"to":1117,"value":"#f7f7f7"},{"from":1118,"to":1161,"value":"#f7f7f7"},{"from":1162,"to":1183,"value":"#f7f7f7"},{"from":1184,"to":1201,"value":"#f7f7f7"},{"from":1202,"to":1217,"value":"#f7f7f7"},{"from":1218,"to":1242,"value":"#f7f7f7"},{"from":1243,"to":1267,"value":"#f7f7f7"},{"from":1268,"to":1293,"value":"#f7f7f7"},{"from":1294,"to":1322,"value":"#f7f7f7"},{"from":1323,"to":1342,"value":"#f7f7f7"},{"from":1343,"to":1386,"value":"#f7f7f7"},{"from":1387,"to":1408,"value":"#f7f7f7"},{"from":1409,"to":1426,"value":"#f7f7f7"},{"from":1427,"to":1442,"value":"#f7f7f7"},{"from":1443,"to":1467,"value":"#f7f7f7"},{"from":1468,"to":1492,"value":"#f7f7f7"},{"from":1493,"to":1517,"value":"#f7f7f7"},{"from":1518,"to":1543,"value":"#f7f7f7"},{"from":1544,"to":1572,"value":"#f7f7f7"},{"from":1573,"to":1591,"value":"#f7f7f7"},{"from":1592,"to":1635,"value":"#f7f7f7"},{"from":1636,"to":1657,"value":"#f7f7f7"},{"from":1658,"to":1675,"value":"#f7f7f7"},{"from":1676,"to":1691,"value":"#f7f7f7"},{"from":1692,"to":1716,"value":"#f7f7f7"},{"from":1717,"to":1742,"value":"#f7f7f7"},{"from":1743,"to":1771,"value":"#f7f7f7"},{"from":1772,"to":1790,"value":"#f7f7f7"},{"from":1791,"to":1834,"value":"#f7f7f7"},{"from":1835,"to":1856,"value":"#f7f7f7"},{"from":1857,"to":1874,"value":"#f7f7f7"},{"from":1875,"to":1890,"value":"#f7f7f7"},{"from":1891,"to":1915,"value":"#f7f7f7"},{"from":1916,"to":1941,"value":"#f7f7f7"},{"from":1942,"to":1970,"value":"#f7f7f7"},{"from":1971,"to":1989,"value":"#f7f7f7"},{"from":1990,"to":2033,"value":"#f7f7f7"},{"from":2034,"to":2055,"value":"#f7f7f7"},{"from":2056,"to":2073,"value":"#f7f7f7"},{"from":2074,"to":2089,"value":"#f7f7f7"},{"from":2090,"to":2114,"value":"#f7f7f7"},{"from":2115,"to":2140,"value":"#f7f7f7"},{"from":2141,"to":2169,"value":"#f7f7f7"},{"from":2170,"to":2188,"value":"#f7f7f7"},{"from":2189,"to":2232,"value":"#f7f7f7"},{"from":2233,"to":2254,"value":"#f7f7f7"},{"from":2255,"to":2272,"value":"#f7f7f7"},{"from":2273,"to":2288,"value":"#f7f7f7"},{"from":2289,"to":2313,"value":"#f7f7f7"},{"from":2314,"to":2339,"value":"#f7f7f7"},{"from":2340,"to":2368,"value":"#f7f7f7"},{"from":2369,"to":2417,"value":"#f7f7f7"},{"from":2418,"to":2461,"value":"#f7f7f7"},{"from":2462,"to":2483,"value":"#f7f7f7"},{"from":2484,"to":2501,"value":"#f7f7f7"},{"from":2502,"to":2517,"value":"#f7f7f7"},{"from":2518,"to":2542,"value":"#f7f7f7"},{"from":2543,"to":2568,"value":"#f7f7f7"},{"from":2569,"to":2597,"value":"#f7f7f7"},{"from":2598,"to":2643,"value":"#f7f7f7"},{"from":2644,"to":2687,"value":"#f7f7f7"},{"from":2688,"to":2709,"value":"#f7f7f7"},{"from":2710,"to":2727,"value":"#f7f7f7"},{"from":2728,"to":2743,"value":"#f7f7f7"},{"from":2744,"to":2767,"value":"#f7f7f7"},{"from":2768,"to":2792,"value":"#f7f7f7"},{"from":2793,"to":2817,"value":"#f7f7f7"},{"from":2818,"to":2842,"value":"#f7f7f7"},{"from":2843,"to":2867,"value":"#f7f7f7"},{"from":2868,"to":2892,"value":"#f7f7f7"},{"from":2893,"to":2917,"value":"#f7f7f7"},{"from":2918,"to":2942,"value":"#f7f7f7"},{"from":2943,"to":2967,"value":"#f7f7f7"},{"from":2968,"to":2993,"value":"#f7f7f7"},{"from":2994,"to":3019,"value":"#f7f7f7"},{"from":3020,"to":3045,"value":"#f7f7f7"},{"from":3046,"to":3072,"value":"#f7f7f7"},{"from":3073,"to":3101,"value":"#f7f7f7"},{"from":3102,"to":3147,"value":"#f7f7f7"},{"from":3148,"to":3192,"value":"#f7f7f7"},{"from":3193,"to":3214,"value":"#f7f7f7"},{"from":3215,"to":3232,"value":"#f7f7f7"},{"from":3233,"to":3248,"value":"#f7f7f7"},{"from":3249,"to":3272,"value":"#f7f7f7"},{"from":3273,"to":3296,"value":"#f7f7f7"},{"from":3297,"to":3321,"value":"#f7f7f7"},{"from":3322,"to":3346,"value":"#f7f7f7"},{"from":3347,"to":3371,"value":"#f7f7f7"},{"from":3372,"to":3397,"value":"#f7f7f7"},{"from":3398,"to":3425,"value":"#f7f7f7"},{"from":3426,"to":3471,"value":"#f7f7f7"},{"from":3472,"to":3516,"value":"#f7f7f7"},{"from":3517,"to":3538,"value":"#f7f7f7"},{"from":3539,"to":3556,"value":"#f7f7f7"},{"from":3557,"to":3572,"value":"#f7f7f7"},{"from":3573,"to":3596,"value":"#f7f7f7"},{"from":3597,"to":3620,"value":"#f7f7f7"},{"from":3621,"to":3644,"value":"#f7f7f7"},{"from":3645,"to":3669,"value":"#f7f7f7"},{"from":3670,"to":3694,"value":"#f7f7f7"},{"from":3695,"to":3719,"value":"#f7f7f7"},{"from":3720,"to":3744,"value":"#f7f7f7"},{"from":3745,"to":3769,"value":"#f7f7f7"},{"from":3770,"to":3794,"value":"#f7f7f7"},{"from":3795,"to":3820,"value":"#f7f7f7"},{"from":3821,"to":3846,"value":"#f7f7f7"},{"from":3847,"to":3872,"value":"#f7f7f7"},{"from":3873,"to":3899,"value":"#f7f7f7"},{"from":3900,"to":3926,"value":"#f7f7f7"},{"from":3927,"to":3953,"value":"#f7f7f7"},{"from":3954,"to":3980,"value":"#f7f7f7"},{"from":3981,"to":4008,"value":"#f7f7f7"},{"from":4009,"to":4054,"value":"#f7f7f7"},{"from":4055,"to":4099,"value":"#f7f7f7"},{"from":4100,"to":4121,"value":"#f7f7f7"},{"from":4122,"to":4139,"value":"#f7f7f7"},{"from":4140,"to":4155,"value":"#f7f7f7"},{"from":4156,"to":4179,"value":"#f7f7f7"},{"from":4180,"to":4203,"value":"#f7f7f7"},{"from":4204,"to":4227,"value":"#f7f7f7"},{"from":4228,"to":4251,"value":"#f7f7f7"},{"from":4252,"to":4276,"value":"#f7f7f7"},{"from":4277,"to":4301,"value":"#f7f7f7"},{"from":4302,"to":4326,"value":"#f7f7f7"},{"from":4327,"to":4351,"value":"#f7f7f7"},{"from":4352,"to":4376,"value":"#f7f7f7"},{"from":4377,"to":4402,"value":"#f7f7f7"},{"from":4403,"to":4429,"value":"#f7f7f7"},{"from":4430,"to":4457,"value":"#f7f7f7"},{"from":4458,"to":4486,"value":"#f7f7f7"},{"from":4487,"to":4530,"value":"#f7f7f7"},{"from":4531,"to":4552,"value":"#f7f7f7"},{"from":4553,"to":4570,"value":"#f7f7f7"},{"from":4571,"to":4586,"value":"#f7f7f7"},{"from":4587,"to":4611,"value":"#f7f7f7"},{"from":4612,"to":4637,"value":"#f7f7f7"},{"from":4638,"to":4663,"value":"#f7f7f7"},{"from":4664,"to":4692,"value":"#f7f7f7"}]}}],"heights":[40],"widths":[617]}
3427-1552017673559测试内容还是不少的,可以根据这些数据来进行优化相关工作。02816028#555555028#ffffffjustify9011-1552017673559连接与管道05true052005#55555505#ffffffjustify1.58024-1552017673559Redis 通过监听一个 TCP 端口或者 Unix socket 的方式来接收来自客户端的连接,当一个连接建立后,Redis 内部会进行以下一些操作:07616076#555555076#ffffffjustify1456-1552017673559客户端 socket 会被设置为非阻塞模式,因为 Redis 在网络事件处理上采用的是非阻塞多路复用模型。05316053#555555053#ffffffjustify2098-1552017673559为这个 socket 设置 TCP_NODELAY 属性,禁用 Nagle 算法。Nagle 算法实际就是当需要发送的数据攒到一定程度时才真正进行发包,通过这种方式来减少 header 数据占比的问题。不过在高互动的环境下是不必要的,一般来说,在客户端/服务器模型中会禁用。更多信息可在参考链接中查看。0141614251325151160151#555555014#ffffff1425#eeeeee25151#ffffffjustify4455-1552017673559创建一个可读的文件事件用于监听这个客户端 socket 的数据发送03316033#555555033#ffffffjustify5078-1552017673559Redis 管道技术可以在服务端未响应时,客户端可以继续向服务端发送请求,并最终一次性读取所有服务端的响应。管道技术最显著的优势是提高了 redis 服务的性能。08116081#555555081#ffffffjustify8497-1552017673559分区02true022002#55555502#ffffffjustify1.54667-1552017673559本段内容主要来自 Redis 分区0171609#555555917#0593d309#ffffff917http://www.runoob.com/redis/redis-partitioning.htmljustify8029-1552017673559分区是分割数据到多个 Redis 实例的处理过程,因此每个实例只保存 key 的一个子集。分区的优势有很多,尤其是在大数据当道的今天,更需要利用合理的分区机制来完成更加复杂的工作。09016090#555555090#ffffffjustify7537-1552017673559通过利用多台计算机内存的和值,允许我们构造更大的数据库02716027#555555027#ffffffjustify7589-1552017673559通过多核和多台计算机,允许我们扩展计算能力02116021#555555021#ffffffjustify2181-1552017673559通过多台计算机和网络适配器,允许我们扩展网络带宽02416024#555555024#ffffffjustify5991-1552017673559分区实际上把数据进行了隔离,如果原本应该在同一分区的数据被放在了不同分区,或者原本没有太多关系的数据因为新的业务产生了关系,就会遇到一些问题:07116071#555555071#ffffffjustify9479-1552017673559涉及多个 key 的操作通常是不被支持的。举例来说,当两个 set 映射到不同的 redis 实例上时,你就不能对这两个 set 执行交集操作07116071#555555071#ffffffjustify7183-1552017673559涉及多个 key 的 redis 事务不能使用02316023#555555023#ffffffjustify8686-1552017673559当使用分区时,数据处理较为复杂,比如你需要处理多个 rdb/aof 文件,并且从多个实例和主机备份持久化文件05416054#555555054#ffffffjustify3094-1552017673559增加或删除容量也比较复杂。redis 集群大多数支持在运行时增加、删除节点的透明数据平衡的能力,但是类似于客户端分区、代理等其他系统则不支持这项特性。然而,一种叫做 presharding 的技术对此是有帮助的。0106160106#5555550106#ffffffjustify3866-1552017673559Redis 有两种类型分区。 假设有 4 个 Redis实例 R0,R1,R2,R3,和类似 user:1,user:2 这样的表示用户的多个 key,对既定的 key 有多种不同方式来选择这个 key 存放在哪个实例中。也就是说,有不同的系统来映射某个 key 到某个 Redis 服务。0145160145#5555550145#ffffffjustify9030-1552017673559范围分区04true041604#55555504#ffffffjustify8110-1552017673559最简单的分区方式是按范围分区,就是映射一定范围的对象到特定的 Redis 实例。比如,ID 从 0 到 10000 的用户会保存到实例 R0,ID 从 10001 到 20000 的用户会保存到 R1,以此类推。这种方式的不足之处是要有一个区间范围到实例的映射表,同时还需要各种对象的映射表,通常对 Redis 来说并非是好的方法。0166160166#5555550166#ffffffjustify2346-1552017673559哈希分区04true041604#55555504#ffffffjustify8714-1552017673559另外一种分区方法是 hash 分区。这对任何 key 都适用,也无需是 object_name: 这种形式,只需要确定统一的哈希函数,然后通过取模确定应该保存在哪个分区即可。03616364813488716087#555555036#ffffff3648#eeeeee4887#ffffffjustify6685-1552017673559实战应用04true042204#55555504#ffffffjustify1.59235-1552017673560最近需要自己设计系统架构,一个核心思路是利用已有机制降低设计复杂度,这样可以避免很多无谓的『坑』,尽量少自己去造轮子,而是用经过实践检验的工具。07216072#555555072#ffffffjustify4030-1552017673560而且一开始就要考虑得稍微长远一些,从扩展性到 key 设计都是,还要善待 redis 中的数据,不用了就自己清理,而不是过分依赖 redis 本身。简单的原则如下08116081#555555081#ffffffjustify3691-1552017673560由于Redis单线程(严格意义上不是单线程,但认为对request的处理是单线程的)的模型,对大数据结构的使用一定要慎重06016060#555555060#ffffffjustify3770-1552017673560每个实例的内存容量也应该有一定的限制,不然故障恢复的时候会很痛苦03216032#555555032#ffffffjustify5994-1552017673560集群的解决方案基本目前公认就是 codis 了,不过看目前的数据量,走单点和 1 个备份应该是行得通的,具体要看看压力测试的结果06416064#555555064#ffffffjustify7683-1552017673560业务中最重要的是 KV, SQL 和事务,不要为了所谓的『架构合理』增加太多理解难度04216042#555555042#ffffffjustify9234-1552017673560Key 过期机制08true082008#55555508#ffffffjustify1.53284-1552017673560现在项目中的每条记录都有一定的存活时间,原本的机制是在 MySQL 的每条记录中增加一个 status 字段,定时跑一个程序根据时间戳来进行检查。但是怎么想都感觉有点折腾,难道不能依赖数据库的已有机制吗?0102160102#5555550102#ffffffjustify4811-1552017673560能的!使用 Key 的过期机制,每个 Key 过期之后自动失效,就不用增加额外复杂度了。如果需要刷新,直接对该 key 执行 EXPIRE 操作,即可。06316636913697616076#555555063#ffffff6369#eeeeee6976#ffffffjustify7070-1552017673560即使如此,我们也需要善待数据,注意清理,尽量使用小对象,不能过分依赖这个机制解决所有问题。04516045#555555045#ffffffjustify7034-1552017673560Google 的应用010true01020010#555555010#ffffffjustify1.53072-1552017673560来自Codis作者黄东旭细说分布式Redis架构设计和踩过的那些坑们0341602#555555234#0593d302#ffffff234http://mp.weixin.qq.com/s?__biz=MzAwMDU1MTE1OQ==&mid=208733458&idx=1&sn=691bfde670fb2dd649685723f7358feajustify1210-1552017673560Google在他们的广告业务中遇到这个问题,既需要高性能,又需要分布式事务,还必须保证一致性:),Google在此之前是通过一个大规模的MySQL集群通过sharding苦苦支撑,这个架构的可运维/扩展性实在太差。这要是在一般公司,估计也就忍了,但是Google可不是一般公司,用原子钟搞定Spanner,然后再Spanner上构建了SQL查询层F1。我在第一次看到这个系统的时候,感觉简直惊艳,应该是第一个可以真正称为NewSQL的公开设计的系统。所以,BigTable(KV)+F1(SQL)+Spanner(高性能分布式事务支持),同时Spanner还有一个非常重要的特性是跨数据中心的复制和一致性保证(通过Paxos实现),多数据中心,刚好补全了整个Google的基础设施的数据库栈,使得Google对于几乎任何类型的业务系统开发都非常方便。我想,这就是未来的方向吧,一个可扩展的KV数据库(作为缓存和简单对象存储),一个高性能支持分布式事务和SQL查询接口的分布式关系型数据库,提供表支持。0450160450#5555550450#ffffffjustify7818-1552017673560总结02true022202#55555502#ffffffjustify1.54567-1552017673560相比于在学校必须手写自己的缓存,使用 Redis(或是 memcache)简直太爽了,工作一段时间了,越发觉得技术的门槛其实越来越低,如何打造高效团队,如何把架构设计得更加合理,才是真正体现差距的地方。0101160101#5555550101#ffffffjustify5094-1552017673560参考链接04true042204#55555504#ffffffjustify1.59523-1552017673560Redis 官方网站01016010#0593d3010http://redis.io/justify9311-1552017673560Redis 命令大全01016010#0593d3010http://redis.io/commandsjustify1453-1552017673560Linux大棚版redis入门教程01716017#0593d3017http://roclinux.cn/?p=3196justify8686-1552017673560Redis 教程081608#0593d308http://www.runoob.com/redis/redis-tutorial.htmljustify5550-1552017673560Redis 作者博客01016010#0593d3010http://antirez.com/latest/0justify7137-1552017673560Redis 作者 Github 主页01816018#0593d3018https://github.com/antirezjustify3974-1552017673560Nagle 算法081608#0593d308https://zh.wikipedia.org/wiki/%E7%B4%8D%E6%A0%BC%E7%AE%97%E6%B3%95justify6012-1552017673560Redis实战经验及使用场景01416014#0593d3014http://www.cnblogs.com/mrxigua/p/3357138.htmljustify6047-1552017673560看看社交软件如何实现查看附近的人01616016#0593d3016http://www.cnblogs.com/iforever/p/4061095.htmljustify4080-1552017673560Redis Commands: Geography Edition03316033#0593d3033https://matt.sh/redis-geojustify2779-1552017673560微信、陌陌 架构方案分析01216012#0593d3012http://www.wubiao.info/401justify9356-1552017673560LBS 初试061606#0593d306http://www.hslk.com.cn/%E6%8A%80%E6%9C%AF/lbs-%E5%88%9D%E8%AF%95.htmljustify3621-1552017673560Redis - EXPIRE01416014#0593d3014http://redisdoc.com/key/expire.htmljustify1962-1552017673560EXPIRE key seconds01816018#0593d3018http://www.redis.cn/commands/expire.htmljustify5195-1552017673560A Quick Guide to Redis 3.2’s Geo Support04016040#0593d3040https://www.compose.com/articles/a-quick-guide-to-redis-3-2s-geo-support/justify
用户评论