文章列表

接口测试和功能测试的区别

作者:测试人生路

一、什么是功能测试 功能测试 就是对产品的各功能进行验证,根据功能测试用例,逐项测试,检查产品是否达到用户要求的功能。Functionaltesting(功能测试),也称为behavioral testing(行为测试)、黑盒测试或数据驱动测试 黑盒测试(Black-box Testing,又称为功能测试或数据驱动测试)是把测试对象看作一个黑盒子。利用黑盒测试法进行动态测试时,需要测试软件产品的功能,不需测试软件产品的内部结构和处理过程。 二、功能测试怎么做 功能测试如何进行的:编写测试用例,测试用例当中最主要的是测试步骤和预期结果;测试人员根据测试用例执行操作步骤,然后通过眼睛和思考判断实际结果与预期结果是否相等。如果相等,测试通过;如果不相等,测试失败。 三、什么是接口测试 接口测试是测试系统组件间接口的一种测试。接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互点。测试的重点是要检查数据的交换,传递和控制管理过程,以及系统间的相互逻辑依赖关系等。 四、接口测试怎么做 接口测试可以通过接口测试工具或者接口测试脚本来进行测试。 接口测试工具:apipost、jmeter、laodrunner等 使用apipost进行接口测试示例: ![1.png](/storage/thumbnails/_signature/3BSP4MPSBO2SAE3C7JLPHL7B4T.png) python脚本进行接口测试示例: ![2.png](/storage/thumbnails/_signature/C5A6GBGM9NVTS468IVM8AGJTC.png) 五、功能测试和接口测试的区别 功能测试和接口测试的区别在于,功能测试侧重点在于前端ui界面,数据展示,图形界面,业务逻辑操作等,接口测试侧重点在于,后端返回的数据是否正确,接口是否正常。 接口测试工具下载地址:www.apipost.cn

Redis主从同步与故障切换,有哪些坑?

作者:微信小助手

