美文网首页
基于mongodb的临时手机池生成方案(后面补充方案图)

基于mongodb的临时手机池生成方案(后面补充方案图)

作者: 小雪的笔记 | 来源:发表于2018-06-08 17:52 被阅读0次

    print('=========WECOME==========');
    //方法
    function getMobileV3() {
    var getNum = function(start, end) {
    var number = (Math.random() * (end - start + 1) + start);
    return parseInt(number);
    };
    var telFirst = "133,153,177,180,181,189,134,135,136,137,138,139,150,151,152,157,158,159,178,182,183,184,187,188,147,130,131,132,155,156,176,185,186,145,170,171"
    .split(",");
    var index = getNum(0, telFirst.length - 1);
    var first = telFirst[index];
    var second = (getNum(1, 888) + 10000).toString().substr(1);
    var thrid = (getNum(1, 9100) + 10000).toString().substr(1);
    return first + second + thrid;
    }

    function getMobile() {
    var getNum = function(start, end) {
    var number = (Math.random() * (end - start + 1) + start);
    return parseInt(number);
    };

    var telFirst = "133,153,177,180,181,189,134,135,136,137,138,139,150,151,152,157,158,159,178,182,183,184,187,188,147,130,131,132,155,156,176,185,186,145,170,171"
            .split(",");
    var mobile_testNum = "mobile_testNum3";
    var mobile = "";
    var index = getNum(0, telFirst.length - 1);
    var first = telFirst[index];
    
    var mobieend = 0;
    var currentNum = 0;
    var timestamp =0;
    while (true) {
     // var value = Integer.valueOf(ucRedisDao.get(mobile_testNum));
      var partitionNum = db.config.findOne({name:"partitionNum"}).value;
      timestamp = ((new Date()).valueOf()).toString(); 
      var partionIndex = (timestamp%100024);
      var redisKeyMax = "mobile_test3_max:" + (partionIndex).toString();
      var start = db.config.findOne({name:redisKeyMax}).value;
     
      if (start == 0) {
        currentNum = parseInt((100000000 / 100024) * (partionIndex - 1));
        if(partionIndex==0){
            currentNum = 5421;
        }
      } else {
        currentNum = parseInt(start);
      }
      if (currentNum >= ((100000000 / 100024) * partionIndex) || currentNum >= 99999999) {
        db.config.update( {name:"partitionNum" } , { $set : { value : (partitionNum-1)} } );
        print('=========partitionNum=========='+(partitionNum-1));
        continue;
      }
    
      ++currentNum;
      mobieend = currentNum;
      db.config.update( {name:redisKeyMax } , { $set : { value :currentNum} } );
      mobile = first + (parseInt(mobieend) + 100000000).toString().substr(1);;
      break;
    }
    print('=========mobile=========='+mobile+'++++++++++++++++++++partionIndex:'+partionIndex+'_____________start:'+start+'   timestamp:'+timestamp);
    
    return mobile;
    

    }

    //调用
    var index =0;
    var startStamp =((new Date()).valueOf());
    while(true){
    var mobile = getMobile();
    var count = db.prdmobile.count({"mobile":parseInt(mobile)});
    if(count==0){
    db.prdavailablemobile.insert({"mobile":mobile});
    ++index;
    if(index>=20000000){
    break;
    }else{
    print('mobile:'+mobile);
    }
    }
    }

    var endStamp =((new Date()).valueOf());
    print('=========end=========='+(endStamp-startStamp));

    相关文章

      网友评论

          本文标题:基于mongodb的临时手机池生成方案(后面补充方案图)

          本文链接:https://www.haomeiwen.com/subject/kylssftx.html