wugg 8 months ago
parent
commit
892eb33257
1 changed files with 5 additions and 2 deletions
  1. 5 2
      app/command/WxPush.php

+ 5 - 2
app/command/WxPush.php

@@ -20,7 +20,9 @@ class WxPush extends Command
 
     protected function execute(Input $input, Output $output)
     {
-        $lockKey= Cache::set('wxpush_lock',1,600);
+        $redis = Cache::store('redis')->handler();
+       $isLock = $redis->set("wxpush_lock", time() + 600, array('nx', 'ex'=>600));
+        if(!$isLock)return;
         try{
             $appid = env('WECHAT.APPID');
             $appsecret = env('WECHAT.APPSECRET');
@@ -65,6 +67,7 @@ class WxPush extends Command
             Log::write('wxpush:'.$e->getMessage(),'error');
             $output->writeln($e->getMessage());
         }
-       Cache::delete('wxpush_lock');
+        $script = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end";
+       $redis->eval($script, 1, "wxpush_lock", time() + 10);
     }
 }