<p style="text-align: left;" data-mpa-powered-by="yiban.io"><span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: normal;">在服务上线后总有些不尽人意的时候,初次使用Redis集群部署<span style="font-size: 15px;color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: left;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);">Redis主从同步出现切换故障,也是常有发生,本篇文章主要分享Redis主从同步切换有哪些坑可以尽量避免!</span></span><span style="letter-spacing: 0.5px;font-size: 15px;color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: left;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);"></span></p> <p><span style="background-color: rgb(255, 255, 255);color: rgb(64, 64, 64);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.12px;text-align: left;caret-color: rgb(64, 64, 64);"><br></span></p> <section data-mpa-template="t" mpa-from-tpl="t" style="white-space: normal;"> <section data-mid="" mpa-from-tpl="t" style="display: flex;justify-content: flex-start;align-items: center;"> <section data-mid="" mpa-from-tpl="t" style="display: flex;justify-content: center;align-items: flex-end;"> <section data-mid="" mpa-from-tpl="t" style="width: 30px;height: 30px;background: rgb(255, 213, 93);border-width: 1px;border-style: solid;border-color: rgb(51, 51, 51);box-shadow: rgb(51, 51, 51) 3px 3px;display: flex;justify-content: center;align-items: center;"> <span data-mid="" style="font-size: 16px;font-family: PingFangSC-Semibold, &quot;PingFang SC&quot;;font-weight: bold;line-height: 22px;letter-spacing: 1px;-webkit-text-stroke: 1px rgb(51, 51, 51);">01</span> </section> <section data-mid="" mpa-from-tpl="t" style="margin-bottom: -3.1px;padding-left: 7px;border-bottom: 1px solid black;display: flex;justify-content: center;align-items: flex-end;flex-direction: column;"> <section data-mid="" mpa-from-tpl="t"> <p data-mid="" style="font-size: 16px;font-family: PingFangSC-Semibold, &quot;PingFang SC&quot;;font-weight: bold;line-height: 22px;">主从数据不一致</p> </section> </section> </section> </section> </section> <p><br></p> <p><span style="background-color: rgb(255, 255, 255);color: rgb(64, 64, 64);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: left;caret-color: rgb(64, 64, 64);font-size: 15px;letter-spacing: normal;">那为啥会出现这个坑呢?其实这是因为主从库间的命令复制是异步进行的。那在什么情况下,从库会滞后执行同步命令呢?</span></p> <ul class="list-paddingleft-2"> <li style="letter-spacing: normal;font-size: 15px;"> <section> <span style="caret-color: rgb(64, 64, 64);color: rgb(64, 64, 64);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: left;text-size-adjust: auto;background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: normal;">一方面,主从库间的网络可能会有传输延迟,所以从库不能及时地收到主库发送的命令,从库上执行同步命令的时间就会被延后。</span> </section></li> <li style="letter-spacing: normal;font-size: 15px;"> <section> <span style="caret-color: rgb(64, 64, 64);color: rgb(64, 64, 64);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: left;text-size-adjust: auto;background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: normal;">另一方面,即使从库及时收到了主库的命令,但是,也可能会因为正在处理其它复杂度高的命令(例如集合操作命令)而阻塞。</span> </section></li> </ul> <p><span style="caret-color: rgb(64, 64, 64);color: rgb(64, 64, 64);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: left;text-size-adjust: auto;background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: normal;">两种解决方法:</span></p> <ul class="list-paddingleft-2"> <li style="letter-spacing: normal;font-size: 15px;"> <section> <span style="caret-color: rgb(64, 64, 64);color: rgb(64, 64, 64);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: left;text-size-adjust: auto;background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: normal;">在硬件环境配置方面,我们要尽量保证主从库间的网络连接状况良好</span> </section></li> <li style="letter-spacing: normal;font-size: 15px;"> <section> <span style="caret-color: rgb(64, 64, 64);color: rgb(64, 64, 64);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: left;text-size-adjust: auto;background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: normal;">可以开发一个外部程序来监控主从库间的复制进度</span> </section> <section> <span style="caret-color: rgb(64, 64, 64);color: rgb(64, 64, 64);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: left;text-size-adjust: auto;background-color: rgb(255, 255, 255);font-size: 14px;letter-spacing: normal;"><br></span> </section></li> </ul> <p><span style="caret-color: rgb(64, 64, 64);color: rgb(64, 64, 64);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: left;text-size-adjust: auto;background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: normal;">因为 Redis 的 INFO replication 命令可以查看主库接收写命令的进度信息(master_repl_offset)和从库复制写命令的进度信息(slave_repl_offset),所以,我们就可以开发一个监控程序,先用 INFO replication 命令查到主、从库的进度,然后,我们用 master_repl_offset 减去 slave_repl_offset,这样就能得到从库和主库间的复制进度差值了</span><span style="caret-color: rgb(64, 64, 64);color: rgb(64, 64, 64);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: left;text-size-adjust: auto;background-color: rgb(255, 255, 255);letter-spacing: normal;font-size: 15px;"></span></p> <p style="text-align: center;margin-top: 10px;"><span style="caret-color: rgb(64, 64, 64);color: rgb(64, 64, 64);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.12px;text-align: left;text-size-adjust: auto;background-color: rgb(255, 255, 255);font-size: 14px;padding: 0px 0.5em;"><img data-backh="395" data-backw="578" data-ratio="0.6829758713136729" src="/upload/64daf8b7e0b5eafedbffdbfc044e7599.png" data-type="png" data-w="1492" style="width: 100%;height: auto;border-radius: 3px;box-shadow: rgb(210, 210, 210) 0em 0em 0.5em 0px;font-size: 17px;border-color: rgb(0, 0, 0);border-style: solid;border-width: 0px;box-sizing: border-box;"></span></p> <p><span style="caret-color: rgb(64, 64, 64);color: rgb(64, 64, 64);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.12px;text-align: left;text-size-adjust: auto;background-color: rgb(255, 255, 255);font-size: 14px;"><br></span></p> <section data-mpa-template="t" mpa-from-tpl="t"> <section style="display: flex;justify-content: flex-start;align-items: center;" data-mid="" mpa-from-tpl="t"> <section style="display: flex;justify-content: center;align-items: flex-end;" data-mid="" mpa-from-tpl="t"> <section style="width: 30px;height: 30px;background: rgb(255, 213, 93);border-width: 1px;border-style: solid;border-color: rgb(51, 51, 51);box-shadow: rgb(51, 51, 51) 3px 3px;display: flex;justify-content: center;align-items: center;" data-mid="" mpa-from-tpl="t"> <span style="font-size: 16px;font-family: PingFangSC-Semibold, &quot;PingFang SC&quot;;font-weight: bold;line-height: 22px;letter-spacing: 1px;-webkit-text-stroke: 1px rgb(51, 51, 51);" data-mid="">02</span> </section> <section style="padding-left: 7px;margin-bottom: -3.1px;border-bottom: 1px solid black;display: flex;justify-content: center;align-items: flex-end;flex-direction: column;" data-mid="" mpa-from-tpl="t"> <section data-mid="" mpa-from-tpl="t"> <p style="font-size: 16px;font-family: PingFangSC-Semibold, &quot;PingFang SC&quot;;font-weight: bold;line-height: 22px;" data-mid="">读取过期数据</p> </section> </section> </section> </section> </section> <p><br></p> <p style="text-align: left;"><span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: normal;">我们在使用 Redis 主从集群时,有时会读到过期数据。例如,数据 X 的过期时间是 202010240900,但是客户端在 202010240910 时,仍然可以从从库中读到数据 X。一个数据过期后,应该是被删除的,客户端不能再读取到该数据,但是,Redis 为什么还能在从库中读到过期的数据呢?这是由 Redis 的过期数据删除策略引起的。</span></p> <ul style="text-align: left;" class="list-paddingleft-2"> <li style="text-align: left;letter-spacing: normal;font-size: 15px;"> <section style="text-align: left;"> <span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: normal;">Redis 同时使用了两种策略来删除过期的数据,分别是惰性删除策略和定期删除策略。先说惰性删除策略。当一个数据的过期时间到了以后,并不会立即删除数据,而是等到再有请求来读写这个数据时,对数据进行检查,如果发现数据已经过期了,再删除这个数据。</span> <span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);letter-spacing: normal;font-size: 15px;"></span> </section></li> </ul> <blockquote style="text-align: left;"> <p style="text-align: left;"><span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.12px;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);">在访问时检查过期时间 (被动). 如果访问的是主库, 那么发现数据过期会删除, 且不返回给客户端. 但是从库的行为与版本有关: 3.2之前的不检查过期, 会返回数据, 3.2之后虽然不删除过期数据, 但是返回空值.</span></p> </blockquote> <p style="text-align: left;"><span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);letter-spacing: 0.5px;font-size: 15px;"><span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: normal;">定期删除策略是指,Redis 每隔一段时间(默认 100ms),就会随机选出一定数量的数据,检查它们是否过期,并把其中过期的数据删除,这样就可以及时释放一些内存。</span></span></p> <blockquote style="text-align: left;"> <p style="text-align: left;"><span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.12px;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);">主动. 定期删除策略每次删除的过期数据不多 (避免影响性能), 所以应用可能读到未来得及删除的数据.</span></p> </blockquote> <p style="text-align: left;"><span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: normal;">只要使用了 Redis 3.2 后的版本,就不会读到过期数据了吗?其实还是会的。这跟 Redis 用于设置过期时间的命令有关系,有些命令给数据设置的过期时间在从库上可能会被延后,导致应该过期的数据又在从库上被读取到了</span></p> <ul style="text-align: left;" class="list-paddingleft-2"> <li style="text-align: left;letter-spacing: normal;font-size: 15px;"> <section style="text-align: left;"> <span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: normal;">EXPIRE 和 PEXPIRE:它们给数据设置的是从命令执行时开始计算的存活时间;</span> </section></li> <li style="text-align: left;letter-spacing: normal;font-size: 15px;"> <section style="text-align: left;"> <span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: normal;">EXPIREAT 和 PEXPIREAT:它们会直接把数据的过期时间设置为具体的一个时间点。</span> <span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);letter-spacing: normal;font-size: 15px;"></span> </section></li> </ul> <section style="text-align: left;margin-top: 10px;"> <span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 14px;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);letter-spacing: 0.5px;"><img data-ratio="0.31032171581769435" src="/upload/73004d5b94201ccbe3c7f993f9b2fca.png" data-type="png" data-w="1492" style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.12px;text-align: center;white-space: normal;caret-color: rgb(64, 64, 64);box-shadow: rgb(210, 210, 210) 0em 0em 0.5em 0px;"></span> </section> <p style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);"><span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);letter-spacing: 0.5px;font-size: 15px;"><span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: normal;">为了避免这种情况,我给你的建议是,在业务应用中使用 EXPIREAT/PEXPIREAT 命令,把数据的过期时间设置为具体的时间点,避免读到过期数据。</span></span></p> <p style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);"><span style="color: rgb(64, 64, 64);font-family: -apple-system-font, system-ui, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 14px;letter-spacing: 0.12px;caret-color: rgb(64, 64, 64);background-color: rgb(255, 255, 255);"><br></span></p> <section data-mpa-template="t" mpa-from-tpl="t"> <section style="display: flex;justify-content: flex-start;align-items: center;" data-mid="" mpa-from-tpl="t"> <section style="display: flex;justify-content: center;align-items: flex-end;" data-mid="" mpa-from-tpl="t"> <section style="width: 30px;height: 30px;background: rgb(255, 213, 93);border-width: 1px;border-style: solid;border-color: rgb(51, 51, 51);box-shadow: rgb(51, 51, 51) 3px 3px;display: flex;justify-content: center;align-items: center;" data-mid="" mpa-from-tpl="t"> <span style="font-size: 16px;font-family: PingFangSC-Semibold, &quot;PingFang SC&quot;;font-weight: bold;line-height: 22px;letter-spacing: 1px;-webkit-text-stroke: 1px rgb(51, 51, 51);" data-mid="">03</span> </section> <section style="padding-left: 7px;margin-bottom: -3.1px;border-bottom: 1px solid black;display: flex;justify-content: center;align-items: flex-end;flex-direction: column;" data-mid="" mpa-from-tpl="t"> <section data-mid="" mpa-from-tpl="t"> <p style="font-size: 16px;font-family: PingFangSC-Semibold, &quot;PingFang SC&quot;;font-weight: bold;line-height: 22px;" data-mid="">不合理的配置导致服务挂掉</p> </section> </section> </section> </section> </section> <p style="margin-bottom: 5px;padding-top: 8px;padding-bottom: 8px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;font-size: 14px;text-align: left;white-space: normal;line-height: 26px;margin-top: 15px;"><span style="letter-spacing: 0.5px;font-size: 15px;">这里涉及到的配置项有两个,分别是 protected-mode 和 cluster-node-timeout。</span></p> <section style="margin-top: 15px;"> <section style="display: flex;justify-content: flex-start;align-items: center;" data-mid="" mpa-from-tpl="t"> <section style="display: flex;justify-content: center;align-items: flex-end;" data-mid="" mpa-from-tpl="t"> <section style="padding-left: 7px;margin-bottom: -3.1px;border-bottom: 1px solid black;display: flex;justify-content: center;align-items: flex-end;flex-direction: column;" data-mid="" mpa-from-tpl="t"> <section data-mid="" mpa-from-tpl="t"> <p style="font-size: 16px;font-family: PingFangSC-Semibold, &quot;PingFang SC&quot;;font-weight: bold;line-height: 22px;" data-mid="">Protected-mode 配置项</p> </section> </section> </section> </section> </section> <section style="font-size: 14px;padding-top: 8px;padding-bottom: 8px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);margin-top: 10px;margin-bottom: 5px;"> <span style="letter-spacing: 0.5px;font-size: 15px;"><span style="font-size: 15px;letter-spacing: normal;">这个配置项的作用是限定哨兵实例能否被其他服务器访问。当这个配置项设置为 yes 时,哨兵实例只能在部署的服务器本地进行访问。当设置为 no 时,其他服务器也可以访问这个哨兵实例。正因为这样,如果 protected-mode 被设置为 yes,而其余哨兵实例部署在其它服务器,那么,这些哨兵实例间就无法通信。当主库故障时,哨兵无法判断主库下线,也无法进行主从切换,最终 Redis 服务不可用。所以,我们在应用主从集群时,要注意将 protected-mode 配置项设置为 no,并且将 bind 配置项设置为其它哨兵实例的 IP 地址。这样一来,只有在 bind 中设置了 IP 地址的哨兵,才可以访问当前实例,既保证了实例间能够通信进行主从切换,也保证了哨兵的安全性。配置示例:</span></span> </section> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="css"><code><span class="code-snippet_outer">protected-mode no</span></code><code><span class="code-snippet_outer">bind 192.168.10.3 192.168.10.4 192.168.10.5</span></code></pre> </section> <section data-mpa-template="t" mpa-from-tpl="t" style="white-space: normal;"> <section data-mid="" mpa-from-tpl="t" style="display: flex;justify-content: flex-start;align-items: center;"> <section data-mid="" mpa-from-tpl="t" style="display: flex;justify-content: center;align-items: flex-end;"> <section data-mid="" mpa-from-tpl="t" style="margin-bottom: -3.1px;padding-left: 7px;border-bottom: 1px solid black;display: flex;justify-content: center;align-items: flex-end;flex-direction: column;"> <section data-mid="" mpa-from-tpl="t"> <p data-mid="" style="font-size: 16px;font-family: PingFangSC-Semibold, &quot;PingFang SC&quot;;font-weight: bold;line-height: 22px;"><br>Cluster-node-timeout 配置项&nbsp;</p> </section> </section> </section> </section> </section> <section style="margin-top: 10px;margin-bottom: 5px;padding-top: 8px;padding-bottom: 8px;white-space: normal;font-size: 14px;line-height: 26px;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;text-align: left;background-color: rgb(255, 255, 255);"> <span style="letter-spacing: 0.5px;font-size: 15px;"><span style="font-size: 15px;letter-spacing: normal;">这个配置项的作用是限定哨兵实例能否被其他服务器访问。当这个配置项设置为 yes 时,哨兵实例只能在部署的</span></span> </section> <p style="padding-top: 8px;padding-bottom: 8px;white-space: normal;color: rgb(0, 0, 0);font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;font-size: 14px;text-align: left;line-height: 26px;margin-bottom: 15px;"><span style="letter-spacing: 0.5px;background-color: rgb(255, 255, 255);font-size: 15px;"><span style="background-color: rgb(255, 255, 255);font-size: 15px;letter-spacing: normal;">这个配置项设置了 Redis Cluster 中实例响应心跳消息的超时时间。当我们在 Redis Cluster 集群中为每个实例配置了“一主一从”模式时,如果主实例发生故障,从实例会切换为主实例,受网络延迟和切换操作执行的影响,切换时间可能较长,就会导致实例的心跳超时(超出 cluster-node-timeout)。实例超时后,就会被 Redis Cluster 判断为异常。而 Redis Cluster 正常运行的条件就是,有半数以上的实例都能正常运行。所以,如果执行主从切换的实例超过半数,而主从切换时间又过长的话,就可能有半数以上的实例心跳超时,从而可能导致整个集群挂掉。所以,我建议你将 cluster-node-timeout 调大些(例如 10 到 20 秒)</span></span></p> <section data-mpa-template="t" mpa-from-tpl="t" style="white-space: normal;"> <section data-mid="" mpa-from-tpl="t" style="display: flex;justify-content: flex-start;align-items: center;"> <section data-mid="" mpa-from-tpl="t" style="display: flex;justify-content: center;align-items: flex-end;"> <section data-mid="" mpa-from-tpl="t" style="width: 30px;height: 30px;background: rgb(255, 213, 93);border-width: 1px;border-style: solid;border-color: rgb(51, 51, 51);box-shadow: rgb(51, 51, 51) 3px 3px;display: flex;justify-content: center;align-items: center;"> <span data-mid="" style="font-size: 16px;font-family: PingFangSC-Semibold, &quot;PingFang SC&quot;;font-weight: bold;line-height: 22px;letter-spacing: 1px;-webkit-text-stroke: 1px rgb(51, 51, 51);">04</span> </section> <section data-mid="" mpa-from-tpl="t" style="margin-bottom: -3.1px;padding-left: 7px;border-bottom: 1px solid black;display: flex;justify-content: center;align-items: flex-end;flex-direction: column;"> <section data-mid="" mpa-from-tpl="t"> <p data-mid="" style="font-size: 16px;font-family: PingFangSC-Semibold, &quot;PingFang SC&quot;;font-weight: bold;line-height: 22px;">总结</p> </section> </section> </section> </section> </section> <p style="text-align: center;margin-top: 10px;"><img data-backh="239" data-backw="578" data-ratio="0.41420911528150134" src="/upload/294c0b8323395a7993ae932855deac82.png" data-type="png" data-w="1492" style="width: 100%;height: auto;"></p> <section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="color: black;line-height: 1.6;letter-spacing: 0px;word-break: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;font-size: 14px;padding: 10px;"> <p style="font-size: 15px;display: block;text-align: center;color: rgb(153, 153, 153);border-bottom: 1px solid rgb(238, 238, 238);margin-top: 5px;margin-bottom: 10px;">- END -</p> </section> <section data-recommend-type="list-title" data-recommend-tid="8" data-mpa-template="t" style="width: 100%;display: flex;justify-content: center;align-items: center;" data-mid="" data-from="yb-recommend"> <section style="width: 100%;background: rgb(255, 255, 255);border-radius: 3px;border-width: 1px;border-style: solid;border-color: rgb(232, 232, 235);padding: 20px 14px;" data-mid=""> <section style="width: 100%;display: flex;justify-content: center;align-items: center;align-items: flex-end;" data-mid=""> <section style="display: flex;justify-content: center;align-items: center;max-width: 100%;background: #fff;margin-bottom: -10px;z-index: 10;" data-mid=""> <section style="width: 10px;height: 10px;border-radius: 50%;border-width: 1px;border-style: solid;border-color: rgb(51, 51, 51);" data-mid=""> <br> </section> <section style="margin: 0 8px;height: 20px;font-size: 14px;font-weight: 500;color: #333333;line-height: 20px;" data-mid=""> <p data-mid="">往期推荐</p> </section> <section style="width: 10px;height: 10px;border-radius: 50%;border-width: 1px;border-style: solid;border-color: rgb(51, 51, 51);" data-mid=""> <br> </section> </section> </section> <section style="width: 100%;height: 1px;background: #333333;margin-bottom: 16px;" data-mid=""> <br> </section> <section style="width: 100%;" data-mid=""> <section data-mpa-template="t" data-recommend-article-type="list-title" data-recomment-template-id="8" data-recommend-article-id="2247492933_1" data-recommend-article-time="1606222800" data-recommend-article-cover="http://mmbiz.qpic.cn/sz_mmbiz_jpg/d7YzaYDnrxHGfic8y3Bh4JIbUnxlEmyskmGkk7AVBu6oQ8mlaBiav727GsZLcRFtgwd2kJBibYiaB25n1RZ4WDdTgg/0?wx_fmt=jpeg" data-recommend-article-title="怎么能避免写出慢SQL?" data-recommend-article-content-url="http://mp.weixin.qq.com/s?__biz=MzU3OTc1MDM1Mg==&amp;mid=2247492933&amp;idx=1&amp;sn=23f3519f6041f12b900b490c7b0bbf34&amp;chksm=fd63f5faca147cec8dff49cfde512083f2e451771159e59a49db8c27c9d2974814804102462b#rd"> <a href="http://mp.weixin.qq.com/s?__biz=MzU3OTc1MDM1Mg==&amp;mid=2247492933&amp;idx=1&amp;sn=23f3519f6041f12b900b490c7b0bbf34&amp;chksm=fd63f5faca147cec8dff49cfde512083f2e451771159e59a49db8c27c9d2974814804102462b&amp;scene=21#wechat_redirect" data-linktype="2"> <section data-recommend-title="t" style="width: 100%;background: #f5f5f5;display: flex;justify-content: center;align-items: center;flex-wrap: nowrap;padding: 6px 16px 6px;font-size: 13px;font-weight: 400;color: #333333;line-height: 18px;" data-mid=""> <p style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 100%;" data-mid="">怎么能避免写出慢SQL?</p> </section></a> </section> <section data-mpa-template="t" data-recommend-article-type="list-title" data-recomment-template-id="8" data-recommend-article-id="2247492793_1" data-recommend-article-time="1606139243" data-recommend-article-cover="http://mmbiz.qpic.cn/sz_mmbiz_jpg/d7YzaYDnrxF38FnraZYorHUvdVEce8eDS0cZynibtmENlsY0yveCZauLf0YEJeHHBjf4GibIM39pv6HTIBiafJevw/0?wx_fmt=jpeg" data-recommend-article-title="如何防止Redis脑裂导致数据丢失?" data-recommend-article-content-url="http://mp.weixin.qq.com/s?__biz=MzU3OTc1MDM1Mg==&amp;mid=2247492793&amp;idx=1&amp;sn=2dcc268eb5ede00699a4a2fe99b705e4&amp;chksm=fd63f406ca147d104b9c6a806c9c1242acbdbadd3d5028a0b268aac83aeadbc731d65653bee7#rd"> <a href="http://mp.weixin.qq.com/s?__biz=MzU3OTc1MDM1Mg==&amp;mid=2247492793&amp;idx=1&amp;sn=2dcc268eb5ede00699a4a2fe99b705e4&amp;chksm=fd63f406ca147d104b9c6a806c9c1242acbdbadd3d5028a0b268aac83aeadbc731d65653bee7&amp;scene=21#wechat_redirect" data-linktype="2"> <section data-recommend-title="t" style="width: 100%;display: flex;justify-content: center;align-items: center;flex-wrap: nowrap;padding: 6px 16px 6px;font-size: 13px;font-weight: 400;color: #333333;line-height: 18px;" data-mid=""> <p style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 100%;" data-mid="">如何防止Redis脑裂导致数据丢失?</p> </section></a> </section> <section data-mpa-template="t" data-recommend-article-type="list-title" data-recomment-template-id="8" data-recommend-article-id="2247492745_1" data-recommend-article-time="1606037700" data-recommend-article-cover="http://mmbiz.qpic.cn/sz_mmbiz_jpg/d7YzaYDnrxFKicXtS14MNY4pEDfLrqjlrGRR9lvLiaKYMbWW1N7NV85JWfzmSicRrCQCAPpfZIVfAcMgxMlCwDTPw/0?wx_fmt=jpeg" data-recommend-article-title="一个几乎每个系统必踩的坑儿:访问数据库超时" data-recommend-article-content-url="http://mp.weixin.qq.com/s?__biz=MzU3OTc1MDM1Mg==&amp;mid=2247492745&amp;idx=1&amp;sn=c9caa6056d282c6ce9796f9c33c3189b&amp;chksm=fd63f436ca147d209474bcbb5570235f18f405174af8f02df76762508dd2b61f1d0aa5a8b3a5#rd"> <a href="http://mp.weixin.qq.com/s?__biz=MzU3OTc1MDM1Mg==&amp;mid=2247492745&amp;idx=1&amp;sn=c9caa6056d282c6ce9796f9c33c3189b&amp;chksm=fd63f436ca147d209474bcbb5570235f18f405174af8f02df76762508dd2b61f1d0aa5a8b3a5&amp;scene=21#wechat_redirect" data-linktype="2"> <section data-recommend-title="t" style="width: 100%;background: #f5f5f5;display: flex;justify-content: center;align-items: center;flex-wrap: nowrap;padding: 6px 16px 6px;font-size: 13px;font-weight: 400;color: #333333;line-height: 18px;" data-mid=""> <p style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 100%;" data-mid="">一个几乎每个系统必踩的坑儿:访问数据库超时</p> </section></a> </section> <section data-mpa-template="t" data-recommend-article-type="list-title" data-recomment-template-id="8" data-recommend-article-id="2247492745_3" data-recommend-article-time="1606037700" data-recommend-article-cover="http://mmbiz.qpic.cn/sz_mmbiz_jpg/d7YzaYDnrxFKicXtS14MNY4pEDfLrqjlrfS6GgB6ToEISGcsnibW5gCLzxr6A4vItNCfudvh6iarLIHcp1qwL2AVQ/0?wx_fmt=jpeg" data-recommend-article-title="API和SDK有什么区别?" data-recommend-article-content-url="http://mp.weixin.qq.com/s?__biz=MzU3OTc1MDM1Mg==&amp;mid=2247492745&amp;idx=3&amp;sn=aad52536cd783d82722ac15b6c956ed3&amp;chksm=fd63f436ca147d20210d11094b207839e5d379e67ac8a23a007d20cb5b7d319bd0cbe77846ea#rd"> <a href="http://mp.weixin.qq.com/s?__biz=MzU3OTc1MDM1Mg==&amp;mid=2247492745&amp;idx=3&amp;sn=aad52536cd783d82722ac15b6c956ed3&amp;chksm=fd63f436ca147d20210d11094b207839e5d379e67ac8a23a007d20cb5b7d319bd0cbe77846ea&amp;scene=21#wechat_redirect" data-linktype="2"> <section data-recommend-title="t" style="width: 100%;display: flex;justify-content: center;align-items: center;flex-wrap: nowrap;padding: 6px 16px 6px;font-size: 13px;font-weight: 400;color: #333333;line-height: 18px;" data-mid=""> <p style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 100%;" data-mid="">API和SDK有什么区别?</p> </section></a> </section> <section data-mpa-template="t" data-recommend-article-type="list-title" data-recomment-template-id="8" data-recommend-article-id="2247492933_2" data-recommend-article-time="1606222800" data-recommend-article-cover="http://mmbiz.qpic.cn/sz_mmbiz_jpg/d7YzaYDnrxHwPia7ibLY26vI2Z80tUd7ydOumIqsfl7tIlLmUiaQC8tj3vjVN7LHicAkpYC7Yxs3icVcXOcXNibf3rbA/0?wx_fmt=jpeg" data-recommend-article-title="设计模式行为型:策略模式(StrategyPattern)" data-recommend-article-content-url="http://mp.weixin.qq.com/s?__biz=MzU3OTc1MDM1Mg==&amp;mid=2247492933&amp;idx=2&amp;sn=8c9d3fe59adeaecab32372f106569875&amp;chksm=fd63f5faca147cec856dd92a9af9d161f74177d4fea6bf02807ba1f5eb9229494f74d74bd3b7#rd"> <a href="http://mp.weixin.qq.com/s?__biz=MzU3OTc1MDM1Mg==&amp;mid=2247492933&amp;idx=2&amp;sn=8c9d3fe59adeaecab32372f106569875&amp;chksm=fd63f5faca147cec856dd92a9af9d161f74177d4fea6bf02807ba1f5eb9229494f74d74bd3b7&amp;scene=21#wechat_redirect" data-linktype="2"> <section data-recommend-title="t" style="width: 100%;background: #f5f5f5;display: flex;justify-content: center;align-items: center;flex-wrap: nowrap;padding: 6px 16px 6px;font-size: 13px;font-weight: 400;color: #333333;line-height: 18px;" data-mid=""> <p style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 100%;" data-mid="">设计模式行为型:策略模式(StrategyPattern)</p> </section></a> </section> <section data-mpa-template="t" data-recommend-article-type="list-title" data-recomment-template-id="8" data-recommend-article-id="2247492793_3" data-recommend-article-time="1606139243" data-recommend-article-cover="http://mmbiz.qpic.cn/sz_mmbiz_jpg/d7YzaYDnrxF38FnraZYorHUvdVEce8eDGdWicvUdiaEz4Bm9AaXCFSObic7QJcOMDsOakC6OiakfBTmtmibKQJ0BmDQ/0?wx_fmt=jpeg" data-recommend-article-title="边缘计算的未来是什么样的?" data-recommend-article-content-url="http://mp.weixin.qq.com/s?__biz=MzU3OTc1MDM1Mg==&amp;mid=2247492793&amp;idx=3&amp;sn=457dc11dafa1c34774e2c4cc316dfa7a&amp;chksm=fd63f406ca147d106ad6a880067a289036d189318f79225e938c365fe8c8e29359dc8ec5091d#rd"> <a href="http://mp.weixin.qq.com/s?__biz=MzU3OTc1MDM1Mg==&amp;mid=2247492793&amp;idx=3&amp;sn=457dc11dafa1c34774e2c4cc316dfa7a&amp;chksm=fd63f406ca147d106ad6a880067a289036d189318f79225e938c365fe8c8e29359dc8ec5091d&amp;scene=21#wechat_redirect" data-linktype="2"> <section data-recommend-title="t" style="width: 100%;display: flex;justify-content: center;align-items: center;flex-wrap: nowrap;padding: 6px 16px 6px;font-size: 13px;font-weight: 400;color: #333333;line-height: 18px;border-bottom:none !important;" data-mid=""> <p style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;max-width: 100%;" data-mid="">边缘计算的未来是什么样的?</p> </section></a> </section> </section> </section> </section> <section style="margin-top: 10px;"> <img class="rich_pages js_insertlocalimg" data-backh="123" data-backw="578" data-ratio="0.21328125" data-s="300,640" src="/upload/62e1c66b7ebe4ae627c388db8f4eef36.png" data-type="png" data-w="1280" style="font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: center;width: 100%;"> <br> </section>

接口测试和性能测试的区别

作者:测试人生路

