zoukankan      html  css  js  c++  java
  • 常用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"));
    
        }
    
  • 相关阅读:
    静态代码块执行时机
    java中的命令
    JDBC
    final, finally, finalize
    面向对象
    线程中常用的一些方法
    线程中的yield()
    线程中的join()
    Thread对象 既传入了Runnable对象又重写了run()方法
    Python 绘制词云
  • 原文地址:https://www.cnblogs.com/zz-newbie/p/15090877.html
Copyright © 2011-2022 走看看