发表于: 2017-08-03 23:10:01

1 1111


今天完成的事:

       配置好Redis但是进行压测的时候,仅有几十条数据成功剩下的全部error

      

     判断是连接池的问题

     连接池的配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">

   <!-- 引入配置文件 其中order属性代表其加载顺序,而ignoreUnresolvablePlaceholders为是否忽略不可解析的Placeholder,如配置了多个PropertyPlaceholderConfigurer,则需设置为true -->
   <bean id="propertyConfigurerJedis"
         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
       <property name="order" value="2" />
       <property name="ignoreUnresolvablePlaceholders" value="true" />
       <property name="location">
           <value>classpath:redis.properties</value>
       </property>
   </bean>

   <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
       <property name="maxIdle" value="${redis.maxIdle}" />
       <property name="minIdle" value="${redis.minIdle}" />
       <property name="maxTotal" value="${redis.maxTotal}" />
       <property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
       <property name="testOnBorrow" value="${redis.testOnBorrow}" />
   </bean>

   <bean id="jedisConnectionFactory"
         class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
       <property name="hostName" value="${redis.host}" />
       <property name="port" value="${redis.port}" />
       <property name="password" value="" />
       <property name="database" value="${redis.default.db}"/>
       <constructor-arg index="0" ref="jedisPoolConfig" />
   </bean>

   <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
       <property name="connectionFactory" ref="jedisConnectionFactory" />
   </bean>
</beans>

#redis的服务器地址

redis.host=127.0.0.1
#redis的服务端口
redis.port=6379
#最大空闲数
redis.maxIdle=400
#最小空闲数
redis.minIdle=0
#链接数据库
redis.default.db=0
#最大连接数
redis.maxTotal=400
#最大建立连接等待时间
redis.maxWaitMillis=200
#指明是否在从池中取出连接前进行检验,如果检验失败,则从池中去除连接并尝试取出另一个
redis.testOnBorrow=true

重写get方法

@Override
public Category get(Category category) {
Category c = new Category();
   String key = "category_id("+category.getId()+")";
   c = (Category) SerializeUtil.unserialize(jedis.get(key.getBytes()));
   System.out.println("从缓存中读取");
   /**从缓存中读取如果为空则从数据库中读取*/
   if(c == null){
    System.out.println("从数据库中读取");
       c = categoryMapper.get(category);
       if(c != null){
           jedis.set(key.getBytes(), SerializeUtil.serialize(c));  
       }
}
return c;
}

崩溃错误

Exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Connection reset by peer: socket write error
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Root Cause


遇到的困难:

      以上

收获:

     学会配置Redis,感觉腰快断了

明天计划:

     发呆,或者继续做任务


返回列表 返回列表
评论

    分享到