发表于: 2017-12-26 17:24:26
1 644
今天完成的事情:
电信还是听讲信用,早上没网,打电话说中午来,中午真的就来了,然后去吃了个午饭,睡了一觉,醒来,玛德又断了。。。电信还是牛逼~~~~~
搞定了redis。。之前莫名其妙连接redis 会connect timeout 去改了一哈 配置文件 把默认的bind地址给注释掉,然后重启了服务,试了试连接上了。
电信真的喜剧。
然后看一看impl层的代码。这一次只是对单个数据进行了操作。
这里存在redis中的是单个student对象,需要用student id 来加以区分,所以最后的代码如下:
//嗯 这样任务六用redis也做出来了。提交一下任务六,师兄审核一下。
Student student= null;
Jedis jedis = new Jedis("101.132.166.168",6379);
if(jedis.get(("student"+id).getBytes())==null){
student = studentMapper.getStudent(id);
System.out.println(student);
byte[] bytes= SerializeUtil.serialize(student);
jedis.set(("student"+id).getBytes(),bytes);
System.out.println("存入一个id为"+id+"的student对象"+bytes);
return student;
}else {
byte[] bytes = jedis.get(("student"+id).getBytes());
student =(Student) SerializeUtil.unserialize(bytes);
System.out.println("取出一个id为"+id+"的student对象"+student);
return student;}
再贴一下序列化和反序列化的东西吧,这个还挺有用的。目前
public static byte[] serialize(Object object){
ObjectOutputStream oos = null;
ByteArrayOutputStream baos= null;
try {
// 序列化
baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
oos.writeObject(object);
byte[] bytes = baos.toByteArray();
return bytes;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static Object unserialize( byte[] bytes) {
ByteArrayInputStream bais = null;
try {
// 反序列化
bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
return ois.readObject();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}大概就差不多是这样,然后开始着手任务七吧。感觉自己最近进度很慢了。没做太多事情。应该加快自己的节奏了。
明天计划的事情:
继续任务七
遇到的问题:
主要是断网啊~~很托节奏的啊啊啊 本来昨天就可以做完了~
收获:
学会了redis的基本操作,这个还挺好~
评论