标签:dream article tab pool value config hostname org xmlns
1、redis是一个nosql的数据库,操作内存数据,并可以将其存储到硬盘中来持久化
2、与spring的整合 http://www.cnblogs.com/holdouts/articles/5811118.html
需要jar包common-pool2.jar jedis.jar spring-data-redis.jar
spring 配置文件
<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="maxIdle" value="${redis.maxIdle}"></property>
<property name="minEvictableIdleTimeMillis" value="${redis.minEvictableIdleTimeMillis}"></property>
<property name="numTestsPerEvictionRun" value="${redis.numTestsPerEvictionRun}"></property>
<property name="timeBetweenEvictionRunsMillis" value="${redis.timeBetweenEvictionRunsMillis}"></property>
</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.hostName}"></property>
<property name="port" value="${redis.port}"></property>
<property name="timeout" value="${redis.timeout}"></property>
<property name="usePool" value="${redis.usePool}"></property>
</bean>
<bean id="jedisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory"></property>
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer" /> //代表redis的key/value需要序列化 若是实体类,实体类需要实现序列化
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
</property>
</bean>
</beans>
@Autowired
@Qualifier("jedisTemplate")
public RedisTemplate redisTemplate;
需要redis的类中,可以注入redisTemplate
有5种数据操作方式
redisTemplate.opsForValue();//操作字符串
redisTemplate.opsForHash();//操作hash
redisTemplate.opsForList();//操作list
redisTemplate.opsForSet();//操作set
redisTemplate.opsForZSet();//操作
作者:DreamerRzc
链接:http://www.jianshu.com/p/7bf5dc61ca06
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
作者:DreamerRzc
链接:http://www.jianshu.com/p/7bf5dc61ca06
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
标签:dream article tab pool value config hostname org xmlns
原文地址:http://www.cnblogs.com/happy0120/p/7688091.html