Redis管道存储--简单例子

首先获取redis连接

   //指定IP,端口,超时时间
   Jedis j = new Jedis("127.0.0.1",6379,1000);
   //选择节点DB
   j.select(1);
   //开启管道
   Pipeline pipeline = j.pipelined();
/*List数据存储,lpush key value value ... */
public void addRuleConditionToRedis(Pipeline pipeline) {
        for(Map< String, Object> map : oldObjects){
            pipeline.lpush("orule:" + "condi:" + map.get("ObjectRuleID").toString(),
                    map.get("ObjectRuleConditionID").toString());
        }
        //提交
        pipeline.sync();
}
 /*Hash数据存储,hmset ket Map< String,String>*/
   public void storeRuleCondition(List< Map< String, Object>> mapList) {
        Pipeline pipeline = client.pipelined();
        for(Map< String, Object> map : mapList){
            Map< String,String> map2 = new HashMap<>();
            map2.put("RuleDataType",map.get("RuleDataType").toString());
            map2.put("LogicType",map.get("LogicType").toString());
            pipeline.hmset("orule:condi-type:" + map.get("ObjectRuleConditionID").toString(),map2);
        }
        //提交
        pipeline.sync();
    }
    /*Set数据存储,sadd key value value ...*/
    for(Map< String, Object> map : mapList){
        pipeline.sadd("orule:condi_cont_dict:" + 
            map.get("ObjectRuleConditionID").toString(), dictId);
    }
    //提交
    pipeline.sync();

你可能感兴趣的:(工作代码库)