Bootstrap

Redis zset的基本使用

public static void zset(){
        RedisConfig redisConfig = new RedisConfig();
        redisConfig.zadd("myset",1d,"第1");
        redisConfig.zadd("myset",2d,"第2");
        redisConfig.zadd("myset",3d,"第3");

        //zrange按照正序排序,参数区间为排名范围
        Set<String> myset = redisConfig.zRange("myset", 0, -1);
        for (String s : myset) {
            System.out.println(s);
        }

        //zrevrange按照倒序排序,参数区间为排名范围
        Set<String> remyset = redisConfig.zRevRange("myset", 0, -1);
        for (String s : remyset) {
            System.out.println(s);
        }

        //相当于count
        Long countSet = redisConfig.zcard("myset");
        System.out.println(countSet);

        //根据指定的value获取score
        Double zscore = redisConfig.zscore("myset", "第1");
        System.out.println(zscore);

        //根据指定value获取排名
        Long zrank = redisConfig.zrank("myset", "第2");
        System.out.println(zrank);

        //删除指定的value
        Double zscore1 = redisConfig.zscore("myset", "第3");
        System.out.println(zscore1);
        redisConfig.zrem("myset","第3");
        Double zscore2 = redisConfig.zscore("myset", "第3");
        System.out.println(zscore2);

        redisConfig.close();

    }
;