spring-redis.xml
5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?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>