## 一、什么是接口测试 接口测试是测试系统组件间接口的一种测试。接口测试主要用于检测外部系统与系统之间以及内部各个子系统之间的交互点。测试的重点是要检查数据的交换,传递和控制管理过程,以及系统间的相互逻辑依赖关系等。 ## 二、接口测试原理 通过测试程序模拟客户端向服务器发送请求报文,服务器接收请求报文后对相应的报文做出处理然后再把应答报文发送给客户端,客户端接收应答报文这一过程(request(请求)→response(响应)) ## 三、接口测试步骤 实现接口测试的两种办法,一种使用接口测试工具:apipost、jmeter、loadrunner。 比如选择apipost,按照接口文档或者自己抓包获取接口信息,填写url,请求方法,填写参数查看返回值 ![1.png](/storage/thumbnails/_signature/3NL553HD0U4NS80JR5SDLM6E47.png) jmeter也是差不多的步骤,不过jmeter安装需要配置环境变量。 ![2.png](/storage/thumbnails/_signature/C3UUNOUCG0OKEMR77RG6C6DNI.png) loadrunner需要单独通过浏览器录制脚本实现,然后配置场景,然后执行测试场景。 二是通过脚本进行接口测试,一般是使用python+requests。 ## 四、什么是性能测试 1.软件性能测试指通过自动化的测试工具模拟多种正常、峰值以及异常负载条件来对系统的各项性能指标进行的测试活动。 2.软件性能测试指通过模拟生产运行的业务压力或用户使用场景来测试系统的性能指标是否满足性能需求要求的测试活动。 3.软件性能测试指检验软件性能是否符合性能指标需求定义的测试活动。 ## 五、性能测试步骤 性能测试一般是通过jmeter和loadrunner来进行测试的,我们以loadrunner为例子来说: LR进行测试对于大多数人来说无法三个步骤:录制接口(或者接口抓包),配置场景,执行测试场景,配置多用户(或者说多线程)然后进行性能测试。 ## 六、接口测试和性能测试的区别 接口测试和性能测试主要区别是侧重点不一样,接口测试是针对后端开发的接口(不一定是http的,也有可能是tcp的),而性能测试是偏重于产品的各方面各阶段性能(接口的性能,页面的性能,app的性能),可以说性能测试的覆盖度比接口更大一些。 以web端测试为例子。 简单来说,它俩区别就在于性能测试有多用户(并发)的概念,而接口测试只是单用户场景。我们做接口测试是是用于验证接口的请求和返回是否匹配(其实可以理解成接口测试也是一种功能测试); 而性能测试则是很多人同时在做这种接口测试,更侧重于真实的用户场景。因为我们研发完的产品投入市场后,不会就专门给某一个人使用功能,肯定是会有很多人同时在用我们的产品功能。那在这里,很多人同时在用其实就是性能的一个关键点。 所以性能测试和接口测试的区别为:性能测试近乎等同于很多用户同时在做接口测试。 测试工具下载地址: apipost下载地址: [https://www.apipost.cn](https://www.apipost.cn/?dt=20201127) jmeter下载地址: [https://jmeter.apache.org/](https://jmeter.apache.org/)

Redis主从复制与优化

作者:微信小助手

<p data-mpa-powered-by="yiban.io" style="max-width: 100%;min-height: 1em;letter-spacing: 0.544px;white-space: normal;color: rgb(62, 71, 83);font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: center;background-color: rgb(255, 255, 255);font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-family: Optima-Regular, PingFangTC-light;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(127, 127, 127);font-size: 14px;line-height: 1.75em;box-sizing: border-box !important;overflow-wrap: break-word !important;">点击上方“</span><span style="max-width: 100%;font-size: 14px;line-height: 1.75em;color: rgb(0, 176, 240);box-sizing: border-box !important;overflow-wrap: break-word !important;">服务端思维</span><span style="max-width: 100%;color: rgb(127, 127, 127);font-size: 14px;line-height: 1.75em;box-sizing: border-box !important;overflow-wrap: break-word !important;">”,选择“</span></span><span style="max-width: 100%;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">设为星标</span><span style="max-width: 100%;color: rgb(127, 127, 127);letter-spacing: 0.544px;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">”</span></span></p> <p style="max-width: 100%;min-height: 1em;letter-spacing: 0.544px;white-space: normal;font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: center;background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-family: Optima-Regular, PingFangTC-light;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.544px;color: rgb(127, 127, 127);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">回复”</span><span style="max-width: 100%;letter-spacing: 0.544px;font-size: 14px;color: rgb(0, 122, 170);box-sizing: border-box !important;overflow-wrap: break-word !important;">669</span><span style="max-width: 100%;letter-spacing: 0.544px;color: rgb(127, 127, 127);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">“获取独家整理的精选资料集</span></span></p> <p style="max-width: 100%;min-height: 1em;letter-spacing: 0.544px;white-space: normal;font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: center;background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-family: Optima-Regular, PingFangTC-light;letter-spacing: 0.544px;color: rgb(127, 127, 127);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;">回复”</span><span style="max-width: 100%;letter-spacing: 0.544px;color: rgb(0, 122, 170);box-sizing: border-box !important;overflow-wrap: break-word !important;">加群</span><span style="max-width: 100%;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;">“加入全国服务端高端社群「后端圈」</span></span></p> <p style="text-align: center;"><img class="rich_pages js_insertlocalimg" data-backh="313" data-backw="500" src="/upload/5c2790e07695a61799d7d9ff1927d0c.jpg" data-cropx1="0" data-cropx2="500" data-cropy1="0" data-cropy2="304.4982698961938" data-ratio="0.61" data-s="300,640" src="https://mmbiz.qpic.cn/mmbiz_jpg/hUzEz6Bmcaotnr3egDpqToEJAAO8NVKib0Rk0vRiaTNGIAWIJZuwuwbf81iaZ0SDQficfibZFvRAIVvQIeNdu08ic0gw/640?wx_fmt=jpeg" data-type="jpeg" data-w="500" style="width: 578px;height: 352px;"></p> <p style="text-align: left;"><span style="background-color: rgb(255, 255, 255);color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: 1.2em;font-weight: 600;text-align: start;">主从复制</span></p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">我们关注主从复制之前,首先要考虑单机有什么问题?</p> <ul style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>机器故障</p></li> <li style="list-style: none;display: table-row;"><p>容量瓶颈</p></li> <li style="list-style: none;display: table-row;"><p>QPS瓶颈</p></li> </ul> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">这些都是单节点所遇到的问题,所以这个时候出现了主从复制(一主一从,一主多从)</p> <figure style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"> <img data-ratio="0.41805555555555557" src="/upload/ea6a2b55099acf63ee3e7c5aa91314ce.png" data-type="png" data-w="720" style="display: block;margin-right: auto;margin-left: auto;background-color: transparent;animation: 0.5s ease-in 0s 1 normal none running fxRichTextFadeIn;"> </figure> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">使用主从复制可以:</p> <ul style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>数据副本</p></li> <li style="list-style: none;display: table-row;"><p>扩展读性能</p></li> </ul> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">注意:</p> <ul style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>一个master可以有多个slave</p></li> <li style="list-style: none;display: table-row;"><p>一个slave只有一个master</p></li> <li style="list-style: none;display: table-row;"><p>数据流向是单向的,master到slave</p></li> </ul> <hr style="margin: 4em auto;width: 240px;max-width: 100%;border-right: none;border-bottom: none;border-left: none;border-top-style: solid;border-top-color: rgb(211, 211, 211);color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"> <h2 style="margin-top: 2.33333em;margin-bottom: 1.16667em;font-variant-numeric: inherit;font-weight: 600;font-stretch: inherit;font-size: 1.2em;line-height: 1.5;font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;clear: left;color: rgb(18, 18, 18);text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">主从复制的配置</h2> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><strong>两种实现方式</strong></p> <ul style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>slaveof命令</p></li> </ul> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">两台机器:主节点:47.11.11.11 从节点 47.22.22.22</p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">在从节点执行 slaveof 命令</p> <pre style="padding: 0.88889em;font-size: 0.9em;word-break: normal;overflow-wrap: normal;overflow: auto;background: rgb(246, 246, 246);border-radius: 4px;"><code style="border-radius: 0px;font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace;font-size: inherit;background-color: inherit;">47.22.22.22-6379 &gt; slacefof 47.11.11.11 6379<br>OK</code></pre> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">取消复制:</p> <pre style="padding: 0.88889em;font-size: 0.9em;word-break: normal;overflow-wrap: normal;overflow: auto;background: rgb(246, 246, 246);border-radius: 4px;"><code style="border-radius: 0px;font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace;font-size: inherit;background-color: inherit;">47.22.22.22-6379 &gt; slacefof no one<br>OK</code></pre> <ul style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>修改配置</p></li> </ul> <pre style="padding: 0.88889em;font-size: 0.9em;word-break: normal;overflow-wrap: normal;overflow: auto;background: rgb(246, 246, 246);border-radius: 4px;"><code style="border-radius: 0px;font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace;font-size: inherit;background-color: inherit;">slaveof ip port //从节点ip + 端口<br>slave-read-only yes //开启只做读的操作</code></pre> <ul style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>两种方式比较</p></li> </ul> <figure style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"> <img data-ratio="0.18194444444444444" src="/upload/1af5fc05d7c58423f5cef762836d5071.png" data-type="png" data-w="720" style="display: block;margin-right: auto;margin-left: auto;background-color: transparent;animation: 0.5s ease-in 0s 1 normal none running fxRichTextFadeIn;"> </figure> <ul style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>查看主从</p></li> </ul> <pre style="padding: 0.88889em;font-size: 0.9em;word-break: normal;overflow-wrap: normal;overflow: auto;background: rgb(246, 246, 246);border-radius: 4px;"><code style="border-radius: 0px;font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace;font-size: inherit;background-color: inherit;">127.0.0.1:6379&gt; info replication<br># Replication<br>role:master //主节点 <br>connected_slaves:0<br>master_replid:1d43401335a5343b27b1638fc9843e3a593fc1a7<br>master_replid2:0000000000000000000000000000000000000000<br>master_repl_offset:0<br>second_repl_offset:-1<br>repl_backlog_active:0<br>repl_backlog_size:1048576<br>repl_backlog_first_byte_offset:0<br>repl_backlog_histlen:0<br></code></pre> <hr style="margin: 4em auto;width: 240px;max-width: 100%;border-right: none;border-bottom: none;border-left: none;border-top-style: solid;border-top-color: rgb(211, 211, 211);color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">知识点 :</p> <ul style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>主节点 runID:</p></li> </ul> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">每个redis节点启动后都会动态分配一个40位的十六进制字符串为运行ID。运行ID的主要作用是来唯一识别redis节点,比如从节点保存主节点的运行ID识别自已正在复制是哪个主节点。如果只使用ip+port的方式识别主节点,那么主节点重启变更了整体数据集(如替换RDB/AOF文件),从节点再基于偏移量复制数据将是不安全的,因此当运行ID变化后从节点将做全量复制。可以在info server命令查看当前节点的运行ID。</p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">需要注意的是redis关闭再启动,运行的id会随之变化。</p> <hr style="margin: 4em auto;width: 240px;max-width: 100%;border-right: none;border-bottom: none;border-left: none;border-top-style: solid;border-top-color: rgb(211, 211, 211);color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"> <h2 style="margin-top: 2.33333em;margin-bottom: 1.16667em;font-variant-numeric: inherit;font-weight: 600;font-stretch: inherit;font-size: 1.2em;line-height: 1.5;font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;clear: left;color: rgb(18, 18, 18);text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">全量复制和部分复制等</h2> <h3 style="margin-top: 1.90909em;margin-bottom: 1.27273em;font-variant-numeric: inherit;font-weight: 600;font-stretch: inherit;font-size: 1.1em;line-height: 1.5;font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;clear: left;color: rgb(18, 18, 18);text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">全量复制</h3> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">用于初次复制或其它无法进行部分复制的情况,将主节点中的所有数据都发送给从节点。当数据量过大的时候,会造成很大的网络开销。</p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">redis2.8+ 全量复制流程</p> <figure style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"> <img data-ratio="0.6236111111111111" src="/upload/b2fbd2d4e4963d88caa77a1451a5f080.png" data-type="png" data-w="720" style="display: block;margin-right: auto;margin-left: auto;background-color: transparent;animation: 0.5s ease-in 0s 1 normal none running fxRichTextFadeIn;"> </figure> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">开销:</p> <ol style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;counter-reset: ol 0;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>bgsave时间</p></li> <li style="list-style: none;display: table-row;"><p>RDB文件网络传输</p></li> <li style="list-style: none;display: table-row;"><p>从节点清空数据时间</p></li> <li style="list-style: none;display: table-row;"><p>从节点加载RDB时间</p></li> <li style="list-style: none;display: table-row;"><p>可能的AOF重写时间</p></li> </ol> <h3 style="margin-top: 1.90909em;margin-bottom: 1.27273em;font-variant-numeric: inherit;font-weight: 600;font-stretch: inherit;font-size: 1.1em;line-height: 1.5;font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;clear: left;color: rgb(18, 18, 18);text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">部分复制</h3> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">用于处理在主从复制中因网络闪退等原因造成数据丢失场景,当从节点再次连上主节点,如果条件允许,主节点会补发丢失数据给从节点,因为补发的数据远远小于全量数据,可以有效避免全量复制的过高开销。但需要注意,如果网络中断时间过长,造成主节点没有能够完整地保存中断期间执行的写命令,则无法进行部分复制,仍使用全量复制 。</p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">流程:</p> <figure style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"> <img data-ratio="0.7375" src="/upload/4d609f124b79828f417062e57b8478a2.png" data-type="png" data-w="720" style="display: block;margin-right: auto;margin-left: auto;background-color: transparent;animation: 0.5s ease-in 0s 1 normal none running fxRichTextFadeIn;"> </figure> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><span style="font-size: 1.1em;font-weight: 600;">复</span><span style="font-size: 1.1em;font-weight: 600;">制偏移量:</span><br></p> <ul style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>参与复制的主从节点都会维护自身复制偏移量,主节点在处理完写入命令操作后,会把命令的字节长度做累加记录,统计信息在info replication中的master_repl_offset指标中。</p></li> <li style="list-style: none;display: table-row;"><p>从节点每秒钟上报自身的复制偏移量给主节点,因此主节点也会保存从节点的复制偏移量slave0:ip=192.168.1.3,port=6379,state=online,offset=116424,lag=0</p></li> <li style="list-style: none;display: table-row;"><p>从节点在接收到主节点发送的命令后,也会累加记录自身的偏移量。统计信息在info replication中的slave_repl_offset中。</p></li> </ul> <h3 style="margin-top: 1.90909em;margin-bottom: 1.27273em;font-variant-numeric: inherit;font-weight: 600;font-stretch: inherit;font-size: 1.1em;line-height: 1.5;font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;clear: left;color: rgb(18, 18, 18);text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">复制积压缓冲区:</h3> <ul style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>复制积压缓冲区是保存在主节点上的一个固定长度的队列,默认大小为1MB,当主节点有连接的从节点时被创建,这时主节点响应写命令时,不但会把命令发给从节点,还会写入复制积压缓冲区。<br>在命令传播阶段,主节点除了将写命令发送给从节点,还会发送一份给复制积压缓冲区,作为写命令的备份;除了存储写命令,复制积压缓冲区中还存储了其中 的每个字节对应的复制偏移量(offset) 。由于复制积压缓冲区定长且先进先出,所以它保存的是主节点最近执行的写命令;时间较早的写命令会被挤出缓冲区。</p></li> </ul> <hr style="margin: 4em auto;width: 240px;max-width: 100%;border-right: none;border-bottom: none;border-left: none;border-top-style: solid;border-top-color: rgb(211, 211, 211);color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"> <h2 style="margin-top: 2.33333em;margin-bottom: 1.16667em;font-variant-numeric: inherit;font-weight: 600;font-stretch: inherit;font-size: 1.2em;line-height: 1.5;font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;clear: left;color: rgb(18, 18, 18);text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">生产中常见问题</h2> <p><span style="color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;background-color: rgb(255, 255, 255);">读写分离</span></p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">分流到从节点。主节点写数据,从节点读数据,可能遇到读问题</p> <ol style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;counter-reset: ol 0;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>复制数据延迟</p></li> <li style="list-style: none;display: table-row;"><p>读到过期数据</p></li> <li style="list-style: none;display: table-row;"><p>从节点故障</p></li> </ol> <p><span style="color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;background-color: rgb(255, 255, 255);">主从配置不一致</span></p> <ol style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;counter-reset: ol 0;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>例如maxmemory 不一致 会导致 丢失数据</p></li> <li style="list-style: none;display: table-row;"><p>例如数据结构优化参数(例如hash-max-ziplist-entries):内存不一致</p></li> </ol> <p><span style="color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;background-color: rgb(255, 255, 255);">规避全量复制</span></p> <ol style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;counter-reset: ol 0;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>第一次全量复制的时候<br>- 第一次不可避免,尽量小节点 ,低峰处理</p></li> <li style="list-style: none;display: table-row;"><p>节点 运行ID不匹配<br>- 故障转移,例如哨兵或者集群</p></li> <li style="list-style: none;display: table-row;"><p>复制积压缓存区不足<br>- 增大复制缓存区配置rel_backlog_size ,网络增强</p></li> </ol> <p><span style="color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;background-color: rgb(255, 255, 255);">规避复制风暴</span></p> <ol style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;counter-reset: ol 0;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>单机器复制风暴(redis&lt;4.0当master宕机重启,会导致该机器下所有slave同时产生复制。避免单机部署一套redis主从)====》主节点分散多台机</p></li> </ol> <h3 style="margin-top: 1.90909em;margin-bottom: 1.27273em;font-variant-numeric: inherit;font-weight: 600;font-stretch: inherit;font-size: 1.1em;line-height: 1.5;font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;clear: left;color: rgb(18, 18, 18);text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">最后的注意事项:</h3> <ul style="margin-top: 1.4em;margin-bottom: 1.4em;display: table;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="list-style: none;display: table-row;"><p>在上述的过程的实现是从库不开启AOF持久化情况下,如果从库开启的AOF持久化,重启时候依然使用全量复制。</p></li> <li style="list-style: none;display: table-row;"><p>之前从master复制过来的数据并不会丢失,只是不再同步之前master(如上图的6379节点)后续写入的数据</p></li> <li style="list-style: none;display: table-row;"><p>slaveof 可以用来改变其所属的master节点,即重新成为另一台master的slave,但是新的master首先就会把从节点的数据全部清除掉</p></li> <li style="list-style: none;display: table-row;"><p>关于读写分离延时: 读写分离 ,master会一步将数据复制到slave,如果slave发生阻塞,则会延迟master数据的写命令,造成数据不一致的问题。-------一般不考虑这个问题</p></li> <li style="list-style: none;display: table-row;"><p>读到过期数据:redis在删除key时有两种策略,一种是懒惰型策略,即只有当redis操作这个key时才会将key删除,第二种是定期采样key删除--------当key数据非常多时,采样速度比不上key生成速度会造成很多过期数据没有删除,因为redis一般都是在master节点(增加删除数据),slave查询到过期数据也不能删除。会导致slave读到过期数据(在redis3.2中已经解决)</p></li> </ul> <section powered-by="xiumi.us" style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);font-size: 16px;text-align: center;color: rgb(62, 71, 83);font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <p style="margin-right: 16px;margin-left: 16px;max-width: 100%;min-height: 1em;letter-spacing: 1.5px;line-height: 1.5em;font-family: -apple-system-font, BlinkMacSystemFont, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(77, 168, 238);box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 12px;letter-spacing: 1px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;font-size: 17px;letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 12px;box-sizing: border-box !important;overflow-wrap: break-word !important;">— 本文结束 —</span></strong></span></strong></span><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <p style="margin-right: 16px;margin-left: 16px;max-width: 100%;min-height: 1em;letter-spacing: 1.5px;line-height: 1.5em;font-family: -apple-system-font, BlinkMacSystemFont, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <section data-mpa-template="t" mpa-from-tpl="t" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section data-id="93709" mpa-from-tpl="t" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section mpa-from-tpl="t" style="padding: 5px;max-width: 100%;border-style: solid;border-width: 2px;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section mpa-from-tpl="t" style="padding: 15px;max-width: 100%;border-style: dashed;border-width: 1px;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section mpa-from-tpl="t" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <span data-role="width" data-width="80%" style="max-width: 100%;display: inline-block;width: 425.215px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><img border="0" class="__bg_gif" data-ratio="0.08658008658008658" data-type="gif" data-w="462" data-width="80%" height="" title="" width="80%" src="/upload/b0b0d65a8077fe5fc54ccd945913d458.png" style="box-sizing: border-box !important;overflow-wrap: break-word !important;visibility: visible !important;width: 340.156px !important;"></span> </section> <p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;text-align: justify;letter-spacing: 1.5px;line-height: normal;color: rgb(136, 136, 136);font-size: 13px;box-sizing: border-box !important;overflow-wrap: break-word !important;">●&nbsp;<a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzA5NDg3MjAwMQ==&amp;mid=2457103446&amp;idx=1&amp;sn=0d0c0cb83235675963be01cb7b8ddb7b&amp;chksm=87c8c4f8b0bf4dee91ab4a8041363afc0839df2dbc219e2c0938ed2e53d13af4a966121314f4&amp;scene=21#wechat_redirect" textvalue="漫谈设计模式在 Spring 框架中的良好实践" data-itemshowtype="0" tab="innerlink" data-linktype="2" hasload="1" style="color: var(--weui-LINK);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">漫谈设计模式在 Spring 框架中的良好实践</a></p> <p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;text-align: justify;letter-spacing: 1.5px;line-height: normal;color: rgb(136, 136, 136);font-size: 13px;box-sizing: border-box !important;overflow-wrap: break-word !important;">●&nbsp;<a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzA5NDg3MjAwMQ==&amp;mid=2457103280&amp;idx=1&amp;sn=f3bd921a2f88a9a3440c0ff1e03d1bd9&amp;chksm=87c8c31eb0bf4a0820a572626141cfb1fc87ea1c7072a16f61992d67d21d9b61b556de2d6cd7&amp;scene=21#wechat_redirect" textvalue="颠覆微服务认知:深入思考微服务的七个主流观点" data-itemshowtype="11" tab="innerlink" data-linktype="2" hasload="1" style="color: var(--weui-LINK);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">颠覆微服务认知:</a><a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzA5NDg3MjAwMQ==&amp;mid=2457103280&amp;idx=1&amp;sn=f3bd921a2f88a9a3440c0ff1e03d1bd9&amp;chksm=87c8c31eb0bf4a0820a572626141cfb1fc87ea1c7072a16f61992d67d21d9b61b556de2d6cd7&amp;scene=21#wechat_redirect" textvalue="颠覆微服务认知:深入思考微服务的七个主流观点" data-itemshowtype="11" tab="innerlink" data-linktype="2" hasload="1" style="color: var(--weui-LINK);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">深入思考微服务的七个主流观点</a><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;text-align: justify;letter-spacing: 1.5px;line-height: normal;color: rgb(136, 136, 136);font-size: 13px;box-sizing: border-box !important;overflow-wrap: break-word !important;">●&nbsp;<a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzA5NDg3MjAwMQ==&amp;mid=2457103129&amp;idx=1&amp;sn=3e0386d5f6f3b706e6bd72195648e34e&amp;chksm=87c8c3b7b0bf4aa1530354a3b1507b33c5033db70e4c61328e9ed68118e24212a36d763671d8&amp;scene=21#wechat_redirect" textvalue="人人都是 API 设计者" data-itemshowtype="0" tab="innerlink" data-linktype="2" hasload="1" style="color: var(--weui-LINK);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">人人都是 API 设计者</a></p> <p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;text-align: justify;letter-spacing: 1.5px;line-height: normal;color: rgb(136, 136, 136);font-size: 13px;box-sizing: border-box !important;overflow-wrap: break-word !important;">●&nbsp;<a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzA5NDg3MjAwMQ==&amp;mid=2457103538&amp;idx=1&amp;sn=9261bb2b742fd41168889738e0377a9c&amp;chksm=87c8c41cb0bf4d0a5401fac49320faebfc4ac5ad7711d39758ecb0fd9df43354d19aa5aa57e3&amp;scene=21#wechat_redirect" textvalue="一文讲透微服务下如何保证事务的一致性" data-itemshowtype="0" tab="innerlink" data-linktype="2" hasload="1" style="color: var(--weui-LINK);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">一文讲透微服务下如何保证事务的一致性</a><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;text-align: justify;letter-spacing: 1.5px;line-height: normal;color: rgb(136, 136, 136);font-size: 13px;box-sizing: border-box !important;overflow-wrap: break-word !important;">●&nbsp;<a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzA5NDg3MjAwMQ==&amp;mid=2457103584&amp;idx=1&amp;sn=007226d602709eb3c840a0539dae678b&amp;chksm=87c8c44eb0bf4d58e9aaba3221c0d9f61556f4a199691b428dd322231ab450023e748cfc620a&amp;scene=21#wechat_redirect" textvalue="要黑盒测试微服务内部服务间调用,我该如何实现?" data-itemshowtype="0" tab="innerlink" data-linktype="2" hasload="1" style="color: var(--weui-LINK);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">要黑盒测试微服务内部服务间调用,我该如何实现?</a><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> </section> </section> </section> </section> <p style="max-width: 100%;min-height: 1em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br mpa-from-tpl="t" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> </section> </section> </section> </section> </section> </section> <section powered-by="xiumi.us" style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);font-size: 16px;text-align: center;color: rgb(62, 71, 83);font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <p style="max-width: 100%;min-height: 1em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><img data-ratio="0.3708738" data-type="png" data-w="515" src="/upload/328ca60e65e37255ffc9d00bfba58c3c.png" style="vertical-align: middle;box-sizing: border-box !important;overflow-wrap: break-word !important;visibility: visible !important;width: 515px !important;"></p> <p style="margin-right: 16px;margin-left: 16px;max-width: 100%;min-height: 1em;letter-spacing: 1.5px;line-height: 1.5em;font-family: -apple-system-font, BlinkMacSystemFont, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="margin-top: 10px;margin-bottom: 10px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;display: inline-block;width: 574px;vertical-align: top;border-style: solid;border-width: 1px;border-radius: 0px;border-color: rgb(225, 238, 226);background-color: rgba(191, 224, 216, 0.58);box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="padding: 10px;max-width: 100%;display: inline-block;width: 572px;vertical-align: top;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;font-size: 15px;color: rgb(46, 101, 91);line-height: 1.8;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <p style="max-width: 100%;min-height: 1em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 12px;box-sizing: border-box !important;overflow-wrap: break-word !important;">关注我,回复 「加群」 加入各种主题讨论群。</span></p> </section> </section> </section> </section> </section> <section powered-by="xiumi.us" style="margin-top: 10px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;background-color: rgb(147, 195, 186);height: 2px;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> </section> </section> </section> </section> </section> </section> </section> </section> </section> <section powered-by="xiumi.us" style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);font-size: 16px;text-align: center;color: rgb(62, 71, 83);font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <p style="max-width: 100%;min-height: 1em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <p style="margin-right: 16px;margin-left: 16px;max-width: 100%;min-height: 1em;letter-spacing: 1.5px;line-height: 1.5em;font-family: -apple-system-font, BlinkMacSystemFont, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 12px;letter-spacing: 1px;color: rgb(0, 0, 0);box-sizing: border-box !important;overflow-wrap: break-word !important;">对「服务端思维」有期待,请在文末点个<span style="max-width: 100%;color: rgb(198, 19, 25);box-sizing: border-box !important;overflow-wrap: break-word !important;">在看</span></span></strong></p> <p style="margin-right: 16px;margin-left: 16px;max-width: 100%;min-height: 1em;letter-spacing: 1.5px;line-height: 1.5em;font-family: -apple-system-font, BlinkMacSystemFont, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 12px;letter-spacing: 1px;color: rgb(0, 0, 0);box-sizing: border-box !important;overflow-wrap: break-word !important;">喜欢这篇文章,欢迎<span style="max-width: 100%;color: rgb(198, 19, 25);box-sizing: border-box !important;overflow-wrap: break-word !important;">转发、分享</span>朋友圈</span></strong></p> </section> </section> </section> <p style="max-width: 100%;min-height: 1em;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);color: rgb(63, 63, 63);font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif;font-size: 14px;text-align: center;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <section data-role="outer" label="Powered by 135editor.com" style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);font-size: 16px;color: rgb(63, 63, 63);font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif;text-align: center;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section data-role="outer" label="Powered by 135editor.com" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section data-tools="135编辑器" data-id="94783" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;display: flex;justify-content: flex-end;align-items: center;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;width: 20px;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;width: 20px;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <img data-ratio="1.037037037037037" data-type="png" data-w="27" data-width="100%" src="/upload/6087772642bee9a4b8104517c36c9aa7.png" style="display: block;box-sizing: border-box !important;overflow-wrap: break-word !important;visibility: visible !important;width: 20px !important;"> </section> </section> <section style="max-width: 100%;display: inline-block;text-align: right;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section data-brushtype="text" style="margin-bottom: -15px;max-width: 100%;letter-spacing: 2px;transform: rotate(0deg);color: rgb(0, 0, 0);box-sizing: border-box !important;overflow-wrap: break-word !important;"> 在看点这里 </section> </section> <section style="max-width: 100%;width: 22px;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="margin-top: 15px;max-width: 100%;width: 22px;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <img class="__bg_gif" data-ratio="1" data-type="gif" data-w="100" data-width="100%" src="/upload/8b34c0e8ddcf33f56770ae9f44c95ce1.png" style="display: block;box-sizing: border-box !important;overflow-wrap: break-word !important;visibility: visible !important;width: 22px !important;"> </section> </section> </section> </section> </section> </section>

