Redis configuration in Spring

in pom.xml:

< dependency >
     < groupId > org.springframework.data </ groupId >
     < artifactId > spring-data-redis </ artifactId >
     < version > 1.4.1.RELEASE </ version >
 </ dependency >
 < dependency >
     < groupId > redis .clients </ groupId >
     < artifactId > jedis </ artifactId >
     <> 2.6.2 </ version >
 </ dependency >

applicationContext-redis.xml:

< beans xmlns =“http://www.springframework.org/schema/beans”
 xmlns:context =“http://www.springframework.org/schema/context” xmlns:p =“http://www.springframework .org / schema / p“
 xmlns:aop =”http://www.springframework.org/schema/aop“ xmlns:tx =”http://www.springframework.org/schema/tx“
 xmlns:xsi =” http://www.w3.org/2001/XMLSchema-instance “
 的xsi :的schemaLocation =” http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-豆类,4.0.xsd
                               http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
     http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop /www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0 .xsd
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd " >
  <!--Connection pool configuration->
  < bean id = "jedisPoolConfig" class = "redis.clients.jedis.JedisPoolConfig" >
  <!- max connections ->
  < property name = "maxTotal" value = "${redis. maxTotal}"/>

                                <! - max wait time ->
  < property name ="maxWaitMillis" value ="${redis.maxWaitMillis}" />
  <! - Check validity when getting connection ->
  < property name ="testOnBorrow" value ="${redis.testOnBorrow}" />
      </ bean >
  <! - Jedis connection factory ->
  < bean id ="jedisConnectionFactory"
  class ="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" >
  <! - Configuration of connection pool ->
  <<! - host address ->
                        
                                                  < property name ="hostName" value ="${redis.hostName}" />
  <! - port ->
  < property name ="port" value ="${redis.port}" />
  <! - Whether connection pooling is enabled ->
  < property name ="usePool" value ="${redis.usePool}" />
      </ bean >
  <! - RedisTemplate template of type String ->
  < bean id ="stringRedisTemplate" class ="org.springframework.data.redis.core.StringRedisTemplate" >
         < constructor-argindex =“0”                                
        ref =“jedisConnectionFactory” />
     </ bean >
 </ beans >
redis.properties中:

redis.maxTotal = 200
 redis.maxWaitMillis = 1000
 redis.testOnBorrow = true
 redis.hostName = 192.168.206.101
 redis.port = 6379
 redis.usePool = true

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325583711&siteId=291194637