zoukankan      html  css  js  c++  java
  • java redistemplate

    //添加一个 key 
            ValueOperations<String, Object> value = redisTemplate.opsForValue();
            value.set("lp", "hello word");
            //获取 这个 key 的值
            System.out.println(value.get("lp"));
            //添加 一个 hash集合
            HashOperations<String, Object, Object>  hash = redisTemplate.opsForHash();
            Map<String,Object> map = new HashMap<String,Object>();
            map.put("name", "lp");
            map.put("age", "26");
            hash.putAll("lpMap", map);
            //获取 map
            System.out.println(hash.entries("lpMap"));
            //添加 一个 list 列表
            ListOperations<String, Object> list = redisTemplate.opsForList();
            list.rightPush("lpList", "lp");
            list.rightPush("lpList", "26");
            //输出 list
            list.range("lpList", 0, 1)
         (List<String>) redisTemplate.opsForList().range(key, 0, -1);
         //list中移除元素
         redisTemplate.opsForList().remove("key", 0, list中的值必须一模一样的值);
    //添加 一个 set 集合 SetOperations<String, Object> set = redisTemplate.opsForSet(); set.add("lpSet", "lp"); set.add("lpSet", "26"); set.add("lpSet", "178cm"); //输出 set 集合 System.out.println(set.members("lpSet")); //添加有序的 set 集合 ZSetOperations<String, Object> zset = redisTemplate.opsForZSet(); zset.add("lpZset", "lp", 0); zset.add("lpZset", "26", 1); zset.add("lpZset", "178cm", 2); //输出有序 set 集合 System.out.println(zset.rangeByScore("lpZset", 0, 2));      //清空zset中的值 只能写个无限大的值     redisTemplate.opsForZSet().removeRangeByScore(key, min, max);     redisTemplate.opsForZSet().removeRangeByScore("datainfo2", 0, 10000);     //查询zset中所有的值 0 到 -1    redisTemplate.opsForZSet().range(key, 0, -1)   
    redis 中opsforlist 元素的下标从0开始 到 -1结束







      

      

  • 相关阅读:
    中文词语的语法划分
    程序员转行可以做什么?
    Linux Crontab 定时任务 命令详解
    Spring对AOP的支持
    ASP.NET 2.0 Web Part编程入门
    linux ramdom hung up
    VLC plugin加载代码分析
    mac上的ssh proxy客户端 iSSH个人修改版
    关于MP4 fileformat中 duration及timescale相关的几个地方
    inline 小结
  • 原文地址:https://www.cnblogs.com/xdcr/p/6343350.html
Copyright © 2011-2022 走看看