Redisキャッシュ実装データランキング
6388 ワード
1.
/**
* @Author: wangHui
* @Dscription:
* @Date: Created in 19:29 2018/6/8
**/
public class PlayTest {
public static void main(String[] args) throws InterruptedException {
Jedis jedis = new Jedis("127.0.0.1",6379);
Random random = new Random();
String[] lolHero = {" "," "," "," "," "," "};
while (true){
int index = random.nextInt(lolHero.length);
String hero = lolHero[index];
Thread.sleep(2000);
jedis.zincrby("lol:hero:jsv",1,hero);
System.out.println(hero + "----- -----");
}
}
}
2.
/** * @Author: wangHui * @Dscription: * @Date: Created in 19:50 2018/6/8 **/ public class RankTest { public static void main(String[] args) throws Exception{ Jedis jedis = new Jedis("127.0.0.1",6379); int i = 1; while (true){ Thread.sleep(3000); System.out.println(" "+i+" "); Set
heroRanks = jedis.zrevrangeWithScores("lol:hero:jsv",0,5); for (Tuple t : heroRanks) { System.out.println(t.getElement()+"------"+t.getScore()); } i++; System.out.println(); System.out.println(); System.out.println(); System.out.println(); } } }