[Redis]Redis 概述及基本使用规范.
<p class="17" style="margin-left: 18pt; line-height: normal; text-indent: -18pt; mso-char-indent-count: 0.0000; mso-list: l23 level1 lfo2;"><span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 22.0000pt;"><span style="mso-list: ignore;"><span style="font-family: Calibri;"><span style="font-size: 22pt;">1 n<span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 22.0000pt; mso-spacerun: 'yes';"><span style="font-size: 22pt;"><span style="font-family: Calibri;">osql<span style="face: 宋体;"><span style="font-size: 22pt;">的简介 <h2 style="margin-bottom: 13pt; margin-top: 13pt; margin-left: 28.8pt; text-justify: inter-ideograph; line-height: 28pt; text-indent: -28.8pt; mso-list: l22 level2 lfo1;" align="justify"><span style="font-family: 宋体;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-ascii-font-family: 'Calibri Light'; mso-hansi-font-family: 'Calibri Light';"><span style="mso-list: ignore;"><span style="font-size: 16pt;">1.1?<span style="font-size: 16pt;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: 'Calibri Light'; mso-hansi-font-family: 'Calibri Light';">nosql<span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';"><span style="font-size: 16pt;">简介 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;">随着互联网<span style="font-size: 10.5pt;">Web2.0网站的兴起,传统的关系数据库在应付<span style="font-size: 10.5pt;"><span style="face: calibri;">Web2.0<span style="face: 宋体;">网站,特别是超大规模和高并发的<span style="face: calibri;">SNS<span style="face: 宋体;">类型的<span style="face: calibri;">Web2.0<span style="face: 宋体;"><span style="font-size: 10.5pt;">纯动态网站已经显得力不从心,暴露了很多难以克服的问题,如: <h3 style="margin-bottom: 13pt; margin-top: 13pt; margin-left: 36pt; text-justify: inter-ideograph; line-height: 28pt; text-indent: -36pt; mso-list: l22 level3 lfo1;" align="justify"><span style="font-family: 宋体;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="mso-list: ignore;"><span style="font-size: 16pt;">1.1.1?<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-size: 16pt;">对数据库高并发读写的需求 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;"> 网站要根据用户个性化信息来实时生成动态页面和提供动态信息,所以基本上无法使用动态页面静态化技术,因此数据库并发负载非常高,往往要达到每秒上万次读写请求。关系数据库应付上万次<span style="font-size: 10.5pt;">SQL查询还勉强顶得住,但是应付上千万次<span style="font-size: 10.5pt;"><span style="face: calibri;">SQL<span style="face: 宋体;">写数据请求,硬盘<span style="face: calibri;">IO<span style="face: 宋体;"><span style="font-size: 10.5pt;">就已经无法承受了。 <h3 style="margin-bottom: 13pt; margin-top: 13pt; margin-left: 36pt; text-justify: inter-ideograph; line-height: 28pt; text-indent: -36pt; mso-list: l22 level3 lfo1;" align="justify"><span style="font-family: 宋体;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="mso-list: ignore;"><span style="font-size: 16pt;">1.1.2?<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-size: 16pt;">对海量数据的高效率存储和访问的需求 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;"> 对于大型的<span style="font-size: 10.5pt;">SNS网站,每天用户产生海量的用户动态,以国外的<span style="font-size: 10.5pt;"><span style="face: calibri;">Friendfeed<span style="face: 宋体;">为例,一个月就达到了<span style="face: calibri;">2.5<span style="face: 宋体;">亿条用户动态,对于关系数据库来说,在一张<span style="face: calibri;">2.5<span style="face: 宋体;">亿条记录的表里面进行<span style="face: calibri;">SQL<span style="face: 宋体;"><span style="font-size: 10.5pt;">查询,效率是极其低下乃至不可忍受的。 <h3 style="margin-bottom: 13pt; margin-top: 13pt; margin-left: 36pt; text-justify: inter-ideograph; line-height: 28pt; text-indent: -36pt; mso-list: l22 level3 lfo1;" align="justify"><span style="font-family: 宋体;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="mso-list: ignore;"><span style="font-size: 16pt;">1.1.3?<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-size: 16pt;">对数据库的高可扩展性和高可用性的需求 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;"> 在基于<span style="font-size: 10.5pt;">Web的架构当中,数据库是最难进行横向扩展的,当一个应用系统的用户量和访问量与日俱增的时候,你的数据库却没有办法像<span style="font-size: 10.5pt;"><span style="face: calibri;">Web<span style="face: 宋体;">服务器和应用服务器那样简单的通过添加更多的硬件和服务节点来扩展性能和负载能力。对于很多需要提供<span style="face: calibri;">7*24<span style="face: 宋体;"><span style="font-size: 10.5pt;">小时不间断服务的网站来说,对数据库系统进行升级和扩展是非常痛苦的事情,往往需要停机维护和数据迁移,为什么数据库不能通过不断的添加服务器节点来实现扩展呢? <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;"> 在上面提到的<span style="font-size: 10.5pt;">“三高”的需求面前,关系数据库遇到了难以克服的障碍,而对于<span style="font-size: 10.5pt;"><span style="face: calibri;">Web2.0<span style="face: 宋体;"><span style="font-size: 10.5pt;">网站来说,关系数据库的很多主要特性却往往无用武之地,例如: <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;"> (<span style="font-size: 10.5pt;">1<span style="font-size: 10.5pt;">)数据库事务一致性需求 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;"> 很多<span style="font-size: 10.5pt;">Web<span style="font-size: 10.5pt;">实时系统并不要求严格的数据库事务,对读一致性的要求很低,有些场合对写一致性要求也不高。因此数据库事务管理成了数据库高负载下一个沉重的负担。 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;"> (<span style="font-size: 10.5pt;">2<span style="font-size: 10.5pt;">)数据库的写实时性和读实时性需求 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="face: 宋体;"><span style="font-size: 10.5pt;"> 对关系数据库来说,插入一条数据之后立刻查询,是肯定可以读出来这条数据的。并不要求这么高的实时性。 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;"> (<span style="font-size: 10.5pt;">3)对复杂的<span style="font-size: 10.5pt;"><span style="face: calibri;">SQL<span style="face: 宋体;"><span style="font-size: 10.5pt;">查询,特别是多表关联查询的需求 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;"> 任何大数据量的<span style="font-size: 10.5pt;">Web系统,都非常忌讳多个大表的关联查询,以及复杂的数据分析类型的复杂<span style="font-size: 10.5pt;"><span style="face: calibri;">SQL<span style="face: 宋体;">报表查询,特别是<span style="face: calibri;">SNS<span style="face: 宋体;">类型的网站,从需求以及产品设计角度,就避免了这种情况的产生。往往更多的只是单表的主键查询,以及单表的简单条件分页查询,<span style="face: calibri;">SQL<span style="face: 宋体;"><span style="font-size: 10.5pt;">的功能被极大的弱化了。 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';"><span style="font-family: Calibri;"><span style="font-size: 10.5pt;">?<a href="http://images2015.cnblogs.com/blog/799093/201608/799093-20160825230830726-1942580122.png"> <img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="wpsBF6D.tmp" src="https://www.52php.cn/res/2019/02-14/22/83c85e1ce8d09b931c7b923afabda928.png" alt="wpsBF6D.tmp" width="606" height="430" border="0"> <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;"> 因此,关系数据库在这些越来越多的应用场景下显得不那么合适了,为了解决这类问题的非关系数据库应运而生。<span style="font-size: 10.5pt;">NoSQL 是非关系型数据存储的广义定义。它打破了长久以来关系型数据库与<span style="font-size: 10.5pt;"><span style="face: calibri;">ACID<span style="face: 宋体;">理论大一统的局面。<span style="face: calibri;">NoSQL <span style="face: 宋体;"><span style="font-size: 10.5pt;">数据存储不需要固定的表结构(例如以键值对存储,它的结构不固定,每一个元组可以有不一样的字段,每个元组可以根据需要增加一些自己的键值对,这样就不会局限于固定的结构,可以减少一些时间和空间的开销),通常也不存在连接操作。 <h2 style="margin-bottom: 13pt; margin-top: 13pt; margin-left: 28.8pt; text-justify: inter-ideograph; line-height: 28pt; text-indent: -28.8pt; mso-list: l22 level2 lfo1;" align="justify"><span style="font-family: 宋体;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-ascii-font-family: 'Calibri Light'; mso-hansi-font-family: 'Calibri Light';"><span style="mso-list: ignore;"><span style="font-size: 16pt;">1.2?<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: 'Calibri Light'; mso-hansi-font-family: 'Calibri Light';"><span style="font-size: 16pt;">NoSQL<span style="font-size: 16pt;">无与伦比的特点 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="face: 宋体;"><span style="font-size: 10.5pt;"> 在大数据存取上具备关系型数据库无法比拟的性能优势,例如: <h3 style="margin-bottom: 13pt; margin-top: 13pt; margin-left: 36pt; text-justify: inter-ideograph; line-height: 28pt; text-indent: -36pt; mso-list: l22 level3 lfo1;" align="justify"><span style="font-family: 宋体;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="mso-list: ignore;"><span style="font-size: 16pt;">1.2.1?<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-size: 16pt;">易扩展 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;">NoSQL<span style="font-size: 10.5pt;">数据库种类繁多,但是一个共同的特点都是去掉关系数据库的关系型特性。数据之间无关系,这样就非常容易扩展。也无形之间,在架构的层面上带来了可扩展的能力。 <h3 style="margin-bottom: 13pt; margin-top: 13pt; margin-left: 36pt; text-justify: inter-ideograph; line-height: 28pt; text-indent: -36pt; mso-list: l22 level3 lfo1;" align="justify"><span style="font-family: 宋体;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="mso-list: ignore;"><span style="font-size: 16pt;">1.2.2?<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-size: 16pt;">大数据量,高性能 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;">NoSQL<span style="font-size: 10.5pt;">数据库都具有非常高的读写性能,尤其在大数据量下,同样表现优秀。这得益于它的无关系性,数据库的结构简单。 <h3 style="margin-bottom: 13pt; margin-top: 13pt; margin-left: 36pt; text-justify: inter-ideograph; line-height: 28pt; text-indent: -36pt; mso-list: l22 level3 lfo1;" align="justify"><span style="font-family: 宋体;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="mso-list: ignore;"><span style="font-size: 16pt;">1.2.3?<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-size: 16pt;">灵活的数据模型 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;">NoSQL无需事先为要存储的数据建立字段,随时可以存储自定义的数据格式。而在关系数据库里,增删字段是一件非常麻烦的事情。如果是非常大数据量的表,增加字段简直就是一个噩梦。这点在大数据量的<span style="font-size: 10.5pt;"><span style="face: calibri;">Web2.0<span style="face: 宋体;"><span style="font-size: 10.5pt;">时代尤其明显。 <h3 style="margin-bottom: 13pt; margin-top: 13pt; margin-left: 36pt; text-justify: inter-ideograph; line-height: 28pt; text-indent: -36pt; mso-list: l22 level3 lfo1;" align="justify"><span style="font-family: 宋体;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="mso-list: ignore;"><span style="font-size: 16pt;">1.2.4?<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-size: 16pt;">高可用 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 21pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;">NoSQL在不太影响性能的情况,就可以方便的实现高可用的架构。比如<span style="font-size: 10.5pt;"><span style="face: calibri;">Cassandra<span style="face: 宋体;">,<span style="face: calibri;">HBase<span style="face: 宋体;"><span style="font-size: 10.5pt;">模型,通过复制模型也能实现高可用。 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 21pt;" align="justify"><span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';"><span style="font-family: Calibri;"><span style="font-size: 10.5pt;">? <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;">综上所述,<span style="font-size: 10.5pt;">NoSQL的非关系特性使其成为了后<span style="font-size: 10.5pt;"><span style="face: calibri;">Web2.0<span style="face: 宋体;">时代的宠儿,助力大型<span style="face: calibri;">Web2.0<span style="face: 宋体;"><span style="font-size: 10.5pt;">网站的再次起飞,是一项全新的数据库革命性运动。 <h2 style="margin-bottom: 13pt; margin-top: 13pt; margin-left: 28.8pt; text-justify: inter-ideograph; line-height: 28pt; text-indent: -28.8pt; mso-list: l22 level2 lfo1;" align="justify"><span style="font-family: 宋体;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-ascii-font-family: 'Calibri Light'; mso-hansi-font-family: 'Calibri Light';"><span style="mso-list: ignore;"><span style="font-size: 16pt;">1.3?<span style="font-size: 16pt;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: 'Calibri Light'; mso-hansi-font-family: 'Calibri Light';">redis<span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';"><span style="font-size: 16pt;">简介 <p class="p" style="margin-bottom: 0pt; background: #ffffff; margin-top: 0pt; line-height: 15pt; text-indent: 21pt;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;">随着应用对高性能需求的增加,<span style="font-size: 10.5pt;">NoSQL逐渐在各大名企的系统架构中生根发芽。时至今日,涌现出的<span style="font-size: 10.5pt;"><span style="face: calibri;">NoSQL<span style="face: 宋体;">产品已经有很多种了,例如<span style="font-size: 10.5pt;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="color: #ff0000;"><span style="font-family: 宋体;">Membase、<span style="face: calibri;">MongoDB<span style="face: 宋体;">、<span style="face: calibri;">Apache Cassandra<span style="face: 宋体;">、<span style="face: calibri;">CouchDB<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="face: 宋体;">等。不过,在国内外互联网巨头例如<span style="color: #ff0000;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;">社交巨头新浪微博、传媒巨头Viacom及图片分享领域佼佼者<span style="face: calibri;">Pinterest<span style="font-family: 宋体;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;">等名企都不约而同地采用了<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;">Redis<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-size: 10.5pt;"><span style="font-family: 宋体;">作为其NoSQL数据库的选择,到底<span style="face: calibri;">Redis<span style="face: 宋体;"><span style="font-size: 10.5pt;">是何方神圣呢?能让如此多的名企为它而痴狂。 <p class="p" style="margin-bottom: 0pt; background: #ffffff; margin-top: 0pt; line-height: 15pt; text-indent: 0pt;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;"> 按照官方的说法,<span style="font-size: 10.5pt;">Redis是一个开源的,使用<span style="font-size: 10.5pt;"><span style="face: calibri;">C<span style="face: 宋体;">语言编写,面向“键<span style="face: calibri;">/<span style="face: 宋体;">值”(<span style="face: calibri;">Key/Value<span style="face: 宋体;">)对类型数据的分布式<span style="face: calibri;">NoSQL<span style="face: 宋体;">数据库系统,特点是<span style="font-size: 10.5pt;"><span style="font-family: 宋体;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;">高性能<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;">,<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;">持久存储<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;">,<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;">适应高并发的应用场景<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;">。因此,可以说Redis纯粹为应用而产生,它是一个高性能的<span style="face: calibri;">key-value<span style="face: 宋体;">数据库,并且还提供了多种语言的<span style="face: calibri;">API<span style="face: 宋体;">(包括我们的大<span style="face: calibri;">C#<span style="face: 宋体;">)。那么,也许我们会问:<span style="font-family: 宋体;"><span style="font-size: 10.5pt;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="color: #ff0000;">到底性能如何呢?以下是官方的bench-mark数据<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-size: 10.5pt;">: <p class="MsoNormal" style="background: #ffffa3; text-justify: inter-ideograph; margin: 0pt; line-height: 19.2pt; text-indent: 0pt;" align="justify"><span style="color: #333333;"><span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';"><span style="face: 宋体;"><span style="font-size: 10.5pt;"> 测试完成了<span style="font-size: 10.5pt;"><span class="16" style="mso-spacerun: 'yes';">50<span style="face: 宋体;">个并发<span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';"><span style="face: 宋体;">执行<span class="16" style="mso-spacerun: 'yes';">100000<span style="face: 宋体;">个请求<span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';"><span style="face: 宋体;"><span style="font-size: 10.5pt;">。 <p class="MsoNormal" style="background: #ffffa3; text-justify: inter-ideograph; margin: 0pt; line-height: 19.2pt; text-indent: 0pt;" align="justify"><span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';"><span style="color: #333333;"><span style="face: 宋体;"><span style="font-size: 10.5pt;"> 设置和获取的值是一个<span style="font-size: 10.5pt;">256<span style="face: 宋体;"><span style="font-size: 10.5pt;">字节字符串。 <p class="MsoNormal" style="background: #ffffa3; text-justify: inter-ideograph; margin: 0pt; line-height: 19.2pt; text-indent: 0pt;" align="justify"><span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';"><span style="color: #333333;"><span style="font-size: 10.5pt;">Linux box<span style="face: 宋体;">是运行<span style="face: 微软雅黑;">Linux 2.6,<span style="face: 宋体;">这是<span style="face: 微软雅黑;">X3320 Xeon 2.5 ghz<span style="face: 宋体;"><span style="font-size: 10.5pt;">。 <p class="MsoNormal" style="background: #ffffa3; text-justify: inter-ideograph; margin: 0pt; line-height: 19.2pt; text-indent: 0pt;" align="justify"><span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';"><span style="color: #333333;"><span style="face: 宋体;"><span style="font-size: 10.5pt;"> 文本执行使用<span style="font-size: 10.5pt;">loopback<span style="face: 宋体;">接口<span style="face: 微软雅黑;">(127.0.0.1)<span style="face: 宋体;"><span style="font-size: 10.5pt;">。 <p class="MsoNormal" style="background: #ffffa3; text-justify: inter-ideograph; margin: 0pt; line-height: 19.2pt; text-indent: 0pt;" align="justify"><span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';"><span style="color: #333333; font-family: 宋体;"><span style="font-size: 10.5pt;"> 结果<span style="font-size: 10.5pt;"><span style="color: #ff0000;"><span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';">:<span class="16" style="mso-spacerun: 'yes';"><span style="face: 宋体;">读的速度是110000<span style="face: 宋体;">次<span style="face: 微软雅黑;">/s,<span style="face: 宋体;">写的速度是<span style="face: 微软雅黑;">81000<span style="face: 宋体;">次<span style="face: 微软雅黑;">/s<span class="15" style="mso-spacerun: 'yes';">?<span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';"><span style="face: 宋体;"><span style="font-size: 10.5pt; color: #333333;">。(当然不同的服务器配置性能也有所不同)。 <p class="p" style="margin-bottom: 0pt; background: #ffffff; margin-top: 0pt; line-height: 15pt; text-indent: 0pt;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;"> 和<span style="font-size: 10.5pt;">Memcached类似,<span style="font-size: 10.5pt;"><span style="face: calibri;">Redis<span style="face: 宋体;">支持存储的<span style="face: calibri;">value<span style="face: 宋体;">类型相对更多,包括<span style="face: calibri;">string(<span style="face: 宋体;">字符串<span style="face: calibri;">)<span style="face: 宋体;">、<span style="face: calibri;">list(<span style="face: 宋体;">链表<span style="face: calibri;">)<span style="face: 宋体;">、<span style="face: calibri;">set(<span style="face: 宋体;">集合<span style="face: calibri;">)<span style="face: 宋体;">、<span style="face: calibri;">zset(sorted set --<span style="face: 宋体;">有序集合<span style="face: calibri;">)<span style="face: 宋体;">和<span style="face: calibri;">hash<span style="face: 宋体;">(哈希类型)。这些数据类型都支持<span style="face: calibri;">push/pop<span style="face: 宋体;">、<span style="face: calibri;">add/remove<span style="face: 宋体;">及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的。在此基础上,<span style="face: calibri;">Redis<span style="face: 宋体;">支持各种不同方式的排序。与<span style="face: calibri;">Memcached<span style="face: 宋体;">一样,为了保证效率,数据都是缓存在内存中。区别的是<span style="font-size: 10.5pt;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="color: #ff0000;"><span style="font-family: 宋体;">Redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在此基础上实现了<span style="face: calibri;">master-slave(<span style="face: 宋体;">主从<span style="face: calibri;">)<span style="face: 宋体;">同步<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="face: 宋体;"><span style="font-size: 10.5pt;">(数据可以从主服务器向任意数量的从服务器上同步,从服务器可以是关联其他从服务器的主服务器。)。 <p class="p" style="margin-bottom: 0pt; background: #ffffff; margin-top: 0pt; line-height: 15pt; text-indent: 18pt;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="face: 宋体;"><span style="font-size: 10.5pt;">因此,<span style="font-size: 10.5pt;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;">Redis的出现,很大程度补偿了<span style="face: calibri;">Memcached<span style="face: 宋体;">这类<span style="face: calibri;">key/value<span style="face: 宋体;">存储的不足,在部分场合可以对关系数据库起到很好的补充作用<span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="face: 宋体;"><span style="font-size: 10.5pt;">。 <h2 style="margin-bottom: 13pt; margin-top: 13pt; margin-left: 28.8pt; text-justify: inter-ideograph; line-height: 28pt; text-indent: -28.8pt; mso-list: l22 level2 lfo1;" align="justify"><span style="font-family: 宋体;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-ascii-font-family: 'Calibri Light'; mso-hansi-font-family: 'Calibri Light';"><span style="mso-list: ignore;"><span style="font-size: 16pt;">1.4?<span style="font-size: 16pt;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: 'Calibri Light'; mso-hansi-font-family: 'Calibri Light';">redis<span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';"><span style="font-size: 16pt;">是什么 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 21pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;">redis是一个开源的、使用<span style="font-size: 10.5pt;"><span style="face: calibri;">C<span style="face: 宋体;">语言编写的、支持网络交互的、可基于内存也可持久化的<span style="face: calibri;">Key-Value<span style="face: 宋体;"><span style="font-size: 10.5pt;">数据库。 <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 21pt;" align="justify"><span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';"><span style="font-family: Calibri;"><span style="font-size: 10.5pt;">? <p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><a href="http://images2015.cnblogs.com/blog/799093/201608/799093-20160825230832788-1929964806.jpg"> <img style="background-image: none; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px; border: 0px;" title="wpsBF6E.tmp" src="https://www.52php.cn/res/2019/02-14/22/a3a86c32e0a74b66e5a158497067f8af.jpg" alt="wpsBF6E.tmp" width="194" height="192" border="0"> <span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes';"><span style="font-family: Calibri;"><span style="font-size: 10.5pt;">?<p class="MsoNormal" style="text-justify: inter-ideograph; margin: 0pt; line-height: normal; text-indent: 0pt;" align="justify"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 1.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="font-family: 宋体;"><span style="font-size: 10.5pt;">redis的作者,<span style="font-size: 10.5pt;"><span style="face: calibri;">Salvatore Sanfilippo<span style="face: 宋体;">,来自意大利的西西里岛,现在居住在卡塔尼亚。目前供职于<span style="face: calibri;">Pivotal<span style="face: 宋体;">公司。他使用的网名是<span style="face: calibri;">antirez<span style="face: 宋体;">,如果你有兴趣,可以去他的博客逛逛,地址是<span style="face: calibri;">antirez.com<span style="face: 宋体;">,他的<span style="face: calibri;">github<span style="face: 宋体;">地址是<span style="face: calibri;">http://github.com/antirez<span style="face: 宋体;"><span style="font-size: 10.5pt;">。 <h1 style="margin-bottom: 16.5pt; margin-top: 17pt; margin-left: 21.6pt; text-justify: inter-ideograph; line-height: 53pt; text-indent: -21.6pt; mso-list: l22 level1 lfo1;" align="justify"> <span style="font-family: 宋体;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 22.0000pt; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;"><span style="mso-list: ignore;"><span style="font-size: 22pt;">2?<span style="font-size: 22pt;"><span style="mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 22.0000pt; mso-spacerun: 'yes'; mso-ascii-font-family: calibri; mso-hansi-font-family: calibri;">CentOS下<span style="mso-fareast-font-family: 宋体; mso-bidi-font-family: 'Times New Roman'; mso-font-kerning: 22.0000pt; mso-spacerun: 'yes';"><span style="font-size: 22pt;"><span style="face: 宋体;">安装<span style="font-family: Calibri;"><span style="font-size: 22pt;">redis
? ? ? ? ? ? ? ? ? ? ? ?
?
?
?
? ? ? ? ?
? ? ? ??
?? ? ? ? ? ? ? ? ??
? ? ?
?
? ?? ? ? ? ? ? ? ? ? ? ? ? ?
??
?? ? ? ? ? ? ? ??
?? ? ? ? ? ? ? ? ? ? ? ? ?
??
?? ? ? ? ? ? ? ? ? ?
?? ? ? ? ? ? ??
??
?
?
??
?? ? ? ? ? ?? ? ? ??
?
?
?
?
?
??? ?
?
? ??? ? ? ? ?? ? ?? ? ? ??? ? ? ? ?? ? ??
? ? ?
?? ? ? ??? ? ? ? ? ? ? ?
??
?
?
?
?
?
?
?
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |