Redis存储list对象
来源:互联网 发布:磁条卡写卡软件 编辑:程序博客网 时间:2024/05/16 05:13
public class JdModel implements Serializable{private String bookID; private String bookName; private String bookPrice; public String getBookID() { return bookID; } public void setBookID(String bookID) { this.bookID = bookID; } public String getBookName() { return bookName; } public void setBookName(String bookName) { this.bookName = bookName; } public String getBookPrice() { return bookPrice; } public void setBookPrice(String bookPrice) { this.bookPrice = bookPrice; }}
public class SerializeUtil {public static byte[] serializeListObject(List<?> object) { ObjectOutputStream oos = null; ByteArrayOutputStream baos = null; try { // 序列化 baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); //oos.writeObject(object); for(Object obj : object){ oos.writeObject(obj); } byte[] bytes = baos.toByteArray(); return bytes; } catch (Exception e) { } return null; }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) { } 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) { } return null; } public static List<Object> deserialize(byte[] in) { List<Object> list = new ArrayList(); ByteArrayInputStream bis = null; ObjectInputStream is = null; try { if(in != null) { bis=new ByteArrayInputStream(in); is=new ObjectInputStream(bis); while (true) { Object obj=(Object) is.readObject(); if(obj == null){ break; }else{ list.add(obj); } } is.close(); bis.close(); } } catch (IOException e) { } catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally { } return list; } }
jedis.set("jdModelList".getBytes(), SerializeUtil.serializeListObject(bookdatas)); byte[] in = jedis.get("jdModelList".getBytes()); List<Object> list = SerializeUtil.deserialize(in); for(int i=0;i<list.size();i++){ JdModel model= (JdModel)list.get(i); System.out.println(model.getBookName()); }
阅读全文
0 0
- Redis 存储List对象
- Redis 存储List对象
- Redis 存储List对象
- Redis 存储List对象
- Redis 存储List对象
- Redis存储list对象
- Redis存储list对象
- Redis 存储List对象
- redis jedis存储对象简单操作,map list 自定义对象
- redis 存储对象
- Redis存储Java对象
- List存储Java对象
- List存储Java对象
- redis存储list工具类
- Redis存储List<T>集合
- Redis存储数据类型二:List
- Redis缓存Object,List对象
- redis存储对象的方法
- 杭电 1171 Big Event in HDU(606比赛选拔 2017-08-20)(1003)
- Android include注意事项
- windows下安装运行rabbitMQ并结合spring框架进行收发消息
- 【POJ】3579
- Python网络爬虫与信息提取-Day8-基于bs4库的HTML格式输出
- Redis存储list对象
- Linux: shell拆分浮点数的整数和小数部分 && 拆分文件的文件名和扩展名
- 什么是Java语言?
- 移动端弱网测试及Chrome前端调试
- 为什么我们要使用Async、Await关键字
- 实用类
- Dying[二分]
- HDU5873Football Games(思维题)
- LNMP1.2及之后版本–添加、删除虚拟主机教程