场景

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进行操作的命令后,下面是对Set进行常用操作。

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

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

 

   @Test
    public void SetTest()
    {
        //System.out.println("向集合中添加元素(不重复):"+jedis.sadd("set1","1","2","3","4"));
        //System.out.println("set1的所有元素:"+jedis.smembers("set1"));
        //System.out.println("删除两个元素3、4:" + jedis.srem("set1", "3", "4"));
        //System.out.println("随机的移除集合中的一个元素:" + jedis.spop("set1"));
        //System.out.println("set1的包含元素的个数:"+jedis.scard("set1"));
        //System.out.println("1是否在set1中:"+jedis.sismember("set1","1"));
        //System.out.println("向集合中添加元素(不重复):" + jedis.sadd("set2", "5", "6", "7", "8"));
        //System.out.println("将set2中的8移动到set1中:"+jedis.smove("set2","set1","8"));
        System.out.println("set1和set2的交集:"+jedis.sinter("set1","set2"));
        System.out.println("set1和set2的并集:"+jedis.sunion("set1","set2"));
        System.out.println("set1和set2的差集:"+jedis.sdiff("set1","set2"));
    }

 

posted on 2020-03-19 17:17  霸道流氓  阅读(2983)  评论(0编辑  收藏  举报