• 常用API之Hash


    public static void main(String[] args) {
            Jedis jedis = new Jedis("127.0.0.1",6379);
            jedis.auth("12345");
            jedis.flushDB();
    
            Map<String, String> map = new HashMap<String, String>();
            map.put("key1","value1");
            map.put("key2","value2");
            map.put("key3","value3");
            map.put("key4","value4");
            //添加名称为hash(key)的hash元素
            System.out.println(jedis.hmset("hash",map));
            //问名称为hash的 hash中添加key为key5,value为value5的元素
            System.out.println(jedis.hset("hash","key5","value5"));
            System.out.println("散列hash的所有键值对为:"+jedis.hgetAll("hash"));
            System.out.println("散列hash的所有键为:"+jedis.hkeys("hash"));
            System.out.println("散列hash的所有值为:"+jedis.hvals("hash"));
            System.out.println("将key6保存的值加上一个整数,如果key6不存在则添加key6:"+jedis.hincrBy("hash","key6",9));
            System.out.println("散列hash的所有键值对为:"+jedis.hgetAll("hash"));
            System.out.println("将key6保存的值加上一个整数,如果key6不存在则添加key6:"+jedis.hincrBy("hash","key6",9));
            System.out.println("散列hash的所有键值对为:"+jedis.hgetAll("hash"));
            System.out.println("删除一个或者多个键值对:"+jedis.hdel("hash","key2"));
            System.out.println("散列hash的所有键值对为:"+jedis.hgetAll("hash"));
            System.out.println("散列hash中键值对的个数:"+jedis.hlen("hash"));
            System.out.println("判断hash中是否存在key2:"+jedis.hexists("hash","key2"));
            System.out.println("判断hash中是否存在key3:"+jedis.hexists("hash","key3"));
            System.out.println("获取hash中的值:"+jedis.hmget("hash","key3"));
            System.out.println("获取hash中的值:"+jedis.hmget("hash","key3","key4","key7"));
    
        }
    
  • 相关阅读:
    LeetCode #1021. Remove Outermost Parentheses 删除最外层的括号
    使用Maven运行测试提示Module sdk 1.5的解决方法
    Map.Entry使用详解
    c++基础(一)
    Python_正则表达式
    使用PIL生成验证码
    OpenCV_图像平滑
    OpenCV—图像阈值
    OpenCV形状变换
    使用OpenCV读写图片
  • 原文地址:https://www.cnblogs.com/zz-newbie/p/15090877.html
Copyright © 2020-2023  润新知