• 通过java操作redis


    前提是redis服务器已启动
    package redis;

    import redis.clients.jedis.Jedis;


    import java.util.HashMap;


    /**
    * @auto dh
    * @create 2020-04-05-19:23
    */
    public class Redis002 {
    public static void main(String[] args) {
    Jedis jedis = new Jedis("192.168.220.129", 6380);
    //获取所有的key
    System.out.println(jedis.keys("*"));
    //通过hset赋值
    jedis.hset("custom", "name", "zhangsan");
    //通过hget获取值
    System.out.println(jedis.hget("custom", "name"));
    HashMap<String, String> hm = new HashMap();
    hm.put("name", "乔村小学");
    hm.put("year", "2013");
    //通过hmset赋值
    jedis.hmset("school", hm);
    //通过hmget获取值
    System.out.println(jedis.hmget("school", "name", "year"));
    //通过hkeys来获取school里的所有key
    System.out.println(jedis.hkeys("school"));
    //通过hvals来获取school里的所有vals
    System.out.println(jedis.hvals("school"));
    //通过hexists来判断school里的key为name是否存在
    System.out.println(jedis.hexists("school", "name"));
    //通过hgetAll来获取school里的所有键值对
    System.out.println(jedis.hgetAll("school"));
    //通过hdel来删除school里的key为name的键值对
    jedis.hdel("school", "name");
    System.out.println(jedis.hgetAll("school"));
    //通过hincrBy来增加key为year的value值
    jedis.hincrBy("school", "year", 20);
    System.out.println(jedis.hget("school", "year"));
    jedis.hincrBy("school", "year", 30);
    System.out.println(jedis.hget("school", "year"));
    //通过hlen来获取school里的键值对个数
    System.out.println(jedis.hlen("school"));
    }
    }
  • 相关阅读:
    低于时钟频率的任意频率生成(相位累加器)
    verilog实现奇数倍分频
    No.135 Candy
    No.42 Trapping Rain Water
    No.149 Max Point on a Line
    No.147 Insertion Sorted List
    No.21 Merge Two Sorted List
    No.88 Merge Sorted Array
    No.148 Sort List
    No.206 Reverse Linked List
  • 原文地址:https://www.cnblogs.com/kukai/p/12639029.html
Copyright © 2020-2023  润新知