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

	<!-- redis template definition -->
	<bean id="searchStringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />

	<!-- pool config -->
	<bean id="searchJedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
		<property name="maxTotal" value="${redis.pool.maxTotal:50}" />
		<property name="maxIdle" value="${redis.pool.maxIdle:20}" />
		<property name="minIdle" value="${redis.pool.minIdle:20}"></property>
		<property name="maxWaitMillis" value="${redis.pool.maxWaitMillis:2000}" />
		<property name="testOnBorrow" value="${redis.pool.testOnBorrow:false}" />
		<property name="testWhileIdle" value="${redis.pool.testWhileIdle:false}"></property>
	</bean>

	<!-- 连接池 -->
	<bean id="searchJedisConnectionFactory"
		class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
		p:timeout="100" 
		p:poolConfig-ref="searchJedisPoolConfig"
		p:hostName="${redis.search.proxy.address}" 
		p:port="${redis.search.proxy.port}"
		p:password="${redis.search.proxy.auth}" primary="true" />

	<!-- 读写模板 -->
	<bean id="searchRedisTemplate" class="com.yoho.core.redis.YHRedisTemplate"
		primary="true" 
		p:connectionFactory-ref="searchJedisConnectionFactory"
		p:keySerializer-ref="searchStringRedisSerializer"
		p:valueSerializer-ref="searchStringRedisSerializer"
		p:hashKeySerializer-ref="searchStringRedisSerializer"
		p:hashValueSerializer-ref="searchStringRedisSerializer"
		p:redisCacheClean-ref="redisCacheClean" />
	
	<!-- 只读模板 -->
	<bean id="searchRedisTemplateReadOnly" class="com.yoho.core.redis.YHRedisTemplate"
		primary="false" 
		p:connectionFactory-ref="searchJedisConnectionFactory"
		p:keySerializer-ref="searchStringRedisSerializer"
		p:valueSerializer-ref="searchStringRedisSerializer"
		p:hashKeySerializer-ref="searchStringRedisSerializer"
		p:hashValueSerializer-ref="searchStringRedisSerializer"
		p:redisCacheClean-ref="redisCacheClean" />
	
	<bean id="searchValueOperations" class="com.yoho.core.redis.YHValueOperations"
		primary="true" 
		p:valueOperations-ref="searchRedisTemplate"
		p:valueOperationsReadOnly-ref="searchRedisTemplateReadOnly"
		p:redisCacheClean-ref="redisCacheClean" />
	
	<bean id="searchHashOperations" class="com.yoho.core.redis.YHHashOperations"
		primary="true" 
		p:hashOperations-ref="searchRedisTemplate"
		p:hashOperationsReadOnly-ref="searchRedisTemplateReadOnly"
		p:redisCacheClean-ref="redisCacheClean" />
		
</beans>