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();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值