欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Java中使用Jedis连接Redis对SortedSet进行排序操作

程序员文章站 2022-06-25 08:38:01
场景 Centos中Redis的下载编译与安装(超详细): https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103967334 Redis的启动和关闭(前台启动和后台启动): https://blog.csdn.net/BADAO_ ......

场景

centos中redis的下载编译与安装(超详细):

https://blog.csdn.net/badao_liumang_qizhi/article/details/103967334

redis的启动和关闭(前台启动和后台启动):

https://blog.csdn.net/badao_liumang_qizhi/article/details/103972348

redisdesktopmanager客户端可视化工具下载安装与使用:

https://blog.csdn.net/badao_liumang_qizhi/article/details/103983147

java中使用jedis连接redis对key进行操作的常用命令:

https://blog.csdn.net/badao_liumang_qizhi/article/details/104915569

参考上面对key进行操作的命令后,下面是对sortedset进行排序操作。

注:

博客:

关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

新建junit方法sortedsettest,然后依次打开以下注释代码

  

  @test
    public void sortedsettest()
    {
        //存放数据
        //jedis.lpush("collections", "1", "2", "3", "4", "5", "6", "7", "8", "9");
        //获取所有元素
        //system.out.println("collections的内容是:"+jedis.lrange("collections",0,-1));
        //排序
        sortingparams sortingparams = new sortingparams();
        //system.out.println("排序后的结果:"+jedis.sort("collections",sortingparams.alpha()));
        system.out.println("升序后的结果:"+jedis.sort("collections",sortingparams.asc()));
        system.out.println("降序后的结果:"+jedis.sort("collections",sortingparams.desc()));
    }