1. 先把Redis的連接池拿出來 JedisPool pool = new JedisPool(new JedisPoolConfig(),"127.0.0.1"); Jedis jedis = pool.getResource();
2. 存取值jedis.set("key","value"); jedis.get("key"); jedis.del("key");
//給一個key疊加value jedis.append("key","value2");
//此時key的值就是value + value2;
//同時給多個key進行賦值: jedis.mset("key1","value1","key2","value2");
3. 對map進行操作 Map user = new HashMap(); user.put("key1","value1"); user.put("key2","value2"); user.put("key3","value3");
//存入 jedis.hmset("user",user);
//取出user中key1 List nameMap = jedis.hmget("user","key1");
//刪除其中一個鍵值 jedis.hdel("user","key2");
//是否存在一個鍵 jedis.exists("user");
//取出所有的Map中的值: Iterator iter = jedis.hkeys("user").iterator(); while(iter.next()){ jedis.hmget("user",iter.next()); }