Java8 Stream:20 个实例,玩转集合的筛选、归约、分组、聚合

作者:微信小助手

<section> <section data-id="137" data-tools="非找你编辑器" data-tools-id="85108"> <section> <section data-id="140" data-tools="非找你编辑器"> <section style="margin-right:0%;margin-left:0%;"> <section style="display:inline-block;vertical-align:middle;width:80%;" data-width="80%"> <section style=""> <section style="margin-top:10px;margin-bottom:10px;text-align:center;"> <section style="display:inline-block;"> <section style="font-size:0px;padding-bottom:3px;"> <section style="display:inline-block;vertical-align:middle;"> <section style="width: 5px;height: 1px;background-color: rgb(217, 217, 217);" data-width="5px"> <span style="line-height: 300px;float: left;height: 0px;clear: both;overflow: hidden;"></span> </section> <section style="width: 1px;height: 5px;margin-top: -3px;margin-right: auto;margin-left: auto;background-color: rgb(217, 217, 217);" data-width="1px"> <span style="line-height: 300px;float: left;height: 0px;clear: both;overflow: hidden;"></span> </section> </section> <section style="margin-top:-1px;margin-right:-5px;margin-left:-5px;width:100%;display:inline-block;vertical-align:middle;padding-right:8px;padding-left:8px;" data-width="100%"> <section style="width: 100%;height: 1px;background-color: rgb(217, 217, 217);" data-width="100%"> <span style="line-height: 300px;float: left;height: 0px;clear: both;overflow: hidden;"></span> </section> </section> <section style="display:inline-block;vertical-align:middle;"> <section style="width: 5px;height: 1px;background-color: rgb(217, 217, 217);" data-width="5px"> <span style="line-height: 300px;float: left;height: 0px;clear: both;overflow: hidden;"></span> </section> <section style="width: 1px;height: 5px;margin-top: -3px;margin-right: auto;margin-left: auto;background-color: rgb(217, 217, 217);" data-width="1px"> <span style="line-height: 300px;float: left;height: 0px;clear: both;overflow: hidden;"></span> </section> </section> </section> <section style="padding-left:15px;padding-right:15px;color:rgb(161,161,161);"> <p><strong>点击上方关注这个神奇的公众号~</strong></p> </section> <section style="font-size:0px;"> <section style="display:inline-block;vertical-align:middle;"> <section style="width: 5px;height: 1px;background-color: rgb(217, 217, 217);" data-width="5px"> <strong><span style="line-height: 300px;float: left;height: 0px;clear: both;overflow: hidden;"></span></strong> </section> <section style="width: 1px;height: 5px;margin-top: -3px;margin-right: auto;margin-left: auto;background-color: rgb(217, 217, 217);" data-width="1px"> <strong><span style="line-height: 300px;float: left;height: 0px;clear: both;overflow: hidden;"></span></strong> </section> </section> <section style="margin-top:-1px;margin-right:-5px;margin-left:-5px;width:100%;display:inline-block;vertical-align:middle;padding-right:8px;padding-left:8px;" data-width="100%"> <section style="width: 100%;height: 1px;background-color: rgb(217, 217, 217);" data-width="100%"> <strong><span style="line-height: 300px;float: left;height: 0px;clear: both;overflow: hidden;"></span></strong> </section> </section> <section style="display:inline-block;vertical-align:middle;"> <section style="width: 5px;height: 1px;background-color: rgb(217, 217, 217);" data-width="5px"> <strong><span style="line-height: 300px;float: left;height: 0px;clear: both;overflow: hidden;"></span></strong> </section> <section style="width: 1px;height: 5px;margin-top: -3px;margin-right: auto;margin-left: auto;background-color: rgb(217, 217, 217);" data-width="1px"> <span style="line-height: 300px;float: left;height: 0px;clear: both;overflow: hidden;"></span> </section> </section> </section> </section> </section> </section> </section> <section style="display:inline-block;vertical-align:middle;width:20%;" data-width="20%"> <section style=""> <section style="text-align:center;margin:-10px 0% 10px;"> <section style="vertical-align:middle;display:inline-block;width:100%;overflow:hidden !important;" data-width="100%"> <img data-ratio="0.94375" src="/upload/dde7acdc77dc0167b092df91f5896bb3.png" data-type="gif" data-w="480" data-width="100%" style="vertical-align:middle;width:100%;" width="100%"> <span style="line-height: 300px;float: left;height: 0px;clear: both;overflow: hidden;"></span> </section> </section> </section> </section> </section> </section> <p mpa-paragraph-type="body" style="max-width: 100%;min-height: 1em;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: right;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 10px;color: rgb(136, 136, 136);box-sizing: border-box !important;overflow-wrap: break-word !important;">来源:blog.csdn.net/mu_wind/article/details/109516995</span></p> <section data-tool="mdnice编辑器" data-website="https://www.mdnice.com" style="padding-right: 10px;padding-left: 10px;max-width: 100%;white-space: normal;background-color: rgb(255, 255, 255);font-size: 16px;line-height: 1.6;letter-spacing: 0px;word-break: break-word;text-align: left;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <ul data-tool="mdnice编辑器" class="list-paddingleft-2" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;max-width: 100%;color: black;overflow-wrap: break-word !important;"> <li style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="margin-top: 5px;margin-bottom: 5px;max-width: 100%;line-height: 26px;color: rgb(1, 1, 1);box-sizing: border-box !important;overflow-wrap: break-word !important;"> 1 Stream概述 </section></li> <li style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="margin-top: 5px;margin-bottom: 5px;max-width: 100%;line-height: 26px;color: rgb(1, 1, 1);box-sizing: border-box !important;overflow-wrap: break-word !important;"> 2 Stream的创建 </section></li> <li style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="margin-top: 5px;margin-bottom: 5px;max-width: 100%;line-height: 26px;color: rgb(1, 1, 1);box-sizing: border-box !important;overflow-wrap: break-word !important;"> 3 Stream的使用 </section></li> <li style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="margin-top: 5px;margin-bottom: 5px;max-width: 100%;line-height: 26px;color: rgb(1, 1, 1);box-sizing: border-box !important;overflow-wrap: break-word !important;"> 4 Stream源码解读 </section></li> </ul> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(58, 58, 58);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="margin-right: auto;margin-left: auto;max-width: 100%;width: auto;border-radius: 5px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><img data-ratio="0.7512899896800825" data-type="png" data-w="969" src="/upload/f57004b7175c1919ad03f690b9c12179.png" style="margin-bottom: 15px;border-radius: 5px;display: block;top: auto;left: auto;right: auto;bottom: auto;width: 657px;box-sizing: border-box !important;overflow-wrap: break-word !important;visibility: visible !important;"></span></span><span style="max-width: 100%;color: rgb(58, 58, 58);box-sizing: border-box !important;overflow-wrap: break-word !important;">先贴上几个案例,水平高超的同学可以挑战一下:</span><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <ol data-tool="mdnice编辑器" class="list-paddingleft-2" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;max-width: 100%;color: black;overflow-wrap: break-word !important;"> <li style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="margin-top: 5px;margin-bottom: 5px;max-width: 100%;line-height: 26px;color: rgb(1, 1, 1);box-sizing: border-box !important;overflow-wrap: break-word !important;"> 从员工集合中筛选出salary大于8000的员工,并放置到新的集合里。 </section></li> <li style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="margin-top: 5px;margin-bottom: 5px;max-width: 100%;line-height: 26px;color: rgb(1, 1, 1);box-sizing: border-box !important;overflow-wrap: break-word !important;"> 统计员工的最高薪资、平均薪资、薪资之和。 </section></li> <li style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="margin-top: 5px;margin-bottom: 5px;max-width: 100%;line-height: 26px;color: rgb(1, 1, 1);box-sizing: border-box !important;overflow-wrap: break-word !important;"> 将员工按薪资从高到低排序,同样薪资者年龄小者在前。 </section></li> <li style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="margin-top: 5px;margin-bottom: 5px;max-width: 100%;line-height: 26px;color: rgb(1, 1, 1);box-sizing: border-box !important;overflow-wrap: break-word !important;"> 将员工按性别分类,将员工按性别和地区分类,将员工按薪资是否高于8000分为两部分。 </section></li> </ol> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;color: rgb(58, 58, 58);line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;">用传统的迭代处理也不是很难,但代码就显得冗余了,跟Stream相比高下立判。</p> <h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 4px;padding-top: 16px;padding-bottom: 10px;font-weight: bold;font-size: 2.1em;max-width: 100%;color: black;line-height: 1.1em;border-bottom: 1px solid rgb(201, 152, 51);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(81, 81, 81);box-sizing: border-box !important;overflow-wrap: break-word !important;">1 Stream概述</span></h1> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;color: rgb(58, 58, 58);line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;">Java 8 是一个非常成功的版本,这个版本新增的<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">Stream</code>,配合同版本出现的&nbsp;<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">Lambda</code>&nbsp;,给我们操作集合(Collection)提供了极大的便利。</p> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;color: rgb(58, 58, 58);line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;">那么什么是<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">Stream</code>?</p> <blockquote data-tool="mdnice编辑器" style="margin-top: 20px;margin-bottom: 20px;padding: 10px 10px 10px 20px;border-left-color: rgb(255, 177, 27);color: rgb(106, 115, 125);font-size: 0.9em;max-width: 100%;border-top: none;border-right: none;border-bottom: none;overflow: auto;background: rgb(255, 245, 227);box-sizing: border-box !important;overflow-wrap: break-word !important;"> <p style="max-width: 100%;min-height: 1em;font-size: 16px;line-height: 26px;color: rgb(89, 89, 89);box-sizing: border-box !important;overflow-wrap: break-word !important;"><code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">Stream</code>将要处理的元素集合看作一种流,在流的过程中,借助<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">Stream API</code>对流中的元素进行操作,比如:筛选、排序、聚合等。</p> </blockquote> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;color: rgb(58, 58, 58);line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">Stream</code>可以由数组或集合创建,对流的操作分为两种:</p> <ol data-tool="mdnice编辑器" class="list-paddingleft-2" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;max-width: 100%;color: black;overflow-wrap: break-word !important;"> <li style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="margin-top: 5px;margin-bottom: 5px;max-width: 100%;line-height: 26px;color: rgb(1, 1, 1);box-sizing: border-box !important;overflow-wrap: break-word !important;"> 中间操作,每次返回一个新的流,可以有多个。 </section></li> <li style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="margin-top: 5px;margin-bottom: 5px;max-width: 100%;line-height: 26px;color: rgb(1, 1, 1);box-sizing: border-box !important;overflow-wrap: break-word !important;"> 终端操作,每个流只能进行一次终端操作,终端操作结束后流无法再次使用。终端操作会产生一个新的集合或值。 </section></li> </ol> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;color: rgb(58, 58, 58);line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;">另外,<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">Stream</code>有几个特性:</p> <ol data-tool="mdnice编辑器" class="list-paddingleft-2" style="margin-top: 8px;margin-bottom: 8px;padding-left: 25px;max-width: 100%;color: black;overflow-wrap: break-word !important;"> <li style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="margin-top: 5px;margin-bottom: 5px;max-width: 100%;line-height: 26px;color: rgb(1, 1, 1);box-sizing: border-box !important;overflow-wrap: break-word !important;"> stream不存储数据,而是按照特定的规则对数据进行计算,一般会输出结果。 </section></li> <li style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="margin-top: 5px;margin-bottom: 5px;max-width: 100%;line-height: 26px;color: rgb(1, 1, 1);box-sizing: border-box !important;overflow-wrap: break-word !important;"> stream不会改变数据源,通常情况下会产生一个新的集合或一个值。 </section></li> <li style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="margin-top: 5px;margin-bottom: 5px;max-width: 100%;line-height: 26px;color: rgb(1, 1, 1);box-sizing: border-box !important;overflow-wrap: break-word !important;"> stream具有延迟执行特性,只有调用终端操作时,中间操作才会执行。 </section></li> </ol> <h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 4px;padding-top: 16px;padding-bottom: 10px;font-weight: bold;font-size: 2.1em;max-width: 100%;color: black;line-height: 1.1em;border-bottom: 1px solid rgb(201, 152, 51);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(81, 81, 81);box-sizing: border-box !important;overflow-wrap: break-word !important;">2 Stream的创建</span></h1> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;color: rgb(58, 58, 58);line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">Stream</code>可以通过集合数组创建。</p> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;color: rgb(58, 58, 58);line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;">1、通过&nbsp;<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">java.util.Collection.stream()</code>&nbsp;方法用集合创建流</p> <pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;max-width: 100%;color: black;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="margin-bottom: -7px;max-width: 100%;display: block;background: url(&quot;https://mmbiz.qpic.cn/mmbiz_png/6mychickmupXLicZLJ5jNBt48r9YH0erjfiaG2IagNwe4jaHB4EHp8iaIZWMxdvgprzr2k9rvf5wzNyS10x9svX0pQ/640?wx_fmt=png&quot;) 10px 10px / 40px no-repeat rgb(39, 40, 34);height: 30px;width: 657px;border-radius: 5px;box-sizing: border-box !important;overflow-wrap: break-word !important;"></span><code style="padding: 15px 16px 16px;max-width: 100%;overflow-x: auto;color: rgb(221, 221, 221);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background: rgb(39, 40, 34);border-radius: 5px;box-sizing: border-box !important;overflow-wrap: break-word !important;">List&lt;String&gt;&nbsp;list&nbsp;=&nbsp;Arrays.asList(<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"a"</span>,&nbsp;<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"b"</span>,&nbsp;<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"c"</span>);<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(117, 113, 94);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">//&nbsp;创建一个顺序流</span><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">Stream&lt;String&gt;&nbsp;stream&nbsp;=&nbsp;list.stream();<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(117, 113, 94);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">//&nbsp;创建一个并行流</span><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">Stream&lt;String&gt;&nbsp;parallelStream&nbsp;=&nbsp;list.parallelStream();<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">12345</span><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></code></pre> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;color: rgb(58, 58, 58);line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;">2、使用<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">java.util.Arrays.stream(T[] array)</code>方法用数组创建流</p> <pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;max-width: 100%;color: black;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="margin-bottom: -7px;max-width: 100%;display: block;background: url(&quot;https://mmbiz.qpic.cn/mmbiz_png/6mychickmupXLicZLJ5jNBt48r9YH0erjfiaG2IagNwe4jaHB4EHp8iaIZWMxdvgprzr2k9rvf5wzNyS10x9svX0pQ/640?wx_fmt=png&quot;) 10px 10px / 40px no-repeat rgb(39, 40, 34);height: 30px;width: 657px;border-radius: 5px;box-sizing: border-box !important;overflow-wrap: break-word !important;"></span><code style="padding: 15px 16px 16px;max-width: 100%;overflow-x: auto;color: rgb(221, 221, 221);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background: rgb(39, 40, 34);border-radius: 5px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(249, 38, 114);font-weight: bold;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">int</span>[]&nbsp;array={<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">1</span>,<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">3</span>,<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">5</span>,<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">6</span>,<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">8</span>};<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">IntStream&nbsp;stream&nbsp;=&nbsp;Arrays.stream(array);<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">12</span><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></code></pre> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;color: rgb(58, 58, 58);line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;">3、使用<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">Stream</code>的静态方法:<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">of()、iterate()、generate()</code></p> <pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;max-width: 100%;color: black;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="margin-bottom: -7px;max-width: 100%;display: block;background: url(&quot;https://mmbiz.qpic.cn/mmbiz_png/6mychickmupXLicZLJ5jNBt48r9YH0erjfiaG2IagNwe4jaHB4EHp8iaIZWMxdvgprzr2k9rvf5wzNyS10x9svX0pQ/640?wx_fmt=png&quot;) 10px 10px / 40px no-repeat rgb(39, 40, 34);height: 30px;width: 657px;border-radius: 5px;box-sizing: border-box !important;overflow-wrap: break-word !important;"></span><code style="padding: 15px 16px 16px;max-width: 100%;overflow-x: auto;color: rgb(221, 221, 221);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background: rgb(39, 40, 34);border-radius: 5px;box-sizing: border-box !important;overflow-wrap: break-word !important;">Stream&lt;Integer&gt;&nbsp;stream&nbsp;=&nbsp;Stream.of(<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">1</span>,&nbsp;<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">2</span>,&nbsp;<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">3</span>,&nbsp;<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">4</span>,&nbsp;<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">5</span>,&nbsp;<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">6</span>);<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">Stream&lt;Integer&gt;&nbsp;stream2&nbsp;=&nbsp;Stream.iterate(<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">0</span>,&nbsp;(x)&nbsp;-&gt;&nbsp;x&nbsp;+&nbsp;<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">3</span>).limit(<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">4</span>);<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">stream2.forEach(System.out::println);&nbsp;<span style="max-width: 100%;color: rgb(117, 113, 94);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">//&nbsp;0&nbsp;2&nbsp;4&nbsp;6&nbsp;8&nbsp;10</span><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">Stream&lt;Double&gt;&nbsp;stream3&nbsp;=&nbsp;Stream.generate(Math::random).limit(<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">3</span>);<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">stream3.forEach(System.out::println);<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">1234567</span><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></code></pre> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;color: rgb(58, 58, 58);line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;">输出结果:</p> <blockquote data-tool="mdnice编辑器" style="margin-top: 20px;margin-bottom: 20px;padding: 10px 10px 10px 20px;border-left-color: rgb(255, 177, 27);color: rgb(106, 115, 125);font-size: 0.9em;max-width: 100%;border-top: none;border-right: none;border-bottom: none;overflow: auto;background: rgb(255, 245, 227);box-sizing: border-box !important;overflow-wrap: break-word !important;"> <p style="max-width: 100%;min-height: 1em;font-size: 16px;line-height: 26px;color: rgb(89, 89, 89);box-sizing: border-box !important;overflow-wrap: break-word !important;">0 3 6 9 0.6796156909271994 0.1914314208854283 0.8116932592396652</p> </blockquote> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;color: rgb(58, 58, 58);line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;color: black;box-sizing: border-box !important;overflow-wrap: break-word !important;"><code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">stream</code>和<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">parallelStream</code>的简单区分:</strong>&nbsp;<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">stream</code>是顺序流,由主线程按顺序对流执行操作,而<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">parallelStream</code>是并行流,内部以多线程并行执行的方式对流进行操作,但前提是流中的数据处理没有顺序要求。例如筛选集合中的奇数,两者的处理不同之处:<img data-ratio="0.7913043478260869" data-type="png" data-w="690" src="/upload/ea454df4926ce04530af61cf6ec27332.png" style="margin-right: auto;margin-bottom: 15px;margin-left: auto;border-radius: 5px;display: block;width: 657px;box-sizing: border-box !important;overflow-wrap: break-word !important;visibility: visible !important;">如果流中的数据量足够大,并行流可以加快处理速度。</p> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;color: rgb(58, 58, 58);line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;">除了直接创建并行流,还可以通过<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">parallel()</code>把顺序流转换成并行流:</p> <pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;max-width: 100%;color: black;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="margin-bottom: -7px;max-width: 100%;display: block;background: url(&quot;https://mmbiz.qpic.cn/mmbiz_png/6mychickmupXLicZLJ5jNBt48r9YH0erjfiaG2IagNwe4jaHB4EHp8iaIZWMxdvgprzr2k9rvf5wzNyS10x9svX0pQ/640?wx_fmt=png&quot;) 10px 10px / 40px no-repeat rgb(39, 40, 34);height: 30px;width: 657px;border-radius: 5px;box-sizing: border-box !important;overflow-wrap: break-word !important;"></span><code style="padding: 15px 16px 16px;max-width: 100%;overflow-x: auto;color: rgb(221, 221, 221);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background: rgb(39, 40, 34);border-radius: 5px;box-sizing: border-box !important;overflow-wrap: break-word !important;">Optional&lt;Integer&gt;&nbsp;findFirst&nbsp;=&nbsp;list.stream().parallel().filter(x-&gt;x&gt;<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">6</span>).findFirst();<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">1</span><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></code></pre> <h1 data-tool="mdnice编辑器" style="margin-top: 30px;margin-bottom: 4px;padding-top: 16px;padding-bottom: 10px;font-weight: bold;font-size: 2.1em;max-width: 100%;color: black;line-height: 1.1em;border-bottom: 1px solid rgb(201, 152, 51);box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(81, 81, 81);box-sizing: border-box !important;overflow-wrap: break-word !important;">3 Stream的使用</span></h1> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;color: rgb(58, 58, 58);line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;">在使用stream之前,先理解一个概念:<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">Optional</code>&nbsp;。</p> <blockquote data-tool="mdnice编辑器" style="margin-top: 20px;margin-bottom: 20px;padding: 10px 10px 10px 20px;border-left-color: rgb(255, 177, 27);color: rgb(106, 115, 125);font-size: 0.9em;max-width: 100%;border-top: none;border-right: none;border-bottom: none;overflow: auto;background: rgb(255, 245, 227);box-sizing: border-box !important;overflow-wrap: break-word !important;"> <p style="max-width: 100%;min-height: 1em;font-size: 16px;line-height: 26px;color: rgb(89, 89, 89);box-sizing: border-box !important;overflow-wrap: break-word !important;"><code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">Optional</code>类是一个可以为<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">null</code>的容器对象。如果值存在则<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">isPresent()</code>方法会返回<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">true</code>,调用<code style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">get()</code>方法会返回该对象。更详细说明请见:菜鸟教程Java 8 Optional类</p> </blockquote> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;color: rgb(58, 58, 58);line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;color: black;box-sizing: border-box !important;overflow-wrap: break-word !important;">接下来,大批代码向你袭来!我将用20个案例将Stream的使用整得明明白白,只要跟着敲一遍代码,就能很好地掌握。</strong><img data-ratio="0.9501915708812261" data-type="png" data-w="261" src="/upload/e1d1b1f21a7d9cf66924d5754ae34efb.png" style="margin-right: auto;margin-bottom: 15px;margin-left: auto;border-radius: 5px;display: block;width: 657px;box-sizing: border-box !important;overflow-wrap: break-word !important;visibility: visible !important;"></p> <h2 data-tool="mdnice编辑器" style="margin-top: 2.2em;margin-bottom: 35px;font-weight: bold;font-size: 22px;max-width: 100%;color: black;line-height: 1.5em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="margin-right: 3px;padding: 2px 13px;max-width: 100%;display: inline-block;background-image: linear-gradient(rgb(255, 255, 255) 60%, rgb(255, 177, 27) 40%);background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;color: rgb(81, 81, 81);height: 37px;box-sizing: border-box !important;overflow-wrap: break-word !important;">案例使用的员工类</span></h2> <p data-tool="mdnice编辑器" style="margin-bottom: 20px;max-width: 100%;min-height: 1em;color: rgb(58, 58, 58);line-height: 1.8em;box-sizing: border-box !important;overflow-wrap: break-word !important;">这是后面案例中使用的员工类:</p> <pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;max-width: 100%;color: black;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="margin-bottom: -7px;max-width: 100%;display: block;background: url(&quot;https://mmbiz.qpic.cn/mmbiz_png/6mychickmupXLicZLJ5jNBt48r9YH0erjfiaG2IagNwe4jaHB4EHp8iaIZWMxdvgprzr2k9rvf5wzNyS10x9svX0pQ/640?wx_fmt=png&quot;) 10px 10px / 40px no-repeat rgb(39, 40, 34);height: 30px;width: 657px;border-radius: 5px;box-sizing: border-box !important;overflow-wrap: break-word !important;"></span><code style="padding: 15px 16px 16px;max-width: 100%;overflow-x: auto;color: rgb(221, 221, 221);display: -webkit-box;font-family: &quot;Operator Mono&quot;, Consolas, Monaco, Menlo, monospace;font-size: 12px;background: rgb(39, 40, 34);border-radius: 5px;box-sizing: border-box !important;overflow-wrap: break-word !important;">List&lt;Person&gt;&nbsp;personList&nbsp;=&nbsp;<span style="max-width: 100%;color: rgb(249, 38, 114);font-weight: bold;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">new</span>&nbsp;ArrayList&lt;Person&gt;();<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">personList.add(<span style="max-width: 100%;color: rgb(249, 38, 114);font-weight: bold;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">new</span>&nbsp;Person(<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"Tom"</span>,&nbsp;<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">8900</span>,&nbsp;<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"male"</span>,&nbsp;<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"New&nbsp;York"</span>));<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">personList.add(<span style="max-width: 100%;color: rgb(249, 38, 114);font-weight: bold;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">new</span>&nbsp;Person(<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"Jack"</span>,&nbsp;<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">7000</span>,&nbsp;<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"male"</span>,&nbsp;<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"Washington"</span>));<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">personList.add(<span style="max-width: 100%;color: rgb(249, 38, 114);font-weight: bold;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">new</span>&nbsp;Person(<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"Lily"</span>,&nbsp;<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">7800</span>,&nbsp;<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"female"</span>,&nbsp;<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"Washington"</span>));<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">personList.add(<span style="max-width: 100%;color: rgb(249, 38, 114);font-weight: bold;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">new</span>&nbsp;Person(<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"Anni"</span>,&nbsp;<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">8200</span>,&nbsp;<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"female"</span>,&nbsp;<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"New&nbsp;York"</span>));<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">personList.add(<span style="max-width: 100%;color: rgb(249, 38, 114);font-weight: bold;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">new</span>&nbsp;Person(<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"Owen"</span>,&nbsp;<span style="max-width: 100%;line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">9500</span>,&nbsp;<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"male"</span>,&nbsp;<span style="max-width: 100%;color: rgb(166, 226, 46);line-height: 26px;box-sizing: border-box !important;overflow-wrap: break-word !important;">"New&nbsp;York"</span>));<br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">personList.add(<span style="max-width: 100%;color: rgb(249, 38, 114);font-

Linux 运维必备的 40 个命令总结(波哥强推)

作者:微信小助手

<section powered-by="xiumi.us" style="margin-top: 30px;margin-bottom: 20px;max-width: 100%;box-sizing: border-box;white-space: normal;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;display: inline-block;width: 574px;vertical-align: top;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"> <section style="padding: 5px 10px;max-width: 100%;box-sizing: border-box;display: inline-block;width: 574px;vertical-align: top;border-width: 3px;border-radius: 20px;border-style: solid;border-color: rgb(226, 241, 246);overflow: hidden;background-color: rgb(226, 241, 246);overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;transform: translate3d(1px, 0px, 0px);overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;text-align: center;font-size: 14px;color: rgb(149, 187, 202);overflow-wrap: break-word !important;"> <p style="max-width: 100%;box-sizing: border-box;min-height: 1em;overflow-wrap: break-word !important;">&nbsp; &nbsp; &nbsp; &nbsp;文章来源&nbsp;51CTO博客</p> </section> </section> </section> </section> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"> <p style="max-width: 100%;box-sizing: border-box;min-height: 1em;overflow-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"></p> </section> </section> </section> <section powered-by="xiumi.us" style="margin-bottom: -15px;max-width: 100%;box-sizing: border-box;white-space: normal;text-align: left;transform: translate3d(20px, 0px, 0px);overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;display: inline-block;width: 55px;height: 40px;vertical-align: top;overflow: hidden;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;text-align: center;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;vertical-align: middle;display: inline-block;line-height: 0;overflow-wrap: break-word !important;"> <img data-ratio="0.696" data-w="500" data-type="gif" class="__bg_gif" src="/upload/a040d38d88cdcfaed38ea2886a5b9df0.png" style="box-sizing: border-box;vertical-align: middle;overflow-wrap: break-word !important;width: 500px !important;visibility: visible !important;"> </section> </section> </section> </section> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;white-space: normal;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);font-size: 16px;overflow-wrap: break-word !important;"> <p style="max-width: 100%;box-sizing: border-box;min-height: 1em;text-align: center;overflow-wrap: break-word !important;"><span style="max-width: 100%;box-sizing: border-box;text-shadow: rgb(195, 134, 234) 2px 0px 7px;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;">点击蓝字:波哥的IT人生,关注我们</strong></span></p> </section> </section> <section powered-by="xiumi.us" style="margin-bottom: 10px;max-width: 100%;box-sizing: border-box;white-space: normal;text-align: right;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;display: inline-block;vertical-align: middle;width: 229.594px;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;text-align: center;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;vertical-align: middle;display: inline-block;line-height: 0;width: 229.594px;overflow-wrap: break-word !important;"> <img data-ratio="0.2106667" data-w="750" width="100%" data-type="gif" class="__bg_gif" src="/upload/9a990984a6b8f7f7b3c167d0a48d8599.png" style="box-sizing: border-box;vertical-align: middle;overflow-wrap: break-word !important;width: 229.594px !important;visibility: visible !important;"> </section> </section> </section> <section style="max-width: 100%;box-sizing: border-box;display: inline-block;vertical-align: middle;width: 143.5px;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="margin-top: 0.5em;margin-bottom: 0.5em;max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;background-color: rgb(29, 29, 29);height: 1px;overflow-wrap: break-word !important;"> <br> </section> </section> </section> </section> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section data-tool="mdnice编辑器" data-website="https://www.mdnice.com"> <figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;max-width: 100%;display: flex;flex-direction: column;justify-content: center;align-items: center;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <span style="max-width: 100%;color: black;font-size: 15px;letter-spacing: 0.05em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="color: rgb(89, 89, 89);letter-spacing: 0.05em;background-color: rgb(255, 255, 255);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;"></span><br></span> </figure> <p style="max-width: 100%;min-height: 1em;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;margin-bottom: 1.2em !important;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">1、删除0字节文件</strong></span><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <pre style="max-width: 100%;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="bash"><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">find -type f -size 0 -exec rm -rf {} \;</span></code></pre> </section></pre> <section style="max-width: 100%;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;margin-bottom: 1.2em !important;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">2、查看进程</span></strong> </section> <section style="max-width: 100%;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;margin-bottom: 1.2em !important;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <span style="max-width: 100%;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">按内存从大到小排列</span> </section> <pre style="max-width: 100%;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="perl"><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">PS -e -o "%C : %p : %z : %a"|sort -k5 -nr</span></code></pre> </section></pre> <p style="max-width: 100%;min-height: 1em;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;margin-bottom: 1.2em !important;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">3、按 CPU 利用率从大到小排列</strong></span></p> <pre style="max-width: 100%;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="perl"><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">ps -e -o "%C : %p : %z : %a"|sort -nr</span></code></pre> </section></pre> <p style="max-width: 100%;min-height: 1em;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;margin-bottom: 1.2em !important;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">4、打印 cache 里的URL</strong></span></p> <pre style="max-width: 100%;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="nginx"><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">grep&nbsp;-r&nbsp;-a&nbsp;jpg&nbsp;/data/cache/*&nbsp;|&nbsp;strings&nbsp;|&nbsp;grep&nbsp;"http:"&nbsp;|&nbsp;awk&nbsp;-F'http:'&nbsp;'{print&nbsp;"http:"$2;}'</span></code></pre> </section></pre> <p style="max-width: 100%;min-height: 1em;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;margin-bottom: 1.2em !important;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">5、查看 http 的并发请求数及其 TCP 连接状态:</span></strong></p> <pre style="max-width: 100%;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="nginx"><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'</span></code></pre> </section></pre> <section style="max-width: 100%;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);line-height: 1.75em;text-align: left;margin-bottom: 1.2em !important;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <span style="max-width: 100%;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">6、<span>&nbsp;</span></span> <code style="margin-right: 0.15em;margin-left: 0.15em;padding-right: 0.3em;padding-left: 0.3em;max-width: 100%;font-size: 0.85em;font-family: Consolas, Inconsolata, Courier, monospace;white-space: pre-wrap;border-width: 1px;border-style: solid;border-color: rgb(234, 234, 234);background-color: rgb(248, 248, 248);border-radius: 3px;display: inline;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;">sed -i '/Root/s/no/yes/' /etc/ssh/sshd_config</span></code> <span style="max-width: 100%;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span>&nbsp;</span>sed 在这个文里 Root 的一行,匹配 Root 一行,将 no 替换成 yes。</span> </section> <p style="max-width: 100%;min-height: 1em;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;margin-bottom: 1.2em !important;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">7、如何杀掉 MySQL 进程</strong></span></p> <pre style="max-width: 100%;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="perl"><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">ps aux |grep mysql |grep -v grep |awk '{print $2}' |xargs kill -9 (从中了解到awk的用途)</span></code><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer"><br></span></code><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">killall -TERM mysqld</span></code><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer"><br></span></code><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">kill -9 `cat /usr/local/apache2/logs/httpd.pid` 试试查杀进程PID</span></code></pre> </section></pre> <p style="max-width: 100%;min-height: 1em;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;margin-bottom: 1.2em !important;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">8、显示运行 3 级别开启的服务:</strong></span></p> <pre style="max-width: 100%;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="nginx"><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">ls /etc/rc3.d/S* |cut -c 15- (从中了解到cut的用途,截取数据)</span></code></pre> </section></pre> <p style="max-width: 100%;min-height: 1em;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;margin-bottom: 1.2em !important;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">9、如何在编写 SHELL 显示多个信息,用 EOF</strong></span></p> <pre style="max-width: 100%;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="diff"><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">cat &lt;&lt; EOF</span></code><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">+--------------------------------------------------------------+</span></code><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">| === Welcome to Tunoff services === |</span></code><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">+--------------------------------------------------------------+</span></code><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">EOF</span></code></pre> </section></pre> <p style="max-width: 100%;min-height: 1em;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: left;margin-bottom: 1.2em !important;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">10、for 的巧用(如给 MySQL 建软链接)</strong></span></p> <pre style="max-width: 100%;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section class="code-snippet__fix code-snippet__js"> <ul class="code-snippet__line-index code-snippet__js"> </ul> <pre class="code-snippet__js" data-lang="bash"><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">cd /usr/local/mysql/bin</span></code><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">for i in *</span></code><code style=" white-space:pre-wrap;max-width: 1000%;text-align: left;display: flex; font-family: Consolas, &quot;Liberation Mono&quot;, Menlo, Courier, monospace;box-sizing: border-box !important;overflow-wrap: break-word !important; "><span class="code-snippet_outer" style="max-width: 1000%;box-sizing: border-box !important;overflow-wrap: break-word !important;">do ln /usr/local/mysql/bin/$i /usr/bin/$i</span></code><code style=" white-space:pre-wrap;max-width:

分布式锁用 Redis 还是 Zookeeper?

作者:微信小助手

<p data-mpa-powered-by="yiban.io" style="max-width: 100%;min-height: 1em;letter-spacing: 0.544px;white-space: normal;color: rgb(62, 71, 83);font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: center;background-color: rgb(255, 255, 255);font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-family: Optima-Regular, PingFangTC-light;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(127, 127, 127);font-size: 14px;line-height: 1.75em;box-sizing: border-box !important;overflow-wrap: break-word !important;">点击上方“</span><span style="max-width: 100%;font-size: 14px;line-height: 1.75em;color: rgb(0, 176, 240);box-sizing: border-box !important;overflow-wrap: break-word !important;">服务端思维</span><span style="max-width: 100%;color: rgb(127, 127, 127);font-size: 14px;line-height: 1.75em;box-sizing: border-box !important;overflow-wrap: break-word !important;">”,选择“</span></span><span style="max-width: 100%;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">设为星标</span><span style="max-width: 100%;color: rgb(127, 127, 127);letter-spacing: 0.544px;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">”</span></span></p> <p style="max-width: 100%;min-height: 1em;letter-spacing: 0.544px;white-space: normal;font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: center;background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-family: Optima-Regular, PingFangTC-light;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.544px;color: rgb(127, 127, 127);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">回复”</span><span style="max-width: 100%;letter-spacing: 0.544px;font-size: 14px;color: rgb(0, 122, 170);box-sizing: border-box !important;overflow-wrap: break-word !important;">669</span><span style="max-width: 100%;letter-spacing: 0.544px;color: rgb(127, 127, 127);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">“获取独家整理的精选资料集</span></span></p> <p style="max-width: 100%;min-height: 1em;letter-spacing: 0.544px;white-space: normal;font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: center;background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-family: Optima-Regular, PingFangTC-light;letter-spacing: 0.544px;color: rgb(127, 127, 127);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;">回复”</span><span style="max-width: 100%;letter-spacing: 0.544px;color: rgb(0, 122, 170);box-sizing: border-box !important;overflow-wrap: break-word !important;">加群</span><span style="max-width: 100%;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;">“加入全国服务端高端社群「后端圈」</span></span></p> <p style="text-align: center;"><img class="rich_pages js_insertlocalimg" data-backh="300" data-backw="533" data-ratio="0.5628517823639775" data-s="300,640" src="/upload/5220ced701fce99f5ade8a0d4e875c2e.jpg" data-type="jpeg" data-w="533" style="width: 100%;height: auto;"></p> <p style="margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><span style="font-size: 1.2em;font-weight: 600;">1</span><span style="font-size: 1.2em;font-weight: 600;">&nbsp;</span><span style="font-size: 1.2em;font-weight: 600;">为什么要</span><span style="font-size: 1.2em;font-weight: 600;">拆</span><span style="font-size: 1.2em;font-weight: 600;">分</span><span style="font-size: 1.2em;font-weight: 600;">?</span><br></p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">先看一段对话。</p> <figure data-size="normal" style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"> <img data-ratio="0.4986111111111111" src="/upload/9e7c2b1d4a51dcfe9bb0c24e71c1118d.jpg" data-type="jpeg" data-w="720" style="display: block;margin-right: auto;margin-left: auto;cursor: zoom-in;background-color: transparent;animation: 0.5s ease-in 0s 1 normal none running fxRichTextFadeIn;" width="1080"> </figure> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">从上面对话可以看出拆分的理由:</p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">1)&nbsp;<span style="font-weight: 600;">应用间耦合严重</span>。系统内各个应用之间不通,同样一个功能在各个应用中都有实现,后果就是改一处功能,需要同时改系统中的所有应用。这种情况多存在于历史较长的系统,因各种原因,系统内的各个应用都形成了自己的业务小闭环;</p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">2)&nbsp;<span style="font-weight: 600;">业务扩展性差</span>。数据模型从设计之初就只支持某一类的业务,来了新类型的业务后又得重新写代码实现,结果就是项目延期,大大影响业务的接入速度;</p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">3)&nbsp;<span style="font-weight: 600;">代码老旧,难以维护</span>。各种随意的if else、写死逻辑散落在应用的各个角落,处处是坑,开发维护起来战战兢兢;</p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">4)&nbsp;<span style="font-weight: 600;">系统扩展性差</span>。系统支撑现有业务已是颤颤巍巍,不论是应用还是DB都已经无法承受业务快速发展带来的压力;</p> <figure data-size="normal" style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"> <br> </figure> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">5)&nbsp;<span style="font-weight: 600;">新坑越挖越多,恶性循环</span>。不改变的话,最终的结果就是把系统做死了。</p> <h2 style="margin-top: 2.33333em;margin-bottom: 1.16667em;font-variant-numeric: inherit;font-weight: 600;font-stretch: inherit;font-size: 1.2em;line-height: 1.5;font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;clear: left;color: rgb(18, 18, 18);text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">2&nbsp;拆前准备什么?</h2> <h2 style="margin-top: 2.33333em;margin-bottom: 1.16667em;font-variant-numeric: inherit;font-weight: 600;font-stretch: inherit;font-size: 1.2em;line-height: 1.5;font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;clear: left;color: rgb(18, 18, 18);text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">2.1 多维度把握业务复杂度</h2> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">一个老生常谈的问题,系统与业务的关系?</p> <figure data-size="normal" style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"> <img data-ratio="0.5069444444444444" src="/upload/52d11fc8581e0bce8dfaff0015920c0.jpg" data-type="jpeg" data-w="720" style="display: block;margin-right: auto;margin-left: auto;cursor: zoom-in;background-color: transparent;animation: 0.5s ease-in 0s 1 normal none running fxRichTextFadeIn;" width="1080"> </figure> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">我们最期望的理想情况是第一种关系(车辆与人),业务觉得不合适,可以马上换一辆新的。但现实的情况是更像心脏起搏器与人之间的关系,不是说换就能换。一个系统接的业务越多,耦合越紧密。如果在没有真正把握住业务复杂度之前贸然行动,最终的结局就是把心脏带飞。</p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">如何把握住业务复杂度?需要多维度的思考、实践。一个是技术层面,通过与pd以及开发的讨论,熟悉现有各个应用的领域模型,以及优缺点,这种讨论只能让人有个大概,更多的细节如代码、架构等需要通过做需求、改造、优化这些实践来掌握。</p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">各个应用熟悉之后,需要从系统层面来构思,我们想打造平台型的产品,那么最重要也是最难的一点就是功能集中管控,打破各个应用的业务小闭环,统一收拢,这个决心更多的是开发、产品、业务方、各个团队之间达成的共识,可以参考《微服务(Microservice)那点事》一文,“按照业务或者客户需求组织资源”。</p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">此外也要与业务方保持功能沟通、计划沟通,确保应用拆分出来后符合使用需求、扩展需求,获取他们的支持。</p> <h2 style="margin-top: 2.33333em;margin-bottom: 1.16667em;font-variant-numeric: inherit;font-weight: 600;font-stretch: inherit;font-size: 1.2em;line-height: 1.5;font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;clear: left;color: rgb(18, 18, 18);text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">2.2 定义边界,原则:高内聚,低耦合,单一职责!</h2> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">业务复杂度把握后,需要开始定义各个应用的服务边界。怎么才算是好的边界?像葫芦娃兄弟一样的应用就是好的!</p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">举个例子,葫芦娃兄弟(应用)间的技能是相互独立的,遵循单一职责原则,比如水娃只能喷水,火娃只会喷火,隐形娃不会喷水喷火但能隐身。</p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">更为关键的是,葫芦娃兄弟最终可以合体为金刚葫芦娃,即这些应用虽然功能彼此独立,但又相互打通,最后合体在一起就成了我们的平台。</p> <figure data-size="normal" style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"> <img data-ratio="0.3597222222222222" src="/upload/acf22f3ddfb6de73839c2030947cad02.jpg" data-type="jpeg" data-w="720" style="display: block;margin-right: auto;margin-left: auto;cursor: zoom-in;background-color: transparent;animation: 0.5s ease-in 0s 1 normal none running fxRichTextFadeIn;" width="1080"> </figure> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">这里很多人会有疑惑,拆分粒度怎么控制?很难有一个明确的结论,只能说是结合业务场景、目标、进度的一个折中。但总体的原则是先从一个大的服务边界开始,不要太细,因为随着架构、业务的演进,应用自然而然会再次拆分,让正确的事情自然发生才最合理。</p> <h2 style="margin-top: 2.33333em;margin-bottom: 1.16667em;font-variant-numeric: inherit;font-weight: 600;font-stretch: inherit;font-size: 1.2em;line-height: 1.5;font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;clear: left;color: rgb(18, 18, 18);text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">2.3 确定拆分后的应用目标</h2> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">一旦系统的宏观应用拆分图出来后,就要落实到某一具体的应用拆分上了。首先要确定的就是某一应用拆分后的目标。拆分优化是没有底的,可能越做越深,越做越没结果,继而又影响自己和团队的士气。比如说可以定这期的目标就是将db、应用分拆出去,数据模型的重新设计可以在第二期。</p> <h2 style="margin-top: 2.33333em;margin-bottom: 1.16667em;font-variant-numeric: inherit;font-weight: 600;font-stretch: inherit;font-size: 1.2em;line-height: 1.5;font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;clear: left;color: rgb(18, 18, 18);text-align: start;white-space: normal;backgro

