zoukankan      html  css  js  c++  java
  • 通过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"));
    }
    }
  • 相关阅读:
    团队项目第二次冲刺Ⅶ
    团队项目第二次冲刺Ⅷ
    随机生成四则运算式2-NEW+PSP项目计划(补充没有真分数的情况)
    第二周的学习进度情况
    最近关于编程学习的一点小体会
    构建之法阅读笔记02
    随机生成四则运算式2
    本周的学习进度情况
    本学期的阅读计划
    随机生成30道四则运算-NEW
  • 原文地址:https://www.cnblogs.com/kukai/p/12639029.html
Copyright © 2011-2022 走看看