Http://www.cnblogs.com/linjiqin/archive/2013/06/14/3135921.html
1. Add voting options to Redis's List and HashMap
List key ==> tomas:vote:vote_item:%s:list (PS.%s=voteid)
value==> {Video_hashmap_key}
Map key ==> Tomas:vote:vote_item:%s:hashmap (PS.%s=voteid)
value==> {{id=01;name=001,title=0002, poll number =33.....},{...}}
Map<string, string> map =NewHashmap<string, String> ();
//long size = Voteservice.getcountnewyearvideos (null, Voteid);
Map.put ("AC", Ac;
Map.put ("Vid", "***");
Map.put ("title", Content.gettitle ());
Map.put ("Time", Content.getsortdate (). GetTime ());
Map.put ("Conver", Content.gettitleimg ());
Map.put ("up_id", Content.getuser (). GetId ());
Map.put ("Up_name", Content.getusername ());
Map.put ("Up_icon", Content.getuser (). GETUSERIMG ());
Map.put ("Votecount", "0");
//Add video that is voting options
Long result =Voteservice. Addvoteitem (NULL,Voteid, Map;
/**
* Add video
*
* @paramJedis
* @paramVoteidActivity ID
* @paramparamsac:acid vid:vid name:title cover: Cover Up:upername
* @returnint add complete Video Total
*/
@Override
PublicLongAddvoteitem(Jedis Jedis, Integer Voteid, Map<string, String> params) {
String Video_list_key = This. GETFORMATKEYSTR (all_video_list, Voteid);
String Video_hashmap_key = This. GETFORMATKEYSTR (New_year_video_info_map, Voteid, Params.get ("AC"));
if( This. Isexistinvoteitem (Jedis, Voteid, Params.get ("AC"))) {
return0L;
}
if(StringUtils.IsEmpty(Params.get ("Vid"))) {
jedis.incr (getformatkeystr (all_video_list_indexvoteid)) ; //self-increment ID
}
Add the video information to the paging list Lrange (with) and the map key as the Vlaue page of the list is to query out list
Long all_size = Jedis.lpush (video_list_key, Video_hashmap_key);
//Add video information to HashMap
Jedis.hmset (Video_hashmap_key, Params;
//Set key expiration time
Jedis.expire (Video_hashmap_key, Default_cooldown);
//Set key expiration time
Jedis.expire (Video_list_key, Default_cooldown);
returnAll_size;
}
/**
* Get video paging video
*
* @paramJedis
* @paramVoteidActivity ID
* @paramuserIdUser ID
* @parampageSizePaging Size
* @paramPageNoThe first few pages
* @paramOrderSort Fields
* @paramASCwhether ascending
* @returnList<Map<String,String>> Video Information
*/
PublicList<map<string, String>>Getshapeshiftvideospage(Jedis Jedis, Integer Voteid, String userId, intPageSize,
intPageNo, String Order, the BooleanASC) {
String Video_list_key = This. GETFORMATKEYSTR (all_video_list, Voteid);
List<map<string, String>> rs =NewArraylist<map<string, String>> ();
list<string> result =NewArraylist<> ();
System. out. println (Getstartindex (PageNo, PageSize) +"------" + Getendindex (pageno, PageSize));
if(ASC) {
result = Jedis.sort (video_list_key, NewSortingparams (). by ("*->"+ order). ASC (). Limit (Getstartindex (pageno, PageSize), PageSize).
Get"*->ac", "*->vid", "*->title", "*->time", "*->conver", "*->up_id", "*->up_name", "*->up_icon", "*->votecount"));
}Else{
result = Jedis.sort (video_list_key, NewSortingparams (). by ("*->"+ order). Desc (). Limit (Getstartindex (pageno, PageSize), PageSize).
Get"*->ac", "*->vid", "*->title", "*->time", "*->conver", "*->up_id", "*->up_name", "*->up_icon", "*->votecount"));
}
Map<string, string> map =NewHashmap<string, String> ();
for(inti =0; I < Result.size (); i = i +9) {
if((i +1) %9==1) {
Map =NewHashmap<string, String> ();
}
Map.put ("AC", Result.get (i));
Map.put ("Vid", Result.get (i +1));
Map.put ("title", Result.get (i +2));
Map.put ("Time", Result.get (i +3));
Map.put ("Conver", Result.get (i +4));
Map.put ("up_id", Result.get (i +5));
Map.put ("Up_name", Result.get (i +6));
Map.put ("Up_icon", Result.get (i +7));
Map.put ("Votecount", Result.get (i +8));
//Detect whether the user has voted on this item today
if(! StringUtils.IsEmpty(userId) && Isvotetodaybyitem (Jedis, Voteid, Result.get (i), UserId)) {
Map.put ("Isvote", "1");
}Else{
Map.put ("Isvote", "0");
}
Rs.add (map);
}
//system.out.println (Json.tojson (RS));
returnRs;
}
Redis Sort Command