使用Redis集群时,如何配置spring-data-redis-1.7.2 password(xml)?

时间:2018-09-26 04:48:07

标签: redis

我尝试使用spring-data-redis-2.0.9,我这样配置密码,一切正常。

<bean name="redisPassword" class="org.springframework.data.redis.connection.RedisPassword">
    <constructor-arg name="thePassword" value="${spring.redis.cluster.password}"/>
</bean>

<bean id="redisClusterConfiguration" class="org.springframework.data.redis.connection.RedisClusterConfiguration">
    <constructor-arg name="propertySource" ref="propertySource"/>
    <property name="password" ref="redisPassword"/>
</bean>

但是,由于某种原因,我必须使用spring-data-redis-1.7.2。这是我的配置

<context:property-placeholder location="/WEB-INF/redis.properties" ignore-unresolvable="true"></context:property-placeholder>

<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
    <property name="maxTotal" value="${redis.pool.maxTotal}"/>
    <property name="maxIdle" value="${redis.pool.maxIdle}"/>
    <property name="numTestsPerEvictionRun" value="${redis.pool.numTestsPerEvictionRun}"/>
    <property name="timeBetweenEvictionRunsMillis" value="${redis.pool.timeBetweenEvictionRunsMillis}"/>
    <property name="minEvictableIdleTimeMillis" value="${redis.pool.minEvictableIdleTimeMillis}"/>
    <property name="softMinEvictableIdleTimeMillis" value="${redis.pool.softMinEvictableIdleTimeMillis}"/>
    <property name="maxWaitMillis" value="${redis.pool.maxWaitMillis}"/>
    <property name="testOnBorrow" value="${redis.pool.testOnBorrow}"/>
    <property name="testWhileIdle" value="${redis.pool.testWhileIdle}"/>
    <property name="blockWhenExhausted" value="${redis.pool.blockWhenExhausted}"/>
</bean>

<bean name="propertySource" class="org.springframework.core.io.support.ResourcePropertySource">
    <constructor-arg name="resource" value="/WEB-INF/redis.properties" />
</bean>

<bean id="redisClusterConfig" class="org.springframework.data.redis.connection.RedisClusterConfiguration">
    <constructor-arg name="propertySource" ref="propertySource"/>
</bean>

<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
    <constructor-arg name="clusterConfig" ref="redisClusterConfig"/>
    <constructor-arg name="poolConfig" ref="jedisPoolConfig"/>
    <property name="timeout" value="${redis.timeout}"/>
    <property name="password" value="spring.redis.cluster.password" />
</bean>

<bean id="keySerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
<bean id="valueSerializer" class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer"/>

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

<bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
    <constructor-arg name="connectionFactory" ref="jedisConnectionFactory"></constructor-arg>
    <property name="keySerializer" ref="keySerializer" />
    <property name="valueSerializer" ref="valueSerializer" />
    <property name="hashKeySerializer" ref="valueSerializer" />
    <property name="hashValueSerializer" ref="valueSerializer" />
</bean>

tomcat提醒我“ Jedis不支持受密码保护的Redis群集配置”。 如何配置spring-data-redis-1.7.2密码。

0 个答案:

没有答案