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()); }