Jedis jedis = new Jedis("localhost",6379);
//获取管道
Pipeline pp = jedis.pipelined();
//以下是批量数据,以批量插入hash为例
Map<String, Map<String,String>> datas = new HashMap<String, Map<String,String>>();
for (int i = 0; i < 100000; i++) {
Map<String, String> data = new HashMap<String, String>();
//二级key
data.put("name", "zhangsan");
data.put("age", "18");
data.put("sex", "男");
//一级key
datas.put("key"+i, data);
}
//以下是批量插入
Set<String> keys = datas.keySet();
for (String key : keys) {
pp.hmset(key, datas.get(key));
}
jedis.close();