Php read and write variables [large concurrency]

[1] Today, I made an official account to reply to the keyword php of grabbing red packets. Use a redis variable to record the number of red packets sent. If it reaches 100, it will be snatched up. As a result, the redis variable no longer changes at 56, and the money in the account is emptied: ([2] find a variable reading and writing method that can adapt to high concurrency [3] my code is summarized as follows

    `
    $redis = new Redis();                   
    $redis->connect("127.0.0.1","8090");
    $num_s = $redis->get("num");
    $num = intval( $num_s );

    if(  $num<100 ){         
    $opid = strval( $msg->FromUserName );
    
    require(dirname(__FILE__) . "\redpack.php");  //
             
    if( "SENDNUM_LIMIT"===$result){
      $wechat->reply( "" );
    }elseif( $result===true ){
      $redis->set("num", strval(PP$num) );
      echo "";exit;
    } 
    else {            echo "";exit;        }
  } 
  else {
    $wechat->reply("");
  }        

`

Dec.06,2021

if you fail to send $num, you may also PP


you need to add one before sending red packets, so that even if you fail to send red packets, it does not affect the total amount. Reduce it by one after failure.

Menu