spring-cloud-alibaba版本与spring-cloud版本对应关系

作者:じ☆ve不哭

> spring-cloud的版本与springcloud-alibaba版本对应关系怎么选择?选择错版本可能会出现注册中心nacos无法展现服务。 ![1606983827(1).png](/storage/thumbnails/_signature/3SEJLDS9M92BADAD595L1NGEGT.png) ## 参考资料 [官方地址:https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E](https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E)

使用IntelliJ IDEA查看类图,内容极度舒适

作者:微信小助手

<p data-mpa-powered-by="yiban.io" style="max-width: 100%;min-height: 1em;letter-spacing: 0.544px;white-space: normal;color: rgb(62, 71, 83);font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: center;background-color: rgb(255, 255, 255);font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-family: Optima-Regular, PingFangTC-light;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 16px;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;color: rgb(127, 127, 127);font-size: 14px;line-height: 1.75em;box-sizing: border-box !important;overflow-wrap: break-word !important;">点击上方“</span><span style="max-width: 100%;font-size: 14px;line-height: 1.75em;color: rgb(0, 176, 240);box-sizing: border-box !important;overflow-wrap: break-word !important;">服务端思维</span><span style="max-width: 100%;color: rgb(127, 127, 127);font-size: 14px;line-height: 1.75em;box-sizing: border-box !important;overflow-wrap: break-word !important;">”,选择“</span></span><span style="max-width: 100%;color: rgb(136, 136, 136);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">设为星标</span><span style="max-width: 100%;color: rgb(127, 127, 127);letter-spacing: 0.544px;font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">”</span></span></p> <p style="max-width: 100%;min-height: 1em;letter-spacing: 0.544px;white-space: normal;font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: center;background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-family: Optima-Regular, PingFangTC-light;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.544px;color: rgb(127, 127, 127);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">回复”</span><span style="max-width: 100%;letter-spacing: 0.544px;font-size: 14px;color: rgb(0, 122, 170);box-sizing: border-box !important;overflow-wrap: break-word !important;">669</span><span style="max-width: 100%;letter-spacing: 0.544px;color: rgb(127, 127, 127);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;">“获取独家整理的精选资料集</span></span></p> <p style="max-width: 100%;min-height: 1em;letter-spacing: 0.544px;white-space: normal;font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;text-align: center;background-color: rgb(255, 255, 255);color: rgb(62, 62, 62);font-size: 15px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-family: Optima-Regular, PingFangTC-light;letter-spacing: 0.544px;color: rgb(127, 127, 127);font-size: 14px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;">回复”</span><span style="max-width: 100%;letter-spacing: 0.544px;color: rgb(0, 122, 170);box-sizing: border-box !important;overflow-wrap: break-word !important;">加群</span><span style="max-width: 100%;letter-spacing: 0.544px;box-sizing: border-box !important;overflow-wrap: break-word !important;">“加入全国服务端高端社群「后端圈」</span></span></p> <p style="text-align: center;"><img class="rich_pages js_insertlocalimg" data-backh="313" data-backw="500" data-ratio="0.626" data-s="300,640" src="/upload/a2e796c61b0fc609556ce31ab205b853.jpg" data-type="jpeg" data-w="500" style="width: 100%;height: auto;"></p> <p style="margin-top: 1.4em;margin-bottom: 1.4em;color: rgb(18, 18, 18);font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif;font-size: medium;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);"><span style="color: rgb(51, 51, 51);font-family: mp-quote, -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;font-size: 17px;text-align: justify;">这次利用了IDEA的diagram,结果一目了然,也是好用到炸裂,就此分享。</span><br></p> <h2 style="margin-top: 10px;margin-bottom: 10px;font-size: 21px;font-weight: bold;line-height: 1.5;color: rgb(0, 0, 0);font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);">1、查看图形形式的继承链</h2> <p>在你想查看的类的标签页内,点击<span data-wiz-span="data-wiz-span" style="color: rgb(255, 0, 0);">右键,选择 Diagrams</span>,其中有 show 和 show ... Popup,只是前者新建在标签页内,后者以浮窗的形式展示:</p> <p><img border="0" data-ratio="0.6108986615678776" src="/upload/9ee81f195efe96a7f96068972ef89b8a.png" data-type="png" data-w="1046" height="578" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 820px;" width="946"></p> <p>&nbsp;</p> <p>实际上,你也可以从左边的项目目录树中,对你想查看的类点击右键,同样选择Diagrams,效果是一样的:</p> <p><img border="0" data-ratio="0.625" src="/upload/fef567018ef0d6f04bc92df3056fee16.png" data-type="png" data-w="1440" height="597" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 820px;" width="956"></p> <p>&nbsp;</p> <p>然后你就会得到如下图所示的继承关系图形,以自定义的Servlet为例:</p> <p><img border="0" data-ratio="0.6329365079365079" src="/upload/e904e8a2dabe93d84d6aefa250ec8c56.png" data-type="png" data-w="504" height="426" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 820px;" width="676"></p> <p>显而易见的是:</p> <ul style="margin-left: 30px;word-break: break-all;" class="list-paddingleft-2"> <li style="margin-bottom: 1em;list-style: disc;"><p><span data-wiz-span="data-wiz-span" style="color: rgb(51, 102, 255);"><strong>蓝色实线箭头</strong></span>是指继承关系</p></li> <li style="margin-bottom: 1em;list-style: disc;"><p><span data-wiz-span="data-wiz-span" style="color: rgb(0, 147, 0);"><strong>绿色虚线箭头</strong></span>是指接口实现关系</p></li> </ul> <p><br></p> <h2 style="margin-top: 10px;margin-bottom: 10px;font-size: 21px;font-weight: bold;line-height: 1.5;">2、优化继承链图形,想我所想</h2> <h2 style="margin-top: 10px;margin-bottom: 10px;font-size: 21px;font-weight: bold;line-height: 1.5;color: rgb(0, 0, 0);font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);">2.1 去掉不关心的类</h2> <p>得到的继承关系图形,有些并不是我们想去了解的,比如上图的Object和Serializable,我们只想关心Servlet重要的那几个继承关系,怎么办?</p> <p>简单,删掉。<span data-wiz-span="data-wiz-span" style="color: rgb(255, 0, 0);">点击选择你想要删除的类,然后直接使用键盘上的delete键</span>就行了。清理其他类的关系后图形如下:</p> <p><img border="0" data-ratio="1.2272727272727273" src="/upload/f6ac100b53f3e381a8cb9b4e56a8b580.png" data-type="png" data-w="264" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 820px;"></p> <p>&nbsp;</p> <h2 style="margin-top: 10px;margin-bottom: 10px;font-size: 21px;font-weight: bold;line-height: 1.5;color: rgb(0, 0, 0);font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);">2.2 展示类的详细信息</h2> <p>有人说,诶,这怎么够呢,那继承下来的那些方法我也想看啊?简单,IDEA通通满足你。</p> <p>在<span data-wiz-span="data-wiz-span" style="color: rgb(255, 0, 0);">页面点击右键,选择 show categories</span>,根据需要可以展开类中的属性、方法、构造方法等等。当然,第二种方法<span data-wiz-span="data-wiz-span" style="color: rgb(255, 0, 0);">也可以直接使用上面的工具栏</span>:</p> <p><img border="0" data-ratio="0.7119301648884578" src="/upload/6ca621c408e2d5f485aa795f6971dfcc.png" data-type="png" data-w="1031" height="686" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 820px;color: rgb(0, 0, 0);font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;font-size: 14px;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);" width="964"></p> <p>&nbsp;</p> <p>然后你就会得到:</p> <p><img border="0" data-ratio="1.4685990338164252" src="/upload/26115bc82604b90d39d8a7f8aa1a8e92.png" data-type="png" data-w="414" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 820px;color: rgb(0, 0, 0);font-family: &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;font-size: 14px;text-align: left;white-space: normal;background-color: rgb(255, 255, 255);"></p> <p>什么,方法里你还想筛选,比如说想看protected权限及以上范围的?简单,<span data-wiz-span="data-wiz-span" style="color: rgb(255, 0, 0);">右键选择 Change Visibility Level</span>,根据需要调整即可。</p> <p><img border="0" data-ratio="0.848" src="/upload/53a257f2b78020ea9888a62c335b7844.png" data-type="png" data-w="750" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 820px;"></p> <p>&nbsp;</p> <p>什么,你嫌图形太小你看不清楚?IDEA也可以满足你,<span data-wiz-span="data-wiz-span" style="color: rgb(255, 0, 0);">按住键盘的Alt,竟然出现了放大镜</span>,惊不惊喜,意不意外?<br><img border="0" data-ratio="0.8133669609079445" src="/upload/de68df11c6473a8d8470d3029e5b49bb.png" data-type="png" data-w="793" height="535" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 820px;" width="658"></p> <p>&nbsp;</p> <h2 style="margin-top: 10px;margin-bottom: 10px;font-size: 21px;font-weight: bold;line-height: 1.5;">2.3 加入其他类到关系中来</h2> <p>当我们还需要查看其他类和当前类是否有继承上的关系的时候,我们可以选择加其加入到当前的继承关系图形中来。</p> <p>在<span data-wiz-span="data-wiz-span" style="color: rgb(255, 0, 0);">页面点击右键,选择 Add Class to Diagram</span>,然后输入你想加入的类就可以了:</p> <p><img border="0" data-ratio="0.7169811320754716" src="/upload/4b3ae052aaaed16263809e04c0169932.png" data-type="png" data-w="1060" height="695" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 820px;" width="970"></p> <p>&nbsp;</p> <p>例如我们添加了一个Student类,如下图所示。好吧,并没有任何箭头,看来它和当前这几个类以及接口并没有发生什么不可描述的关系:</p> <p><img border="0" data-ratio="1.1618887015177066" src="/upload/3e39b1d6c860e387e2da54ba77cde62f.png" data-type="png" data-w="593" height="840" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 820px;" width="723"></p> <p>&nbsp;</p> <h2 style="margin-top: 10px;margin-bottom: 10px;font-size: 21px;font-weight: bold;line-height: 1.5;">2.4 查看具体代码</h2> <p>如果你想查看某个类中,比如某个方法的具体源码,当然,不可能给你展现在图形上了,不然屏幕还不得撑炸?</p> <p>但是可以利用图形,或者配合IDEA的structure方便快捷地进入某个类的源码进行查看。</p> <p><span data-wiz-span="data-wiz-span" style="color: rgb(255, 0, 0);">双击某个类后,你就可以在其下的方法列表中游走,对于你想查看的方法,选中后点击右键,选择 Jump to Source</span>:</p> <p><img border="0" data-ratio="0.7435897435897436" src="/upload/91952c1c7d16591a0f994e9075c3427d.png" data-type="png" data-w="858" height="558" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 820px;" width="752"></p> <p><img border="0" data-ratio="0.7117031398667936" src="/upload/9c765d2a435456c1da72aca6030464c1.png" data-type="png" data-w="1051" height="650" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 820px;" width="914"></p> <p>在进入某个类后,如果还想快速地查看该类的其他方法,还可以利用IDEA提供的structure功能:</p> <p><img border="0" data-ratio="0.5972222222222222" src="/upload/32c0607bd40fd08934f357e55c820fe2.png" data-type="png" data-w="1440" height="581" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 820px;" width="973"></p> <p><span data-wiz-span="data-wiz-span" style="color: rgb(255, 0, 0);">选择左侧栏的structure之后,如上图左侧会展示该类中的所有方法,点击哪个方法,页面内容就会跳转到该方法部分去</span>。</p> <h2 style="margin-top: 10px;margin-bottom: 10px;font-size: 21px;font-weight: bold;line-height: 1.5;">3、最后</h2> <p>用上面提到的的IDEA这些功能,学习和查看类关系,了解诸如主流框架源码之类的东西,可以说是非常舒服了。&nbsp;</p> <p><br></p> <h2 style="margin-top: 10px;margin-bottom: 10px;font-size: 21px;font-weight: bold;line-height: 1.5;">4、参考链接</h2> <p>IntelliJ IDEA 中如何查看一个类的所有继承关系(当前类的所有继承关系图)</p> <p>https://blog.csdn.net/qq_27093465/article/details/52857307</p> <p style="max-width: 100%;min-height: 1em;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);text-align: center;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;color: rgb(77, 168, 238);font-family: -apple-system-font, BlinkMacSystemFont, Arial, sans-serif;letter-spacing: 1.5px;font-size: 16px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 12px;letter-spacing: 1px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;font-size: 17px;letter-spacing: 0.544px;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 12px;box-sizing: border-box !important;overflow-wrap: break-word !important;">— 本文结束 —</span></strong></span></strong><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <section powered-by="xiumi.us" style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);font-size: 16px;text-align: center;color: rgb(62, 71, 83);font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <p style="margin-right: 16px;margin-left: 16px;max-width: 100%;min-height: 1em;letter-spacing: 1.5px;line-height: 1.5em;font-family: -apple-system-font, BlinkMacSystemFont, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <section data-mpa-template="t" mpa-from-tpl="t" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section data-id="93709" mpa-from-tpl="t" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section mpa-from-tpl="t" style="padding: 5px;max-width: 100%;border-style: solid;border-width: 2px;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section mpa-from-tpl="t" style="padding: 15px;max-width: 100%;border-style: dashed;border-width: 1px;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section mpa-from-tpl="t" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <span data-role="width" data-width="80%" style="max-width: 100%;display: inline-block;width: 425.215px;box-sizing: border-box !important;overflow-wrap: break-word !important;"><img border="0" class="__bg_gif" data-ratio="0.08658008658008658" data-type="gif" data-w="462" data-width="80%" height="" title="" width="80%" src="/upload/b0b0d65a8077fe5fc54ccd945913d458.png" style="box-sizing: border-box !important;overflow-wrap: break-word !important;visibility: visible !important;width: 340.156px !important;"></span> </section> <p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;text-align: justify;letter-spacing: 1.5px;line-height: normal;color: rgb(136, 136, 136);font-size: 13px;box-sizing: border-box !important;overflow-wrap: break-word !important;">●&nbsp;<a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzA5NDg3MjAwMQ==&amp;mid=2457103446&amp;idx=1&amp;sn=0d0c0cb83235675963be01cb7b8ddb7b&amp;chksm=87c8c4f8b0bf4dee91ab4a8041363afc0839df2dbc219e2c0938ed2e53d13af4a966121314f4&amp;scene=21#wechat_redirect" textvalue="漫谈设计模式在 Spring 框架中的良好实践" data-itemshowtype="0" tab="innerlink" data-linktype="2" hasload="1" style="color: var(--weui-LINK);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">漫谈设计模式在 Spring 框架中的良好实践</a></p> <p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;text-align: justify;letter-spacing: 1.5px;line-height: normal;color: rgb(136, 136, 136);font-size: 13px;box-sizing: border-box !important;overflow-wrap: break-word !important;">●&nbsp;<a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzA5NDg3MjAwMQ==&amp;mid=2457103280&amp;idx=1&amp;sn=f3bd921a2f88a9a3440c0ff1e03d1bd9&amp;chksm=87c8c31eb0bf4a0820a572626141cfb1fc87ea1c7072a16f61992d67d21d9b61b556de2d6cd7&amp;scene=21#wechat_redirect" textvalue="颠覆微服务认知:深入思考微服务的七个主流观点" data-itemshowtype="11" tab="innerlink" data-linktype="2" hasload="1" style="color: var(--weui-LINK);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">颠覆微服务认知:</a><a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzA5NDg3MjAwMQ==&amp;mid=2457103280&amp;idx=1&amp;sn=f3bd921a2f88a9a3440c0ff1e03d1bd9&amp;chksm=87c8c31eb0bf4a0820a572626141cfb1fc87ea1c7072a16f61992d67d21d9b61b556de2d6cd7&amp;scene=21#wechat_redirect" textvalue="颠覆微服务认知:深入思考微服务的七个主流观点" data-itemshowtype="11" tab="innerlink" data-linktype="2" hasload="1" style="color: var(--weui-LINK);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">深入思考微服务的七个主流观点</a><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;text-align: justify;letter-spacing: 1.5px;line-height: normal;color: rgb(136, 136, 136);font-size: 13px;box-sizing: border-box !important;overflow-wrap: break-word !important;">●&nbsp;<a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzA5NDg3MjAwMQ==&amp;mid=2457103129&amp;idx=1&amp;sn=3e0386d5f6f3b706e6bd72195648e34e&amp;chksm=87c8c3b7b0bf4aa1530354a3b1507b33c5033db70e4c61328e9ed68118e24212a36d763671d8&amp;scene=21#wechat_redirect" textvalue="人人都是 API 设计者" data-itemshowtype="0" tab="innerlink" data-linktype="2" hasload="1" style="color: var(--weui-LINK);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">人人都是 API 设计者</a></p> <p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;text-align: justify;letter-spacing: 1.5px;line-height: normal;color: rgb(136, 136, 136);font-size: 13px;box-sizing: border-box !important;overflow-wrap: break-word !important;">●&nbsp;<a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzA5NDg3MjAwMQ==&amp;mid=2457103538&amp;idx=1&amp;sn=9261bb2b742fd41168889738e0377a9c&amp;chksm=87c8c41cb0bf4d0a5401fac49320faebfc4ac5ad7711d39758ecb0fd9df43354d19aa5aa57e3&amp;scene=21#wechat_redirect" textvalue="一文讲透微服务下如何保证事务的一致性" data-itemshowtype="0" tab="innerlink" data-linktype="2" hasload="1" style="color: var(--weui-LINK);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">一文讲透微服务下如何保证事务的一致性</a><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <p style="margin-top: 5px;margin-bottom: 5px;padding-right: 0em;padding-left: 0em;max-width: 100%;min-height: 1em;text-align: justify;letter-spacing: 1.5px;line-height: normal;color: rgb(136, 136, 136);font-size: 13px;box-sizing: border-box !important;overflow-wrap: break-word !important;">●&nbsp;<a target="_blank" href="http://mp.weixin.qq.com/s?__biz=MzA5NDg3MjAwMQ==&amp;mid=2457103584&amp;idx=1&amp;sn=007226d602709eb3c840a0539dae678b&amp;chksm=87c8c44eb0bf4d58e9aaba3221c0d9f61556f4a199691b428dd322231ab450023e748cfc620a&amp;scene=21#wechat_redirect" textvalue="要黑盒测试微服务内部服务间调用,我该如何实现?" data-itemshowtype="0" tab="innerlink" data-linktype="2" hasload="1" style="color: var(--weui-LINK);-webkit-tap-highlight-color: rgba(0, 0, 0, 0);cursor: pointer;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;">要黑盒测试微服务内部服务间调用,我该如何实现?</a><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> </section> </section> </section> </section> <p style="max-width: 100%;min-height: 1em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br mpa-from-tpl="t" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> </section> </section> </section> </section> </section> </section> <section powered-by="xiumi.us" style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);font-size: 16px;text-align: center;color: rgb(62, 71, 83);font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <p style="max-width: 100%;min-height: 1em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><img data-ratio="0.3708738" data-type="png" data-w="515" src="/upload/328ca60e65e37255ffc9d00bfba58c3c.png" style="vertical-align: middle;box-sizing: border-box !important;overflow-wrap: break-word !important;visibility: visible !important;width: 515px !important;"></p> <p style="margin-right: 16px;margin-left: 16px;max-width: 100%;min-height: 1em;letter-spacing: 1.5px;line-height: 1.5em;font-family: -apple-system-font, BlinkMacSystemFont, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="margin-top: 10px;margin-bottom: 10px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;display: inline-block;width: 574px;vertical-align: top;border-style: solid;border-width: 1px;border-radius: 0px;border-color: rgb(225, 238, 226);background-color: rgba(191, 224, 216, 0.58);box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="padding: 10px;max-width: 100%;display: inline-block;width: 572px;vertical-align: top;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;font-size: 15px;color: rgb(46, 101, 91);line-height: 1.8;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <p style="max-width: 100%;min-height: 1em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 12px;box-sizing: border-box !important;overflow-wrap: break-word !important;">关注我,回复 「加群」 加入各种主题讨论群。</span></p> </section> </section> </section> </section> </section> <section powered-by="xiumi.us" style="margin-top: 10px;max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;background-color: rgb(147, 195, 186);height: 2px;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> </section> </section> </section> </section> </section> </section> </section> </section> </section> <section powered-by="xiumi.us" style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);font-size: 16px;text-align: center;color: rgb(62, 71, 83);font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <p style="max-width: 100%;min-height: 1em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <p style="margin-right: 16px;margin-left: 16px;max-width: 100%;min-height: 1em;letter-spacing: 1.5px;line-height: 1.5em;font-family: -apple-system-font, BlinkMacSystemFont, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 12px;letter-spacing: 1px;color: rgb(0, 0, 0);box-sizing: border-box !important;overflow-wrap: break-word !important;">对「服务端思维」有期待,请在文末点个<span style="max-width: 100%;color: rgb(198, 19, 25);box-sizing: border-box !important;overflow-wrap: break-word !important;">在看</span></span></strong></p> <p style="margin-right: 16px;margin-left: 16px;max-width: 100%;min-height: 1em;letter-spacing: 1.5px;line-height: 1.5em;font-family: -apple-system-font, BlinkMacSystemFont, Arial, sans-serif;box-sizing: border-box !important;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="max-width: 100%;font-size: 12px;letter-spacing: 1px;color: rgb(0, 0, 0);box-sizing: border-box !important;overflow-wrap: break-word !important;">喜欢这篇文章,欢迎<span style="max-width: 100%;color: rgb(198, 19, 25);box-sizing: border-box !important;overflow-wrap: break-word !important;">转发、分享</span>朋友圈</span></strong></p> </section> </section> </section> <p style="max-width: 100%;min-height: 1em;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);color: rgb(63, 63, 63);font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif;font-size: 14px;text-align: center;box-sizing: border-box !important;overflow-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"></p> <section data-role="outer" label="Powered by 135editor.com" style="max-width: 100%;letter-spacing: 0.544px;white-space: normal;background-color: rgb(255, 255, 255);font-size: 16px;color: rgb(63, 63, 63);font-family: Avenir, -apple-system-font, 微软雅黑, sans-serif;text-align: center;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section data-role="outer" label="Powered by 135editor.com" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section data-tools="135编辑器" data-id="94783" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;display: flex;justify-content: flex-end;align-items: center;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;width: 20px;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section style="max-width: 100%;width: 20px;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <img data-ratio="1.037037037037037" data-type="png" data-w="27" data-width="100%" src="/upload/6087772642bee9a4b8104517c36c9aa7.png" style="display: block;box-sizing: border-box !important;overflow-wrap: break-word !important;visibility: visible !important;width: 20px !important;"> </section> </section> <section style="max-width: 100%;display: inline-block;text-align: right;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section data-brushtype="text" style="margin-bottom: -15px;max-width: 100%;letter-spacing: 2px;transform: rotate(0deg);color: rgb(0, 0, 0);box-sizing: border-box !important;overflow-wrap: break-word !important;"> 在看点这里 </section> </section> <section style="max-width: 100%;width: 22px;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <img class="__bg_gif" data-ratio="1" data-type="gif" data-w="100" data-width="100%" src="/upload/8b34c0e8ddcf33f56770ae9f44c95ce1.png" style="letter-spacing: 0.544px;display: block;box-sizing: border-box !important;overflow-wrap: break-word !important;visibility: visible !important;width: 22px !important;"> </section> </section> </section> </section> </section>

