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

    <!--订单系统缓存所需配置  需单独配置,否则会与上面的统一管理平台的redis冲突,导致无法登陆-->
    <bean id="jedisPoolConfig2" class="redis.clients.jedis.JedisPoolConfig">
        <!--最大连接池数 默认是8-->
        <property name="maxTotal" value="1000"/>
        <!--最大空闲连接数 默认是8-->
        <property name="maxIdle" value="500"/>
        <!--最大等待时间 毫秒为单位  设置为10秒钟-->
        <property name="maxWaitMillis" value="10000"/>
        <property name="testOnBorrow" value="true"/>
    </bean>

    <bean id="jedis.shardInfo2" class="redis.clients.jedis.JedisShardInfo">
        <constructor-arg index="0" value="${project.redis.host1}"/>
        <constructor-arg index="1" value="${project.redis.port1}"/>
    </bean>

    <bean id="shardedJedisPool2" class="redis.clients.jedis.ShardedJedisPool">
        <constructor-arg index="0" ref="jedisPoolConfig2"/>
        <constructor-arg index="1">
            <list>
                <ref bean="jedis.shardInfo2"/>
            </list>
        </constructor-arg>
    </bean>
    <bean id="orderRedisUtil" class="com.b2c.dtms.common.cache.RedisUtilsImpl">
        <property name="shardedJedisPool" ref="shardedJedisPool2"/>
        <property name="selectDB" value="${orders.cache.redis.selectDB}" />
    </bean>
    <bean id="cachePool" class="com.b2c.dtms.common.cache.CachePool">
        <property name="cacheTime" value="${orders.cache.time}"/>
        <property name="redisUtils" ref="orderRedisUtil"/>
    </bean>

    <!-- dummy cacheManager  -->
    <bean id="cacheManager" class="org.springframework.cache.support.CompositeCacheManager">
        <property name="cacheManagers">
            <list>
                <ref bean="simpleCacheManager" />
            </list>
        </property>
        <property name="fallbackToNoOpCache" value="true" />
    </bean>
    <bean id="simpleCacheManager" class="org.springframework.cache.support.SimpleCacheManager">
        <property name="caches">
            <set>
                <!--10秒缓存-->
                <bean class="org.springframework.data.redis.cache.RedisCache">
                    <constructor-arg name="name" value="tenSecond"/>
                    <constructor-arg name="prefix" value=""/>
                    <constructor-arg name="redisOperations" ref="cache.template"/>
                    <!--过期时间:秒-->
                    <constructor-arg name="expiration" value="10"/>
                </bean>
                <!--1分钟缓存-->
                <bean class="org.springframework.data.redis.cache.RedisCache">
                    <constructor-arg name="name" value="oneMinutes"/>
                    <constructor-arg name="prefix" value=""/>
                    <constructor-arg name="redisOperations" ref="cache.template"/>
                    <!--过期时间:秒-->
                    <constructor-arg name="expiration" value="60"/>
                </bean>
                <!--5分钟缓存-->
                <bean class="org.springframework.data.redis.cache.RedisCache">
                    <constructor-arg name="name" value="fiveMinutes"/>
                    <constructor-arg name="prefix" value=""/>
                    <constructor-arg name="redisOperations" ref="cache.template"/>
                    <!--过期时间:秒-->
                    <constructor-arg name="expiration" value="300"/>
                </bean>
                <!-- 10分钟缓存-->
                <bean class="org.springframework.data.redis.cache.RedisCache">
                    <constructor-arg name="name" value="tenMinutes"/>
                    <constructor-arg name="prefix" value=""/>
                    <constructor-arg name="redisOperations" ref="cache.template"/>
                    <!--过期时间:秒-->
                    <constructor-arg name="expiration" value="600"/>
                </bean>
                <!-- 30分钟缓存-->
                <bean class="org.springframework.data.redis.cache.RedisCache">
                    <constructor-arg name="name" value="thirtyMinutes"/>
                    <constructor-arg name="prefix" value=""/>
                    <constructor-arg name="redisOperations" ref="cache.template"/>
                    <!--过期时间:秒-->
                    <constructor-arg name="expiration" value="1800"/>
                </bean>
                <!--基于 java.util.concurrent.ConcurrentHashMap 的一个内存缓存实现方案-->
                <bean class="org.springframework.cache.concurrent.ConcurrentMapCache">
                    <constructor-arg index="0" value="default"/>
                </bean>
            </set>
        </property>
    </bean>
    <bean id="cacheKeyGenerator" class="com.b2c.dtms.common.tools.CacheKeyGenerator">
        <property name="prefix" value="${orders.cache.main.key}"/>
    </bean>

    <bean id="stringRedisSerializer" class="com.b2c.dtms.common.tools.StringRedisSerializer">
        <property name="prefix" value="${orders.cache.main.key}"/>
    </bean>

    <bean id="cache.connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <property name="shardInfo" ref="jedis.shardInfo2" />
        <property name="poolConfig" ref="jedisPoolConfig2" />
        <property name="usePool" value="true" />
        <property name="database" value="${orders.cache.redis.selectDB}" />
    </bean>
    <bean id="cache.template" class="org.springframework.data.redis.core.RedisTemplate">
        <property name="connectionFactory" ref="cache.connectionFactory" />
        <property name="keySerializer" ref="stringRedisSerializer" />
        <property name="hashKeySerializer" ref="stringRedisSerializer" />
    </bean>

</beans>