码迷,mamicode.com
首页 > 编程语言 > 详细

Spring RedisTemplate操作-Set操作(5)

时间:2017-04-25 11:45:42      阅读:767      评论:0      收藏:0      [点我收藏+]

标签:public   nio   set   res   array   remove   ber   cti   data   

@Autowired
    @Resource(name="redisTemplate")
    private RedisTemplate<String, String> rt;
    
    public void flushdb(){
        rt.execute(new RedisCallback<Object>() {
            public String doInRedis(RedisConnection connection) throws DataAccessException {
                connection.flushDb();
                return "ok";
            }
        });
    }
    
    public void set(){
        flushdb();
        SetOperations<String, String> vo = rt.opsForSet();
        vo.add("book", "a","b","c");
        vo.add("bag", "b","c","d","e");
        vo.add("bag1", "a","c","d","e");
//        vo.pop("bag");
    }
    
    public void get(){
        SetOperations<String, String> vo = rt.opsForSet();
        out(vo.members("book"));
        out(vo.members("bag"));
        out(vo.randomMember("book"));
        out(vo.difference("book", Arrays.asList("bag1","bag")));
        out(vo.difference("book","bag"));
        out(vo.differenceAndStore("book", "bag", "des"));
        out(vo.members("des"));
        out(vo.randomMembers("book", 2));
        out(vo.distinctRandomMembers("book", 2));
        out(vo.intersect("book", "bag"));
        out(vo.intersectAndStore("book", "bag",    "des1"));
        out(vo.members("des1"));
        out(vo.isMember("des1", "b"));
        out(vo.move("des1", "b", "des2"));
        out(vo.members("des1"));
        out(vo.members("des2"));
        out(vo.size("des2"));
        out(vo.union("book", "bag"));
        out(vo.unionAndStore("book", "bag", "jack"));
        out(vo.members("jack"));
        vo.remove("jack", "d","b");
        out(vo.members("jack"));
        
    }
    
    public void out(String str){
        System.out.println(str);
    }
    public void out(Collection list){
        System.out.println(list);
    }
    public void out(long num){
        System.out.println(num);
    }
    public void out(boolean num){
        System.out.println(num);
    }
    public void out(DataType num){
        System.out.println(num);
    }

 

Spring RedisTemplate操作-Set操作(5)

标签:public   nio   set   res   array   remove   ber   cti   data   

原文地址:http://www.cnblogs.com/aoeiuv/p/6760749.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!