zoukankan      html  css  js  c++  java
  • 如何使用Jedis操作redis

    public class JredisTest {
        private static Jedis jedis = new Jedis("localhost", 6379);
    
        public static void main(String[] args) {
            jedis.connect();
    
            Set<String> keys = jedis.keys("*");
            System.out.println(keys);
    
            //----------------hash-----------
            //存储hash
            jedis.hset("hash", "name", "zhou");
            jedis.hset("hash", "age", "10");
            jedis.hset("hash", "sex", "man");
            //返回hash表中指定值
            System.out.println(jedis.hget("hash", "name"));
            System.out.println(jedis.hgetAll("hash"));
    
            //-------------------map------------
            Map map = new HashMap();
            map.put("name", "zhou");
            map.put("age", "10");
            map.put("sex", "female");
            jedis.hmset("map", map);
            System.out.println(jedis.hmget("map", "name", "age", "sex"));
            System.out.println(jedis.hgetAll("map"));
            for (int i = 0; i < 10; ++i) {
                jedis.hincrBy("map", "age", 1);
            }
    
            //----------------list
            try {
                jedis.lpush("list", "name", "age", "sex");
                System.out.println(jedis.lrange("list", 0, -1));
            } catch (Exception ex) {
                System.out.println(ex.toString());
            }
    
            //-----------------set
    
            Set set=jedis.smembers("set");
            System.out.println(set);
    
            jedis.sadd("set","name","age","sex");
            System.out.println(jedis.smembers("set"));
    
            
    
        }
    }
  • 相关阅读:
    web开发之mysql优化总结
    使用webpack构建属于你自己的npm包
    jwt在node中的应用与实践
    zookeeper启动失败解决办法(3.5.7)
    oracle表分区详解
    oracle job
    ORACLE恢复误删的表数据
    go mod使用 踏雪扬尘
    sparkcore 学习 踏雪扬尘
    GO语言基本知识 踏雪扬尘
  • 原文地址:https://www.cnblogs.com/zhoudaxing/p/11859033.html
Copyright © 2011-2022 走看看