注意:本章代码将会建立在上一章的代码基础上,上一章链接《第八章 企业项目开发--分布式缓存memcached

1、为什么用Redis

1.1、为什么用分布式缓存(或者说本地缓存存在的问题)?

1.2、有了memcached,为什么还要用redis?

 

2、代码实现

2.1、ssmm0

第九章 企业项目开发--分布式缓存Redis(1)

pom.xml

只在dev环境下添加了以下代码:

                <!-- 
                    redis:多台服务器支架用什么符号隔开无所谓,只要在程序中用相应的符号去分隔就好。
                    这里只配置了一个redis.servers,如果系统特别大的时候,可以为每一种业务或某几种业务配置一个redis.xxx.servers 
                -->
                <redis.servers><![CDATA[127.0.0.1:6379]]></redis.servers>
                <!-- 
                    下边各个参数的含义在RedisFactory.java中有介绍,
                    当我们三种环境(dev/rc/prod)下的一些参数都相同时,可以将这些参数直接设置到cache_conf.properties文件中去
                -->
                <redis.timeout>2000</redis.timeout><!-- 操作超时时间:2s,单位:ms -->
                <redis.conf.lifo>true</redis.conf.lifo>
                <redis.conf.maxTotal>64</redis.conf.maxTotal>
                <redis.conf.blockWhenExhausted>true</redis.conf.blockWhenExhausted>
                <redis.conf.maxWaitMillis>-1</redis.conf.maxWaitMillis>
                
                <redis.conf.testOnBorrow>false</redis.conf.testOnBorrow>
                <redis.conf.testOnReturn>false</redis.conf.testOnReturn>
                
                <!-- 空闲连接相关 -->
                <redis.conf.maxIdle>8</redis.conf.maxIdle>
                <redis.conf.minIdle>0</redis.conf.minIdle>
                <redis.conf.testWhileIdle>true</redis.conf.testWhileIdle>
                <redis.conf.timeBetweenEvictionRunsMillis>30000</redis.conf.timeBetweenEvictionRunsMillis><!-- 30s -->
                <redis.conf.numTestsPerEvictionRun>8</redis.conf.numTestsPerEvictionRun>
                <redis.conf.minEvictableIdleTimeMillis>60000</redis.conf.minEvictableIdleTimeMillis><!-- 60s -->
View Code

相关文章:

  • 2021-09-21
  • 2021-12-05
  • 2021-11-25
  • 2021-06-23
  • 2021-07-01
  • 2021-04-23
猜你喜欢
  • 2022-01-23
  • 2021-06-10
  • 2021-08-21
  • 2021-12-04
  • 2021-06-06
相关资源
相似解决方案