发表于: 2017-12-25 23:21:03

1 592


今天完成的事情:

当然是做redis拉。。。。可是居然断网了。。。然后就愉快的打起来狼人杀杀杀~~~

尝试用配置去做redis,和memcache实现的方法类似。下面总结一点相关的东西。

//配置

<!--redis 配置-->

<bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig">
   <property name="maxIdle" value="300" />
   <property name="maxWait" value="10000" />
   <property name="testOnBorrow" value="true" />
</bean>
<bean id="connectionFactory"
     class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
   <property name="poolConfig" ref="poolConfig" />
   <property name="port" value="6379" />
   <property name="hostName" value="192.168.242.130" />
   <!--<property name="password" value="${redis.pass}" />-->
   <property name="timeout" value="100000" />
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
   <property name="connectionFactory" ref="connectionFactory" />
   <!-- 如果不配置Serializer,那么存储的时候只能使用String,如果用对象类型存储,那么会提示错误 -->
   <property name="keySerializer">
       <bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
   </property>
   <property name="valueSerializer">
       <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
   </property>

</bean>


Jedis的应用。这会报连接超时?? 糟糕,这边停网,没解决问题,还挺麻烦。

Jedis jedis = new Jedis("92.168.242.130",6379);
if(jedis.get("student".getBytes())==null){
student = studentMapper.getStudent(id);
   byte[] bytes= SerializeUtil.serialize(student);
   jedis.set("student".getBytes(),bytes);
   System.out.println("存入一个student对象"+bytes);
   return student;
}else {
byte[] bytes = jedis.get("student".getBytes());
   student =(Student) SerializeUtil.unserialize(bytes);
   System.out.println("存入一个student对象"+student);
   return student;
}



明天计划的事情:

解决任务六  把这个redis给应用起来、
遇到的问题:

无法远程连接服务器的redis
收获:

初步学习redis


返回列表 返回列表
评论

    分享到