欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java,

来源: javaer 分享于  点击 26901 次 点评:204

java,


1: redis.properteis 连接需要的配置信息

redis.sentinels.host1=sen201.dev.rs.com
redis.sentinels.host2=sen201.dev.rs.com
redis.sentinels.host3=sen201.dev.rs.com
redis.sentinels.port1=26380
redis.sentinels.port2=26380
redis.sentinels.port3=26380

2: spring-redis.xml 配置文件

<bean id="redisSentinelConfiguration"
class="org.springframework.data.redis.connection.RedisSentinelConfiguration">
<property name="master">
<bean class="org.springframework.data.redis.connection.RedisNode">
<property name="name" value="${redis.cluster.name}"></property>
</bean>
</property>
<property name="sentinels">
<set>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg index="0" value="${redis.sentinels_1.host}" />
<constructor-arg index="1" value="${redis.sentinels_1.port}"/>
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg index="0" value="${redis.sentinels_2.host}"/>
<constructor-arg index="1" value="${redis.sentinels_2.port}"/>
</bean>
<bean class="org.springframework.data.redis.connection.RedisNode">
<constructor-arg index="0" value="${redis.sentinels_3.host}"/>
<constructor-arg index="1" value="${redis.sentinels_3.port}"/>
</bean>
</set>
</property>
</bean>

<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="100"/><!-- 最大能够保持idel状态的对象数 -->
<property name="maxTotal" value="4000"/><!-- 最大分配的对象数 -->
<property name="testOnBorrow" value="true"/><!-- 当调用borrow Object方法时,是否进行有效性检查 -->
</bean>

<!-- redis服务器中心 -->
<bean id="jedisConnectionFactory"
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="password" value="${redis.connection.password}"/>
<property name="usePool" value="true"/>
<property name="poolConfig" ref="jedisPoolConfig"></property>
<constructor-arg ref="redisSentinelConfiguration" />
</bean>
<!-- key序列化 -->
<bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />

<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory" />

<property name="keySerializer" ref="stringRedisSerializer" />
<property name="hashKeySerializer" ref="stringRedisSerializer" />
<property name="valueSerializer" ref="stringRedisSerializer"/>
</bean>

相关文章

    暂无相关文章
相关栏目:

用户点评