<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:redis="http://www.springframework.org/schema/redis"
    xsi:schemaLocation="
        http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo-1.8.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
        http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd" 
    default-lazy-init="true"> 
    
    <!-- jedis 配置 -->
    <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
      <!-- 最小空闲连接数 -->
	    <property name="minIdle" value="${redis.minIdle}" />
		<!-- 最大空闲连接数 -->
		<property name="maxIdle" value="${redis.maxIdle}" />
		<!-- 最大连接数 -->
		<property name="maxTotal" value="${redis.maxTotal}" />
		<!-- 获取连接时的最大等待毫秒数 -->
		<property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
		<!-- 连接超时时是否阻塞，false时报异常,ture阻塞直到超时, 默认true -->
		<property name="blockWhenExhausted" value="${redis.blockWhenExhausted}" />
		<!-- 在获取连接的时候检查有效性 -->
		<property name="testOnBorrow" value="${redis.testOnBorrow}" />
		<!-- 在空闲时检查有效性 -->
		<property name="testWhileIdle" value="${redis.testWhileIdle}" />
		<!-- 在空闲时检查有效性 -->
		<property name="testOnReturn" value="${redis.testOnReturn}" />

		<!-- 连接释放策略: 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1 -->
		<property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}" />
		<!-- 连接释放策略: 每次逐出检查时 逐出的最大数目 如果为负数就是 : 1/abs(n), 默认3 -->
		<property name="numTestsPerEvictionRun" value="${redis.numTestsPerEvictionRun}" />
		<!-- 连接释放策略: 逐出连接的最小空闲时间 -->
		<property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}" />
		<!-- 连接释放策略: 对象空闲多久后逐出, 当空闲时间>该值 且 空闲连接>最大空闲数 时直接逐出,不再根据MinEvictableIdleTimeMillis判断  (默认逐出策略)  -->
		<property name="softMinEvictableIdleTimeMillis" value="${redis.softMinEvictableIdleTimeMillis}" />
    </bean>
    <bean id="JedisConnectionFactory" 
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
       <!-- IP地址 -->
		<property name="hostName" value="${redis.host}" />
		<!-- 端口号 -->
		<property name="port" value="${redis.port}" />
		<!-- redis密码 -->
		<property name="password" value="${redis.password}" />
		<!-- 基础数据数据库 -->
		<property name="database" value="${redis.baseDataDB}" />
		<!-- 超时时间 默认2000 -->
		<property name="timeout" value="${redis.timeout}" />
		<!-- 连接池配置引用 -->
		<property name="poolConfig" ref="poolConfig" />
		<!-- usePool：是否使用连接池 -->
		<property name="usePool" value="true" />
    </bean>
    <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
        <property name="connectionFactory" ref="JedisConnectionFactory" />
        <!-- 将key和value序列化后存入redis，读取时再进行反序列化 -->
        <!-- 对key的默认序列化器 -->
        <property name="keySerializer">
            <bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
        </property>
        <!-- 对value的默认序列化器 -->
        <property name="valueSerializer">
            <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>
        </property>
        <!-- 对hash结构数据的hashkey的默认序列化器 -->
        <property name="hashKeySerializer">
            <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
        </property>
        <!-- 对hash结构数据的hashvalue的默认序列化器 -->
        <property name="hashValueSerializer">
            <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
        </property>
    </bean>

</beans>