The implements needs to be serialized first Serializable
Arraylist<room> List=null;
Roomlist = Getdaoroomlistdata (filterparams, sort, order, skip, limit);
list<string> ridlist = new ArrayList ();
//
=========================================================
for (roomr:roomlist) {
String Strkeyrid=key+roomr.getrid ();
map<string,?> parse = Document.parse (json.tojsonstring (ROOMR));
Helper.setroomone (STRKEYRID,ROOMR);//deposit in cache with one entity
}
Map redismap=new HashMap ();
Helper.setroomlist (keys,roomlist);//Save list in cache
The =============== cache gets the entity, which is serialized to show the ========================= directly
if (roomlistone.size () > 0) {
Room=roomlistone.get (0);
String Roomid=room.getrid ();
String Keyroomid=key+roomid;
Roomone=helper.getroomone (Keyroomid);
if (Null!=roomone) {
Roomlist.add (Roomone);
Flagroomone=false;
}
}
================ gets the list, which is serialized to show the ================== directly
Roomlist =helper.getroomlist (keys);
=========================================================
/**
* Get data from cache
* @param UID
* @return List
*/
@SuppressWarnings ("Unchecked")
Public Getroomone (String key) {
Levellist = new ();
Jedis Jedis = null;
try {
Jedis = Jedispoolutil.getinstance (). Getcocosjedis ();
byte[] bs = Jedis.get (Key.getbytes ());
if (null! = BS) {
Levellist = (guest) unserialize (BS);
}else{
return null;
}
} catch (Exception e) {
E.printstacktrace ();
} finally {
if (null! = Jedis)
Jedis.close ();
}
return levellist;
}
/**
* Get room list data from cache
* @param UID
* @return List
*/
@SuppressWarnings ("Unchecked")
Public arraylist<room> getroomlist (String keys) {
arraylist<room> levellist = new arraylist<room> ();
Jedis Jedis = null;
try {
Jedis = Jedispoolutil.getinstance (). Getcocosjedis ();
byte[] bs = Jedis.get (Keys.getbytes ());
if (null! = BS) {
Levellist = (arraylist<room>) unserialize (BS);
}else{
return null;
}
} catch (Exception e) {
E.printstacktrace ();
} finally {
if (null! = Jedis)
Jedis.close ();
}
return levellist;
}
/**
* Save room information to cache
* @param UID
* @return List
*/
public void Setroomone (String key,room) {
Jedis Jedis = null;
try {
Jedis = Jedispoolutil.getinstance (). Getcocosjedis ();
Jedis.set (Key.getbytes (), serialize ();
Jedis.expire (key, 24*3600);
} catch (Exception e) {
E.printstacktrace ();
} finally {
if (null! = Jedis)
Jedis.close ();
}
}
/**
* Save room list information to cache
* @param UID
* @return List
*/
public void Setroomlist (String kes,arraylist<room> roomlist) {
Jedis Jedis = null;
try {
Jedis = Jedispoolutil.getinstance (). Getcocosjedis ();
Jedis.set (Kes.getbytes (), serialize (roomlist));
Jedis.expire (Kes, 24*3600);
} catch (Exception e) {
E.printstacktrace ();
} finally {
if (null! = Jedis)
Jedis.close ();
}
}
Redis Set, serialized cache