Redis+Sentinel数据源配置

    xiaoxiao2026-10-03  10

    1.default.properties配置文件:

    # Redis settings #sentinel_node_1 redis.sentinel1.host=192.168.20.105 redis.sentinel1.port=26379 #sentinel_node_2 redis.sentinel2.host=192.168.20.29 redis.sentinel2.port=26379 #sentinel_node_3 redis.sentinel3.host=192.168.20.108 redis.sentinel3.port=26379 #sentinel_auth redis.sentinel.masterName=mymaster redis.sentinel.password=123456 redis.maxIdle=500 redis.maxTotal=5000 redis.maxWaitTime=1000 redis.minIdle=300 redis.testOnBorrow=true2.applicationContext.xml配置文件:

    <!-- 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服务配置 结束 -->3.数据源配置结束,谢谢。

    转载请注明原文地址: https://ju.6miu.com/read-1312593.html
    最新回复(0)