Redis Set, serialized cache

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.