当前位置: 首页 > news >正文

惠州网站建设英语领动网站建设

惠州网站建设英语,领动网站建设,公司网站制作流程2016,网站怎么做安全文章目录 一、前提条件二、SpringBoot访问Redis集群1. 引入依赖2. yaml配置3. 设置读写分离4. 简单的controller 三、运行四、测试1. 写2. 读3. 额外测试 环境 docker desktop for windows 4.23.0redis 7.2Idea 一、前提条件 先根据以下文章搭建一个Redis集群 Docker-Compo… 文章目录 一、前提条件二、SpringBoot访问Redis集群1. 引入依赖2. yaml配置3. 设置读写分离4. 简单的controller 三、运行四、测试1. 写2. 读3. 额外测试 环境 docker desktop for windows 4.23.0redis 7.2Idea 一、前提条件 先根据以下文章搭建一个Redis集群 Docker-Compose部署Redis(v7.2)主从模式Docker-Compose部署Redis(v7.2)哨兵模式 部署完后redis集群看起来大致如下图 二、SpringBoot访问Redis集群 1. 引入依赖 需要注意的是lettuce-core版本问题不能太旧否则不兼容新版的Redis。 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-redis/artifactId/dependencydependencygroupIdio.lettuce/groupIdartifactIdlettuce-core/artifactIdversion6.1.4.RELEASE/version !-- 或更高版本 --/dependency2. yaml配置 在application.yml加入以下配置。第一个password是用于sentinel节点验证第二个password用于数据节点验证。 spring:redis:sentinel:master: mymasternodes:- 172.30.1.11:26379- 172.30.1.12:26379- 172.30.1.13:26379password: 1009password: 1009这里关于sentinel的ip问题后面会讲解。 3. 设置读写分离 在任意配置类中写一个Bean本文简单起见直接写在SpringBoot启动类了。 Beanpublic LettuceClientConfigurationBuilderCustomizer clientConfigurationBuilderCustomizer(){return clientConfigurationBuilder - clientConfigurationBuilder.readFrom(ReadFrom.REPLICA_PREFERRED);}这里的ReadFrom是配置Redis的读取策略是一个枚举包括下面选择 MASTER从主节点读取MASTER_PREFERRED:优先从master节点读取master不可用才读取replicaREPLICA:从slave (replica)节点读取REPLICA_PREFERRED优先从slave replica节点读取所有的slave都不可用才读取master 至于哪些节点支持读哪些支持写因为redis 7 默认给从节点设置为只读所以可以认为只有主节点有读写权限其余只有读权限。如果情况不一致就手动给每一个redis-server的配置文件都加上这一行。 replica-read-only yes4. 简单的controller 写一个简单的controller等会用于测试。 RestController public class HelloController {Autowiredprivate StringRedisTemplate redisTemplate;GetMapping(/get/{key})public String hi(PathVariable String key) {return redisTemplate.opsForValue().get(key);}GetMapping(/set/{key}/{value})public String hi(PathVariable String key, PathVariable String value) {redisTemplate.opsForValue().set(key, value);return success;} }三、运行 首先因为所有redis节点都在一个docker bridge网络中所以基于Idea编写的项目在宿主机(Windows)中运行spirngboot程序不好去和redis集群做完整的交互。 虽然说无论是sentinel还是redis-server都暴露了端口到宿主机我们可以通过映射的端口分别访问它们但是我们的程序只访问sentinelsentinel管理redis-serversentinel会返回redis-server的ip来让我们的程序来访问redis-server这里的ip是docker bridge网络里的ip所以即使我们的程序拿到ip也访问不了redis-server。 这个时候就需要将我们的项目放到一个docker容器中运行然后把这个容器放到和redis同一网络下就像下图。 具体如何快捷让Idea结合Docker去运行SpringBoot程序可以参考下面这篇文章。 Idea连接Docker在本地(Windows)开发SpringBoot 记得要暴露你的程序端口到宿主机这样才方便测试。 四、测试 1. 写 浏览器访问localhost:8080/set/num/7799 查看SpringBoot容器日志可以看到向主节点172.30.1.2:6379发送写请求。 01-06 07:23:59:848 DEBUG 1 --- [nio-8080-exec-6] io.lettuce.core.RedisChannelHandler : dispatching command AsyncCommand [typeSET, outputStatusOutput [outputnull, errornull], commandTypeio.lettuce.core.protocol.Command] 01-06 07:23:59:848 DEBUG 1 --- [nio-8080-exec-6] i.l.c.m.MasterReplicaConnectionProvider : getConnectionAsync(WRITE) 01-06 07:23:59:848 DEBUG 1 --- [nio-8080-exec-6] io.lettuce.core.RedisChannelHandler : dispatching command AsyncCommand [typeSET, outputStatusOutput [outputnull, errornull], commandTypeio.lettuce.core.protocol.Command] 01-06 07:23:59:848 DEBUG 1 --- [nio-8080-exec-6] i.lettuce.core.protocol.DefaultEndpoint : [channel0x9b4ebc85, /172.30.1.5:46700 - /172.30.1.2:6379, epid0xf] write() writeAndFlush command AsyncCommand [typeSET, outputStatusOutput [outputnull, errornull], commandTypeio.lettuce.core.protocol.Command] 01-06 07:23:59:848 DEBUG 1 --- [nio-8080-exec-6] i.lettuce.core.protocol.DefaultEndpoint : [channel0x9b4ebc85, /172.30.1.5:46700 - /172.30.1.2:6379, epid0xf] write() done 01-06 07:23:59:848 DEBUG 1 --- [oEventLoop-4-10] io.lettuce.core.protocol.CommandHandler : [channel0x9b4ebc85, /172.30.1.5:46700 - /172.30.1.2:6379, epid0xf, chid0x16] write(ctx, AsyncCommand [typeSET, outputStatusOutput [outputnull, errornull], commandTypeio.lettuce.core.protocol.Command], promise) 01-06 07:23:59:849 DEBUG 1 --- [oEventLoop-4-10] io.lettuce.core.protocol.CommandEncoder : [channel0x9b4ebc85, /172.30.1.5:46700 - /172.30.1.2:6379] writing command AsyncCommand [typeSET, outputStatusOutput [outputnull, errornull], commandTypeio.lettuce.core.protocol.Command] 01-06 07:23:59:851 DEBUG 1 --- [oEventLoop-4-10] io.lettuce.core.protocol.CommandHandler : [channel0x9b4ebc85, /172.30.1.5:46700 - /172.30.1.2:6379, epid0xf, chid0x16] Received: 5 bytes, 1 commands in the stack 01-06 07:23:59:851 DEBUG 1 --- [oEventLoop-4-10] io.lettuce.core.protocol.CommandHandler : [channel0x9b4ebc85, /172.30.1.5:46700 - /172.30.1.2:6379, epid0xf, chid0x16] Stack contains: 1 commands 01-06 07:23:59:851 DEBUG 1 --- [oEventLoop-4-10] i.l.core.protocol.RedisStateMachine : Decode done, empty stack: true 01-06 07:23:59:852 DEBUG 1 --- [oEventLoop-4-10] io.lettuce.core.protocol.CommandHandler : [channel0x9b4ebc85, /172.30.1.5:46700 - /172.30.1.2:6379, epid0xf, chid0x16] Completing command AsyncCommand [typeSET, outputStatusOutput [outputOK, errornull], commandTypeio.lettuce.core.protocol.Command]2. 读 浏览器访问localhost:8080/get/num 查看SpringBoot容器日志会向两个从节点之一发送读请求。 01-06 07:25:45:342 DEBUG 1 --- [io-8080-exec-10] io.lettuce.core.RedisChannelHandler : dispatching command AsyncCommand [typeGET, outputValueOutput [outputnull, errornull], commandTypeio.lettuce.core.protocol.Command] 01-06 07:25:45:342 DEBUG 1 --- [io-8080-exec-10] i.l.c.m.MasterReplicaConnectionProvider : getConnectionAsync(READ) 01-06 07:25:45:342 DEBUG 1 --- [io-8080-exec-10] io.lettuce.core.RedisChannelHandler : dispatching command AsyncCommand [typeGET, outputValueOutput [outputnull, errornull], commandTypeio.lettuce.core.protocol.Command] 01-06 07:25:45:342 DEBUG 1 --- [io-8080-exec-10] i.lettuce.core.protocol.DefaultEndpoint : [channel0x96ae68cf, /172.30.1.5:38102 - /172.30.1.4:6379, epid0x1c] write() writeAndFlush command AsyncCommand [typeGET, outputValueOutput [outputnull, errornull], commandTypeio.lettuce.core.protocol.Command] 01-06 07:25:45:342 DEBUG 1 --- [io-8080-exec-10] i.lettuce.core.protocol.DefaultEndpoint : [channel0x96ae68cf, /172.30.1.5:38102 - /172.30.1.4:6379, epid0x1c] write() done 01-06 07:25:45:342 DEBUG 1 --- [oEventLoop-4-11] io.lettuce.core.protocol.CommandHandler : [channel0x96ae68cf, /172.30.1.5:38102 - /172.30.1.4:6379, epid0x1c, chid0x23] write(ctx, AsyncCommand [typeGET, outputValueOutput [outputnull, errornull], commandTypeio.lettuce.core.protocol.Command], promise) 01-06 07:25:45:343 DEBUG 1 --- [oEventLoop-4-11] io.lettuce.core.protocol.CommandEncoder : [channel0x96ae68cf, /172.30.1.5:38102 - /172.30.1.4:6379] writing command AsyncCommand [typeGET, outputValueOutput [outputnull, errornull], commandTypeio.lettuce.core.protocol.Command] 01-06 07:25:45:346 DEBUG 1 --- [oEventLoop-4-11] io.lettuce.core.protocol.CommandHandler : [channel0x96ae68cf, /172.30.1.5:38102 - /172.30.1.4:6379, epid0x1c, chid0x23] Received: 10 bytes, 1 commands in the stack 01-06 07:25:45:346 DEBUG 1 --- [oEventLoop-4-11] io.lettuce.core.protocol.CommandHandler : [channel0x96ae68cf, /172.30.1.5:38102 - /172.30.1.4:6379, epid0x1c, chid0x23] Stack contains: 1 commands 01-06 07:25:45:346 DEBUG 1 --- [oEventLoop-4-11] i.l.core.protocol.RedisStateMachine : Decode done, empty stack: true 01-06 07:25:45:346 DEBUG 1 --- [oEventLoop-4-11] io.lettuce.core.protocol.CommandHandler : [channel0x96ae68cf, /172.30.1.5:38102 - /172.30.1.4:6379, epid0x1c, chid0x23] Completing command AsyncCommand [typeGET, outputValueOutput [output[B7427ef47, errornull], commandTypeio.lettuce.core.protocol.Command]3. 额外测试 以及还有一些额外的测试可以自行去尝试检验这里列举一些但具体不再赘述。 关闭两个从节点容器等待sentinel完成维护和通知后测试读数据和写数据会请求谁再次开启两个从节点等待sentinel完成操作后再关闭主节点等待sentinel完成操作后测试读数据和写数据会请求谁再次开启主节点等待sentinel完成操作后测试读数据和写数据会请求谁
http://www.pierceye.com/news/278553/

相关文章:

  • 宜春公司网站建设百度地图广告投放
  • wordpress 2.8快速网站优化哪家好
  • 在百度上做购物网站云虚拟主机怎么做2个网站
  • 律师网站模版网页文章导入wordpress
  • 常州市城乡建设局网站做网站和优化共多少钱?
  • 做o2o平台网站需要多少钱买卖域名的网站好
  • 网站设计 手写室内设计奖项有哪些
  • 做电影网站需要那种服务器本地电脑搭建服务器
  • 分析某个网站建设百度知道一下首页
  • 贵池区城乡与住房建设网站建站快车是什么
  • 建站程序aspiis 默认网站 删除
  • 手机开网店的免费平台河南seo推广多少钱
  • 网站app推广怎么做wordpress 手机号注册
  • 网站开发到上线需要多久骆驼有没有做网站的公司
  • 中小企业网站建设示范平台wordpress停用react
  • 网站怎样防止攻击seo顾问培训
  • 网站建设后需要维护吗微信安全中心官网
  • dw可以做h5网站设计素材网站0
  • 建设银行郑州中心支行网站青海商会网站建设公司
  • 国外小型网站中国视觉设计网
  • 沈阳专业网站制作团队泰安网络软件公司
  • 网站建设招聘兼职0基础建站教程
  • 如何从零开始做网站文学网站建设平台
  • 企业网站的网址通常包含dchaser wordpress
  • 什么是做网站flash是怎么做网站的
  • 什么是速成网站石家庄网站建设就找
  • 张家界网站建设要求滨州网站建设费用
  • wordpress订阅插件南昌优化排名推广
  • 国外做网站公司能赚钱吗wordpress登录锚点弹
  • 微网站平台微网站建设方案邢台市有几个区几个县