Redis-Sentinel 数据源配置
1.redis配置文件 : redis.properties
- # Redis settings
- #sentinel_node_1
- redis.sentinel1.host=192.168.0.1
- redis.sentinel1.port=8001
- #sentinel_node_2
- redis.sentinel2.host=192.168.0.1
- redis.sentinel2.port=8002
- #sentinel_node_3
- redis.sentinel3.host=192.168.0.1
- redis.sentinel3.port=8003
- #sentinel_auth
- redis.sentinel.masterName=TestMaster
- redis.sentinel.password=testmaster123
- redis.maxIdle=500
- redis.maxTotal=5000
- redis.maxWaitTime=1000
- redis.minIdle=300
- redis.testOnBorrow=true
2.redis数据源的配置文件:redis-datasource.xml
这里给大家介绍两种配置模式 spring-redis配置模式 非spring-redis配置模式
2.1spring-redis配置模式:
maven依赖:
- <dependency>
- <groupId>redis.clients</groupId>
- <artifactId>jedis</artifactId>
- <version>2.8.0</version>
- </dependency>
- <!-- spring-redis -->
- <dependency>
- <groupId>org.springframework.data</groupId>
- <artifactId>spring-data-redis</artifactId>
- <version>1.6.4.RELEASE</version>
- </dependency>
- <!-- redis服务配置 开始-->
- <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
- <property name="maxTotal" value="${redis.maxTotal}" />
- <property name="minIdle" value="${redis.minIdle}" />
- <property name="maxWaitMillis" value="${redis.maxWaitTime}" />
- <property name="maxIdle" value="${redis.maxIdle}" />
- <property name="testOnBorrow" value="${redis.testOnBorrow}" />
- <property name="testOnReturn" value="true" />
- <property name="testWhileIdle" value="true" />
- </bean>
- <bean id="sentinelConfiguration"
- class="org.springframework.data.redis.connection.RedisSentinelConfiguration">
- <property name="master">
- <bean class="org.springframework.data.redis.connection.RedisNode">
- <property name="name" value="${redis.sentinel.masterName}"></property>
- </bean>
- </property>
- <property name="sentinels">
- <set>
- <bean class="org.springframework.data.redis.connection.RedisNode">
- <constructor-arg name="host"
- value="${redis.sentinel1.host}"></constructor-arg>
- <constructor-arg name="port"
- value="${redis.sentinel1.port}"></constructor-arg>
- </bean>
- <bean class="org.springframework.data.redis.connection.RedisNode">
- <constructor-arg name="host"
- value="${redis.sentinel2.host}"></constructor-arg>
- <constructor-arg name="port"
- value="${redis.sentinel2.port}"></constructor-arg>
- </bean>
- <bean class="org.springframework.data.redis.connection.RedisNode">
- <constructor-arg name="host"
- value="${redis.sentinel3.host}"></constructor-arg>
- <constructor-arg name="port"
- value="${redis.sentinel3.port}"></constructor-arg>
- </bean>
- </set>
- </property>
- </bean>
- <bean id="connectionFactory"
- class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:password="${redis.sentinel.password}">
- <constructor-arg name="sentinelConfig" ref="sentinelConfiguration"></constructor-arg>
- <constructor-arg name="poolConfig" ref="poolConfig"></constructor-arg>
- </bean>
- <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
- <property name="connectionFactory" ref="connectionFactory" />
- </bean>
- <bean id="redisService" class="com.usi.hlqb.service.redis.RedisService">
- <property name="redisTemplate" ref="redisTemplate"></property>
- </bean>
- <!-- redis服务配置 结束 -->
2.2 非spring-redis的配置模式:
maven依赖:
- <dependency>
- <groupId>com.imwinston</groupId>
- <artifactId>JedisBase</artifactId>
- <version>2.1.17-sentinel-4</version>
- </dependency>
- <dependency>
- <groupId>redis.clients</groupId>
- <artifactId>jedis</artifactId>
- <version>2.8.0</version>
- </dependency>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <version>18.0</version>
- </dependency>
- <dependency>
- <groupId>com.esotericsoftware</groupId>
- <artifactId>kryo</artifactId>
- <version>3.0.1</version>
- </dependency>
- <!-- jedis 连接池配置-->
- <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
- <property name="maxIdle" value="${redis.maxIdle}" />
- <property name="maxTotal" value="${redis.maxTotal}" />
- <property name="testOnBorrow" value="${redis.testOnBorrow}" />
- </bean>
<!--哨兵配置-->- <bean id="jedisPool" class="redis.clients.jedis.JedisSentinelPool">
- <constructor-arg index="0" value="myMaster" />
- <constructor-arg index="1">
- <set>
- <value>192.168.0.1:8001</value>
- <value>192.168.0.1:8002</value>
- <value>192.168.0.1:8003</value>
- </set>
- </constructor-arg>
- <constructor-arg index="2" ref="jedisPoolConfig" />
- <constructor-arg index="3" value="${redis.sentinel.password}" />
- </bean>
- <bean id="jedisBase" class="com.imwinston.redis.jedisbase.JedisBase">
- <property name="pool" ref="jedisPool" />
- </bean>
- <!-- 本地sqlite数据源定义 -->
- <bean id="sqlDs" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
- <property name="driverClassName" value="org.sqlite.JDBC"/>
- <property name="url" value="jdbc:sqlite:"/>
- <property name="username" value=""/>
- <property name="password" value=""/>
- </bean>
Redis-Sentinel 数据源配置的更多相关文章
- 【转载】Redis Sentinel服务配置
转载地址:http://blog.csdn.net/vtopqx/article/details/49247285 redis官网文档:http://www.redis.cn/topics/senti ...
- Spring Boot 2.x Redis多数据源配置(jedis,lettuce)
Spring Boot 2.x Redis多数据源配置(jedis,lettuce) 96 不敢预言的预言家 0.1 2018.11.13 14:22* 字数 65 阅读 727评论 0喜欢 2 多数 ...
- Redis Sentinel哨兵配置
概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如master宕机了,Redis本身(包括它的很多客户端)都 ...
- 亲密接触Redis-第二天(Redis Sentinel)
简介 经过上次轻松搭建了一个Redis的环境并用Java代码调通后,这次我们要来看看Redis的一些坑以及Redis2.8以后带来的一个新的特性即支持高可用特性功能的Sentinel(哨兵). Red ...
- 高可用Redis(九):Redis Sentinel
1.主从复制高可用的问题 主从复制高可用的作用 1.为master提供备份,当master宕机时,slave有完整的备份数据 2.对master实现分流,实现读写分离 但是主从架构有一个问题 1.如果 ...
- Redis Sentinel 模拟故障迁移
什么是redis sentinel 参考文档:https://redis.io/topics/sentinel 简单的来说,就是Redis Sentinel 为redis 提供高可用性,主要体现在下面 ...
- 亲热接触Redis-第二天(Redis Sentinel)
简单介绍 经过上次轻松搭建了一个Redis的环境并用Java代码调通后.这次我们要来看看Redis的一些坑以及Redis2.8以后带来的一个新的特性即支持高可用特性功能的Sentinel(哨兵). R ...
- Redis Sentinel集群配置中的一些细节
今天在配置Redis集群,用作Tomcat集群的缓存共享.关于Redis集群的配置网上有很多文章,这里只是记录一下我在配置过程中遇到的一些小的细节问题. 1. 关于Protected Mode的问题 ...
- redis sentinel 集群配置-主从切换
1.配置redis master,redis slave(配置具体操作见上文http://www.cnblogs.com/wangchaozhi/p/5140469.html). redis mast ...
- redis sentinel 集群监控 配置
环境: ip 172.16.1.31 26379 redis sentinel ip 172.16.1.30 6379 主 1 ip 172.16.1.31 6380 从 1 ip ...
随机推荐
- python异常处理机制
python有五种异常处理机制,分别是 1.默认异常处理器. 如果我们没有对异常进行任何预防,那么程序在执行过程中发生异常就会中断程序,调用python默认的异常处理器,并在终端输出异常信息,如图所示 ...
- Linux过滤错误日志
grep -E 'at |Exception|exception|Error|error|Caused by' test.log
- 关于手贱--npm 误改全局安装路径
1.通过 npm config set prefix "目录路径" 来设置.通过 npm config get prefix 来获取当前设置的目录. 2.npm config se ...
- Spring Cloud 请求重试机制核心代码分析
场景 发布微服务的操作一般都是打完新代码的包,kill掉在跑的应用,替换新的包,启动. spring cloud 中使用eureka为注册中心,它是允许服务列表数据的延迟性的,就是说即使应用已经不在服 ...
- pycharm中添加PATH变量
最近在pycharm中run程序,终端terminal没有问题,在pycharm找不到$PATH中的变量值,如下图所示 同样的命令,在终端敲就没毛病,终端echo $PATH的时候,显示的是有cuda ...
- 【开发遇到的问题】Spring Mvc使用Jackson进行json转对象时,遇到的字符串转日期的异常处理(JSON parse error: Can not deserialize value of type java.util.Date from String[)
1.问题排查 - 项目配置 springboot 2.1 maven配置jackson - 出现的场景: 服务端通过springmvc写了一个对外的接口,查询数据中的表,表中有一个字段属性是时间戳,返 ...
- Kali安装虚拟机遇到的问题
1.上官网下载了最新版的VMware 14.0版,安装的时候下一步下一步就是了. 2.最新版的官网激活码 FF590-2DX83-M81LZ-XDM7E-MKUT4 CG54H-D8D0H-H8DHY ...
- 数学:确定性的丧失 (M·克莱因 著)
第一章 数学真理的起源 (已看) 第二章 数学真理的繁荣 (已看) 第三章 科学的数学化 (已看) 第四章 第一场灾难:真理的丧失 (已看) 第五章 一门逻辑科学不合逻辑的发展 (已看) 第六章 分析 ...
- winform中devexpress bindcommand无效的解决方法
正常绑定,编译运行无报错,但无法执行command fluentAPI.BindCommand(commandButton, (x, p) => x.DoSomething(p), x => ...
- Spring IOC 相关的面试题
Spring最基础的部分就是IOC,对IOC的理解程度从某个方面代表着你对Spring 的理解程度,看了网上的一些面试题,针对Spring IOC相关的重点是下面几个: 1.Spring中Bean ...