发表于: 2017-11-14 23:27:07
1 766
今天完成的事情
将redis的连接池配置到spring中
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxTotal" value="50"/>
<property name="maxIdle" value="100"/>
<property name="maxWaitMillis" value="1000"/>
<property name="testOnBorrow" value="true"/>
</bean>
<bean id="jedisPool" class="redis.clients.jedis.JedisPool" destroy-method="destroy"
depends-on="jedisPoolConfig">
<constructor-arg name="poolConfig" ref="jedisPoolConfig"/>
<constructor-arg name="host" value="127.0.0.1"/>
<constructor-arg name="port" value="6379" />
</bean>
控制器中:
@RequestMapping("/12")
public String jsp_redis(Model model){
Student student = null;
Jedis jedis = jedisPool.getResource();
student =(Student) SerializeUtil.unserialize(jedis.get("1".getBytes()));
if (student==null) {
student = studentService.get(1);
int i = student.getID();
String k = i + "";
jedis.set(k.getBytes(),SerializeUtil.serialize(student));
}
int count=0;
if (count%3==0)
jedis.flushAll();
count++;
jedisPool.returnResource(jedis);
model.addAttribute("student",student);
return "12";
}
然后进行测试,开20个线程:
错误率很高,尝试排查问题
将控制器中的向DB获取数据部分注释掉,查看单纯从缓存中获取数据时的情况:
还是不行:
将线程改为2,进行测试:
很快,而且全部成功,推测是因为并发问题,可能是reids没有配置好。
查了一下,reids的windows版是由微软修改原始redis开发来的,可能是由于没配置好,导致性能低下。
明天的计划
重新配置一下redis,看看效果
遇到的问题
如上
收获
redis连接池的配置
评论