redis integration development 2 (integration)

1. Add in pom.xml file, use spring-data-redis package component here.

<!-- spring-data-redis 集成依赖 -->
<dependency>
    <
groupId>org.springframework.data</groupId>
    <
artifactId>spring-data-redis</artifactId>
    <
version>1.8.4.RELEASE</version>
</
dependency><!--redis 集成依赖  --><dependency><groupId>redis.clients</groupId><artifactId>



   

   
jedis</artifactId>
    <
version>2.9.0</version>
</
dependency>

 

2. Add configuration in the Spring xml file of spring-applicatioin.xml:

<!--redis 配置start  -->
<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
    <
property name="maxIdle" value="${redis.maxIdle}" /><!--<property name="maxActive" value="${redis.maxActive}" />     <property name="maxWait" value="${redis.maxWait}" />--><property name="testOnBorrow" value="${redis.testOnBorrow}" /></bean><bean id="connectionFactory" class
   


   



="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
     
p:host-name="${redis.host}"
     
p:port="${redis.port}"
     
p:password="${redis.pass}"
     
p:pool-config-ref="poolConfig"/>

<
bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
    <
property name="connectionFactory"   ref="connectionFactory" />
</
bean><!-- redis end-->configuration

 

3. Add the account and password configuration of redis to the Properties file :

 

# Redis settings
redis.host=127.0.0.1
redis.port=6379
redis.pass=

redis.maxIdle=300
redis.maxActive=600
redis.maxWait=1000
redis.testOnBorrow=true

 

At this point, redis has been integrated into the project. . The next step is to use redisTemplate in the project to operate data access redis .

 

Guess you like

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