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 数据源配置的更多相关文章

  1. 【转载】Redis Sentinel服务配置

    转载地址:http://blog.csdn.net/vtopqx/article/details/49247285 redis官网文档:http://www.redis.cn/topics/senti ...

  2. 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 多数 ...

  3. Redis Sentinel哨兵配置

    概述 Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案,当用Redis做Master-slave的高可用方案时,假如master宕机了,Redis本身(包括它的很多客户端)都 ...

  4. 亲密接触Redis-第二天(Redis Sentinel)

    简介 经过上次轻松搭建了一个Redis的环境并用Java代码调通后,这次我们要来看看Redis的一些坑以及Redis2.8以后带来的一个新的特性即支持高可用特性功能的Sentinel(哨兵). Red ...

  5. 高可用Redis(九):Redis Sentinel

    1.主从复制高可用的问题 主从复制高可用的作用 1.为master提供备份,当master宕机时,slave有完整的备份数据 2.对master实现分流,实现读写分离 但是主从架构有一个问题 1.如果 ...

  6. Redis Sentinel 模拟故障迁移

    什么是redis sentinel 参考文档:https://redis.io/topics/sentinel 简单的来说,就是Redis Sentinel 为redis 提供高可用性,主要体现在下面 ...

  7. 亲热接触Redis-第二天(Redis Sentinel)

    简单介绍 经过上次轻松搭建了一个Redis的环境并用Java代码调通后.这次我们要来看看Redis的一些坑以及Redis2.8以后带来的一个新的特性即支持高可用特性功能的Sentinel(哨兵). R ...

  8. Redis Sentinel集群配置中的一些细节

    今天在配置Redis集群,用作Tomcat集群的缓存共享.关于Redis集群的配置网上有很多文章,这里只是记录一下我在配置过程中遇到的一些小的细节问题. 1. 关于Protected Mode的问题 ...

  9. redis sentinel 集群配置-主从切换

    1.配置redis master,redis slave(配置具体操作见上文http://www.cnblogs.com/wangchaozhi/p/5140469.html). redis mast ...

  10. 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   ...

随机推荐

  1. 因mybatis逆向工程而产生的问题

    今天我在搭建SSM框架环境时,配置都配好了,就等运行测试,谁知道一来就报错,并且这个错误折腾了我一下午,真的是血的教训:   BeanCreationException:Error creating ...

  2. 解决ios兼容性问题

    其实也不算兼容性问题 在做一个手指切换动画时,在安卓显示正常但是在iOS上切换图片时整个页面会向上或向下窜,这样非常印象美观,这种现象是由于ios自带的下拉刷新功能能影响的: 解决方法: 添加阻止事件 ...

  3. oh_my_zsh

    oh_my_zsh  zsh默认已经安装   cat /etc/shells   查看安装没有   (https://xiaozhou.net/learn-the-command-line-iterm ...

  4. 一般xcode报错

    下面这图报找不到FMDtabaseQueue,其实是把文件拖入xcode的时候xcode没有把.m文件添加进工程路径 解决办法:build phases-> compile sources &q ...

  5. ECB cspk7 加密

    public function test(){ $param = input('param.'); // $input = 'userid=7&gameid=100107&buycou ...

  6. js使页面重定向

    location.assign("http://www.baidu.com"); window.location="http://www.baidu.com"; ...

  7. 九度OJ-第5章-图论

    二.并查集 1. 例题 题目1012:畅通工程 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:10519 解决:4794 题目描述: 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出 ...

  8. Date.parse()转化日期为时间戳,ios与Android兼容写法

    把固定格式日期转化为时间戳: //格式化当地日期 new Date('2017-11-11 0:0:0') //结果为:Sat Nov 11 2017 00:00:00 GMT+0800 (中国标准时 ...

  9. POJ3017 Cut the Sequence

    题意 Language:Default Cut the Sequence Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 122 ...

  10. MVC 模式

    1.MVC 模式简介 MVC 模式代表 Model-View-Controller(模型-视图-控制器) 模式.这种模式用于应用程序的分层开发.Model(模型):模型代表一个存取数据的对象或 JAV ...