如何使用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")); } }