详解复述,与春天的整合(使用缓存)

  

<强> 1,实现目标
  

  

通过复述,缓存数据。(目的不是加快查询的速度,而是减少数据库的负担)

  

<强> 2,所需的jar包
  

  

详解复述,与春天的整合(使用缓存)

  

注意:jdies和commons-pool两个jar的版本是有对应关系的,注意引入jar包是要配对使用,否则将会报错。因为commons-pooljar的目录根据版本的变化,目录结构会变。前面的版本是org.apache.pool,而后面的版本是org.apache.pool2…

  

3,复述,简介

  

复述是一个键值存储系统。和Memcached类似,它支持存储值的类型相对更多,包括字符串(字符串),列表(链表),设置集(合),zset(排序设置——有序集合)和散列(哈希类型)。这些数据类型都支持推/流行,添加/删除及取交集并集和差集及更丰富的操作,而且这些操作都是原子性的。在此基础上,复述,支持各种不同方式的排序。与Memcached一样,为了保证效率,数据都是缓存在内存中。区别的是复述,会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在此基础上实现了主从(主从)

  

<强> 3,编码实现

  

1),配置的文件(属性)

  

将那些经常要变化的参数配置成独立的同时,方便以后的修改redis.properties

        redis.hostName=127.0.0.1      redis.port=6379      redis.timeout=15000      redis.usePool=true      redis.maxIdle=6      redis.minEvictableIdleTimeMillis=300000      redis.numTestsPerEvictionRun=3      redis.timeBetweenEvictionRunsMillis=60000   之前      

2), spring-redis.xml

  

复述的相关参数配置设置。参数的值来自上面属性的文件

        & lt;豆类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=氨鹈北?      & lt; bean id=癹edisPoolConfig”类=皉edis.clients.jedis.JedisPoolConfig”比;      & lt; !——& lt;属性名=" maxIdle " value=" https://www.yisu.com/zixun/6 "祝辞& lt;/property>      & lt;属性名=" minEvictableIdleTimeMillis " value=" https://www.yisu.com/zixun/300000 "祝辞& lt;/property>      & lt;属性名=" numTestsPerEvictionRun " value=" https://www.yisu.com/zixun/3 "祝辞& lt;/property>      & lt;属性名=" timeBetweenEvictionRunsMillis " value=" https://www.yisu.com/zixun/60000 "祝辞& lt;/property>——比;   & lt;属性名=" maxIdle " value=" https://www.yisu.com/zixun/$ {redis.maxIdle} "祝辞& lt;/property>      & lt;属性名=" minEvictableIdleTimeMillis " value=" https://www.yisu.com/zixun/$ {redis.minEvictableIdleTimeMillis} "祝辞& lt;/property>      & lt;属性名=" numTestsPerEvictionRun " value=" https://www.yisu.com/zixun/$ {redis.numTestsPerEvictionRun} "祝辞& lt;/property>      & lt;属性名=" timeBetweenEvictionRunsMillis " value=" https://www.yisu.com/zixun/$ {redis.timeBetweenEvictionRunsMillis} "祝辞& lt;/property>      & lt;/bean>      & lt; bean id=癹edisConnectionFactory”类=" org.springframework.data.redis.connection.jedis。JedisConnectionFactory摧毁“销毁方法=比;      & lt;属性名=" poolConfig“ref=癹edisPoolConfig祝辞& lt;/property>      & lt;属性名="主机" value=" https://www.yisu.com/zixun/$ {redis.hostName} "祝辞& lt;/property>      & lt;属性名="端口" value=" https://www.yisu.com/zixun/$ {redis.port} "祝辞& lt;/property>      & lt;属性名="超时" value=" https://www.yisu.com/zixun/$ {redis.timeout} "祝辞& lt;/property>      & lt;属性名=" usePool " value=" https://www.yisu.com/zixun/$ {redis.usePool} "祝辞& lt;/property>      & lt;/bean>      & lt; bean id=癹edisTemplate”类=皁rg.springframework.data.redis.core.RedisTemplate”比;      & lt;属性名=" connectionFactory“ref=癹edisConnectionFactory祝辞& lt;/property>      & lt;属性名=発eySerializer”比;      & lt; bean类=" org.springframework.data.redis.serializer.StringRedisSerializer "/比;      & lt;/property>      & lt;属性名=皏alueSerializer”比;      & lt; bean类=" org.springframework.data.redis.serializer.JdkSerializationRedisSerializer "/比;      & lt;/property>      & lt;/bean>      & lt;/beans>      

详解复述,与春天的整合(使用缓存)