【系统架构】如何升级到https?一个脚本帮你搞定且永久免费

作者:微信小助手

<section powered-by="xiumi.us" style="margin-top: 30px;margin-bottom: 20px;max-width: 100%;box-sizing: border-box;white-space: normal;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;display: inline-block;width: 574px;vertical-align: top;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"> <section style="padding: 5px 10px;max-width: 100%;box-sizing: border-box;display: inline-block;width: 574px;vertical-align: top;border-width: 3px;border-radius: 20px;border-style: solid;border-color: rgb(226, 241, 246);overflow: hidden;background-color: rgb(226, 241, 246);overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;transform: translate3d(1px, 0px, 0px);overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;text-align: center;font-size: 14px;color: rgb(149, 187, 202);overflow-wrap: break-word !important;"> <p style="max-width: 100%;box-sizing: border-box;min-height: 1em;overflow-wrap: break-word !important;">&nbsp; &nbsp; &nbsp; &nbsp;文章来源&nbsp; 今日头条</p> </section> </section> </section> </section> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"> <p style="max-width: 100%;box-sizing: border-box;min-height: 1em;overflow-wrap: break-word !important;"><br style="max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"></p> </section> </section> </section> <section powered-by="xiumi.us" style="margin-bottom: -15px;max-width: 100%;box-sizing: border-box;white-space: normal;text-align: left;transform: translate3d(20px, 0px, 0px);overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;display: inline-block;width: 55px;height: 40px;vertical-align: top;overflow: hidden;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;text-align: center;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;vertical-align: middle;display: inline-block;line-height: 0;overflow-wrap: break-word !important;"> <img data-ratio="0.696" data-w="500" data-type="gif" class="__bg_gif" src="/upload/a040d38d88cdcfaed38ea2886a5b9df0.png" style="box-sizing: border-box;vertical-align: middle;overflow-wrap: break-word !important;width: 500px !important;visibility: visible !important;"> </section> </section> </section> </section> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;white-space: normal;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;letter-spacing: 0.544px;background-color: rgb(255, 255, 255);font-size: 16px;overflow-wrap: break-word !important;"> <p style="max-width: 100%;box-sizing: border-box;min-height: 1em;text-align: center;overflow-wrap: break-word !important;"><span style="max-width: 100%;box-sizing: border-box;text-shadow: rgb(195, 134, 234) 2px 0px 7px;overflow-wrap: break-word !important;"><strong style="max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;">点击蓝字:波哥的IT人生,关注我们</strong></span></p> </section> </section> <section powered-by="xiumi.us" style="margin-bottom: 10px;max-width: 100%;box-sizing: border-box;white-space: normal;text-align: right;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;display: inline-block;vertical-align: middle;width: 229.594px;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box;text-align: center;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;vertical-align: middle;display: inline-block;line-height: 0;width: 229.594px;overflow-wrap: break-word !important;"> <img data-ratio="0.2106667" data-w="750" width="100%" data-type="gif" class="__bg_gif" src="/upload/9a990984a6b8f7f7b3c167d0a48d8599.png" style="box-sizing: border-box;vertical-align: middle;overflow-wrap: break-word !important;width: 229.594px !important;visibility: visible !important;"> </section> </section> </section> <section style="max-width: 100%;box-sizing: border-box;display: inline-block;vertical-align: middle;width: 143.5px;overflow-wrap: break-word !important;"> <section powered-by="xiumi.us" style="margin-top: 0.5em;margin-bottom: 0.5em;max-width: 100%;box-sizing: border-box;overflow-wrap: break-word !important;"> <section style="max-width: 100%;box-sizing: border-box;background-color: rgb(29, 29, 29);height: 1px;overflow-wrap: break-word !important;"> <br> </section> </section> </section> </section> <section powered-by="xiumi.us" style="max-width: 100%;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <section data-tool="mdnice编辑器" data-website="https://www.mdnice.com"> <figure data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;max-width: 100%;display: flex;flex-direction: column;justify-content: center;align-items: center;box-sizing: border-box !important;overflow-wrap: break-word !important;"> <span style="max-width: 100%;color: black;font-size: 15px;letter-spacing: 0.05em;box-sizing: border-box !important;overflow-wrap: break-word !important;"><span style="color: rgb(89, 89, 89);letter-spacing: 0.05em;background-color: rgb(255, 255, 255);font-family: -apple-system-font, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei UI&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;"></span><br></span> </figure> <p style="box-sizing: border-box;margin-top: 16px;margin-bottom: 16px;border-width: 0px;border-style: initial;border-color: initial;color: rgb(34, 34, 34);font-family: &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">现在很多站长都会考虑将自己的站点从http升级到https,不仅是基于安全的考虑,有的也是因为第三方平台的限制,如谷歌浏览器会将http站点标记为不安全的站点,微信平台要求接入的微信小程序必须使用https等。</p> <p style="box-sizing: border-box;margin-top: 16px;margin-bottom: 16px;border-width: 0px;border-style: initial;border-color: initial;color: rgb(34, 34, 34);font-family: &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">那如何将一个http站点升级为https站点呢?</p> <h1 style=" box-sizing: border-box;font-size: 1.5em;padding-left: 12px;font-weight: 700;border-width: 0px;border-style: initial;border-color: initial;line-height: 1.33333;color: rgb(34, 34, 34); font-family: &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;text-align: start;white-space: normal;background-color: rgb(255, 255, 255); ">http与https的区别</h1> <p style="box-sizing: border-box;margin-top: 16px;margin-bottom: 16px;border-width: 0px;border-style: initial;border-color: initial;color: rgb(34, 34, 34);font-family: &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">为了数据传输的安全,https在http的基础上加入了ssl协议,ssl协议依靠证书来验证服务器的身份,并为浏览器和服务器之间的通信加密。要想将http升级为https,只需要给http站点增加一个CA证书即可。</p> <p style="box-sizing: border-box;margin-top: 16px;margin-bottom: 16px;border-width: 0px;border-style: initial;border-color: initial;color: rgb(34, 34, 34);font-family: &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">目前获取CA证书有两种途径:</p> <ol style="margin: 20px 30px;border-width: 0px;border-style: initial;border-color: initial;list-style-position: outside;list-style-image: initial;color: rgb(34, 34, 34);font-family: &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);" class="list-paddingleft-2"> <li style="box-sizing: border-box;list-style: inherit;border-width: 0px;border-style: initial;border-color: initial;"><p>购买收费的CA证书</p></li> <li style="box-sizing: border-box;list-style: inherit;border-width: 0px;border-style: initial;border-color: initial;"><p>获取免费的证书</p></li> </ol> <p style="box-sizing: border-box;margin-top: 16px;margin-bottom: 16px;border-width: 0px;border-style: initial;border-color: initial;color: rgb(34, 34, 34);font-family: &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">收费的CA证书各大服务提供商都有卖,如阿里云、腾讯云等。</p> <p style="text-align: center;"><img class="rich_pages" data-ratio="0.397708674304419" data-s="300,640" src="/upload/394603a8237aa5bcb53f1831124a6447.png" data-type="png" data-w="1222" style=""></p> <p style="box-sizing: border-box;margin-top: 16px;margin-bottom: 16px;border-width: 0px;border-style: initial;border-color: initial;color: rgb(34, 34, 34);font-family: &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, &quot;Helvetica Neue&quot;, Arial, sans-serif;font-size: 16px;text-align: start;white-space: normal;background-color: rgb(255, 255, 255);">收费的证书不便宜,从阿里云官方网站看,它的价格可以从几千元到上万元不等。<br></p> <p><img data-ratio="0.4575402635431918" src="/upload/299c06c719bba577e7c7192fffaed853.png" data-type="png" data-w="1366" style="box-sizing: border-box;border-width: 0px;border-style: initial;border-color: initial;margin-right: auto;margin-left: auto;cursor: zoom-in;display: block;"></p> <p style="box-sizing: border-box;margin-top: 16px;margin-bottom: 16px;border-width: 0px;border-style: initial;border-color: initial;color: rgb(34, 34, 34);font-family: &quo