Redisのデータ構造のZsortと基本的なソート操作
package com.jiedistest;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import com.tools.JedisDemo;
import redis.clients.jedis.Jedis;
public class JedisZsort {
static JedisDemo jd=new JedisDemo();
;public static void main(String[] args) {
Map map=new HashMap();
Jedis js=jd.getConn();
js.auth("199633");
//
js.flushDB();
//
js.zadd("car",1," " );
js.zadd("car",2," " );
js.zadd("car",3," " );
js.zadd("car",4," " );
js.zadd("car",5," " );
js.zadd("car",6," " );
js.zadd("car",7," " );
System.out.println(js.zrange("car", 0, -1));
js.zadd("car",8," " );
// key , ( )
Set keys=js.zrange("car", 0, 4);
System.out.println(keys);
// key , ( )
Set keyss=js.zrevrange("car", 0, 4);
System.out.println(keyss);
// int
System.out.println(js.zcard("car"));
// Double
System.out.println(js.zscore("car", " "));
//
System.out.println(js.zrem("car", " "));
//score 0-100
System.out.println(js.zcount("car", 0, 100));
//score+
System.out.println(js.zincrby("car", 100, " "));
//score 0-100
System.out.println(js.zrangeByScore("car", 0, 100));
//
System.out.println(js.zrank("car", " "));
//
System.out.println(js.zrange("car", 0, -1));
js.close();
}
}
package com.jiedistest;
import com.tools.JedisDemo;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.SortingParams;
public class SortDemo {
static JedisDemo jd=new JedisDemo();
static Jedis js=jd.getConn();
public static void main(String[] args) {
js.auth("199633");
js.flushDB();
js.lpush("sort", "777","5555","42","33");
js.lpush("English", "b","g","a","f","c");
js.rpush("rank", "1","3","5","7","9");
js.rpush("rank", "2","4","6","8");
System.out.println(js.lrange("rank", 0, -1));
System.out.println(js.lrange("English", 0, -1));
System.out.println(js.lrange("sort", 0, -1));
SortingParams sort=new SortingParams();
//
System.out.println(js.sort("sort",sort.asc()));
//
System.out.println(js.sort("sort",sort.desc()));
//
System.out.println(js.sort("English",sort.alpha()));
//LIMIT
System.out.println(js.sort("rank",sort.limit(0, 7).desc()));
js.close();
}
}
また、GETとBYソートは、id、levelなどの格納された要素に従ってソートされ、両者の組み合わせがより直感的になります.一度に面倒なソート方法を呼び出したくない場合は、ライフサイクルを設定して保存し、複雑さを避けることができます.