1.java代码
1public class RedisTest01 { 2 3 public static void main(String[] args) { 4 5 // connect redis server 6 Jedis redis = new Jedis("127.0.0.1", 6379); 7 8 Map<String, String> map = new HashMap(); 9 map.put("userName", "jack"); 10 map.put("password", "123"); 11 map.put("age", "12"); 12 // 将map存入redis中 13 redis.hmset("myMap", map); 14 15 // 取出redis中的map进行遍历 16 Map<String, String> userMap = redis.hgetAll("myMap"); 17 for (Map.Entry<String, String> item : userMap.entrySet()) { 18 System.out.println(item.getKey() + " : " + item.getValue()); 19 } 20 } 21 22}
2.输出
userName : jack
age : 12
password : 123
3.Hash存储类型最适合存储java中的Entity,用的比较多。。。