<!-- redis配置开始 -->
<!-- 配置JedisPoolConfig实例 -->
<bean id="redisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${redis.maxIdle}" />
<property name="maxTotal" value="${redis.maxActive}" />
<property name="maxWaitMillis" value="${redis.maxWait}" />
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean>
<!-- Spring-redis连接池管理工厂 -->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
<property name="hostName" value="${redis.host}" />
<property name="port" value="${redis.port}" />
<property name="password" value="${redis.pass}" />
<property name="timeout" value="${redis.timeOut}" />
<property name="database" value="${redis.dbIndex}" />
<property name="poolConfig" ref="redisPoolConfig" />
</bean>
<!-- 配置RedisTemplate -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory"/>
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashKeySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>
</property>
<property name="hashValueSerializer">
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>
</property>
</bean>
<!-- 配置SpringRedisTemplate -->
<bean id="StringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory"/>
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashKeySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashValueSerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<!--开启事务 -->
<property name="enableTransactionSupport" value="true"></property>
</bean>
<bean id="redisUtil" class="com.dami.util.redis.RedisUtil">
<property name="redisTemplate" ref="redisTemplate" />
</bean>
<!-- redis共享程序session 连接到Redis服务器 -->
<bean id="redisHttpSessionConfiguration"
class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<property name="maxInactiveIntervalInSeconds" value="1800"/><!-- session过期时间30分钟 -->
<!-- <property name="redisNamespace" value="ianbase"/> -->
<!-- <property name="configureRedisAction" value="NO_OP"/> --><!-- 让Spring Session不再执行config命令 -->
<!-- <property name="httpSessionListeners">
<list>
<ref bean="RedisSessionListener" />
</list>
</property> -->
</bean>
<!-- SpringSession 监听(session创建,销毁) -->
<bean id="RedisSessionListener" class="org.springframework.session.web.http.SessionEventHttpSessionListenerAdapter">
<constructor-arg name="listeners">
<list>
<bean class="com.dami.util.SessionListener" />
</list>
</constructor-arg>
</bean>
<!-- Spring实现redis键失效监听 -->
<bean id="messageListener" class="org.springframework.data.redis.listener.adapter.MessageListenerAdapter">
<constructor-arg>
<bean class="com.dami.util.redis.RedisMessageDelegateImpl"/>
</constructor-arg>
</bean>
<bean id="redisContainer" class="org.springframework.data.redis.listener.RedisMessageListenerContainer">
<property name="connectionFactory" ref="jedisConnectionFactory"/>
<property name="messageListeners">
<map>
<entry key-ref="messageListener">
<bean class="org.springframework.data.redis.listener.ChannelTopic">
<constructor-arg value="__keyevent@0__:expired"/>
</bean>
</entry>
</map>
</property>
</bean>
<!-- redis配置结束 -->