spring+ redis

<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">

    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">

        <property name="maxTotal" value="1000" />

        <property name="testOnBorrow" value="true" />

        <property name="testWhileIdle" value="true" />

        <property name="minIdle" value="10" />

        <property name="maxIdle" value="50" />

        <property name="maxWaitMillis" value="5000" />

    </bean>

    <bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" destroy-method="destroy">

        <property name="poolConfig" ref="jedisPoolConfig"></property>

        <property name="hostName" value="${redis.host}"></property>

        <property name="port" value="${redis.port}"></property>

        <property name="password" value=""></property>

        <property name="timeout" value="15000"></property>

        <property name="usePool" value="true"></property>

    </bean>

    <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">

        <property name="connectionFactory" ref="jedisConnectionFactory"></property>

        <property name="defaultSerializer">

            <bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>//使用不同的序列化方式,这个里的value只能是json格式数据

        </property>

    </bean>

    <bean id="jdkRedisTemplate" class="org.springframework.data.redis.core.RedisTemplate">

        <property name="connectionFactory" ref="jedisConnectionFactory"></property>

        <property name="defaultSerializer">

            <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>//value可以是任意类型

        </property>

    </bean>

</beans>


你可能感兴趣的:(spring+ redis)