spring-config-redis.xml 1.89 KB
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- redis template definition -->
    <bean id="stringRedisSerializer"
          class="org.springframework.data.redis.serializer.StringRedisSerializer"/>

    <!-- pool config -->
    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <property name="maxTotal" value="${redis.pool.maxTotal:50}" />
        <property name="maxIdle" value="${redis.pool.maxIdle:10}" />
        <property name="minIdle" value="${redis.pool.minIdle:5}"/>
        <property name="maxWaitMillis" value="${redis.pool.maxWaitMillis:2000}" />
        <property name="testOnBorrow" value="${redis.pool.testOnBorrow:false}" />
        <property name="testWhileIdle" value="${redis.pool.testWhileIdle:false}"/>
    </bean>

    <!-- aws -->
    <bean id="awsJedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
          p:timeout="250"
          p:poolConfig-ref="jedisPoolConfig"
          p:hostName="${aws.redis.proxy.address}"
          p:port="${aws.redis.proxy.port}"
          p:password="${aws.redis.proxy.auth}"
          p:database="${aws.redis.proxy.database:0}" primary="true"/>

    <bean id="awsRedisTemplate"  primary="false"
          class="org.springframework.data.redis.core.StringRedisTemplate"
          p:connectionFactory-ref="awsJedisConnectionFactory"
          p:keySerializer-ref="stringRedisSerializer"
          p:valueSerializer-ref="stringRedisSerializer"
          p:hashKeySerializer-ref="stringRedisSerializer"
          p:hashValueSerializer-ref="stringRedisSerializer"/>

</beans>