vali 6 years ago
parent
commit
b8d8c6ec8f
2 changed files with 61 additions and 61 deletions
  1. 47 47
      datainf/logic/HttpServerRedisToSql.php
  2. 14 14
      datainf/logic/HttpServerSettelement.php

+ 47 - 47
datainf/logic/HttpServerRedisToSql.php

@@ -70,65 +70,65 @@ class HttpServerRedisToSql
     private function BatchSqlRedisToDB()
     {
         $redisconfig = $this->redisonfig;
-        //go(function () use ($redisconfig) {
-        $begint = microtime(true);
-        //$redis = new Swoole\Coroutine\Redis();
-        $redis = new \Redis();
-        $ret = $redis->connect($redisconfig['host'], $redisconfig['port']);
-        if (!$ret) {
-            echo "redis 连接失败!";
-            return;
-        }
-        if (!empty($redisconfig['passwd'])) {
-            $ret = $redis->auth($redisconfig['passwd']);
+        go(function () use ($redisconfig) {
+            $begint = microtime(true);
+            $redis = new Swoole\Coroutine\Redis();
+            // $redis = new \Redis();
+            $ret = $redis->connect($redisconfig['host'], $redisconfig['port']);
             if (!$ret) {
-                echo "redis auth 失败!";
+                echo "redis 连接失败!";
                 return;
             }
-        }
-        $redis->select($redisconfig['db']);
+            if (!empty($redisconfig['passwd'])) {
+                $ret = $redis->auth($redisconfig['passwd']);
+                if (!$ret) {
+                    echo "redis auth 失败!";
+                    return;
+                }
+            }
+            $redis->select($redisconfig['db']);
 
-        if ($redis->llen(self::SQLKEY) <= 0) {
-            return;
-        }
+            if ($redis->llen(self::SQLKEY) <= 0) {
+                return;
+            }
 
-        $this->httpserver->account->add();
+            $this->httpserver->account->add();
 
-        $batchsql = [];
-        $max = 1000;
+            $batchsql = [];
+            $max = 1000;
 
-        for ($i = 0; $i < $max; $i++) {
-            $now = $redis->rpop(self::SQLKEY);
-            if (empty($now)) {
-                break;
-            } else {
-                $batchsql[] = str_replace(";", ":", trim(trim($now), ";"));
+            for ($i = 0; $i < $max; $i++) {
+                $now = $redis->rpop(self::SQLKEY);
+                if (empty($now)) {
+                    break;
+                } else {
+                    $batchsql[] = str_replace(";", ":", trim(trim($now), ";"));
+                }
             }
-        }
 
-        if (!empty($batchsql)) {
-            $pdo = DB::getPdo();
-            $sqlstr = implode(";", $batchsql);
-            $erowcount = 0;
-            try {
-                $erowcount = $pdo->exec($sqlstr);
-            } catch (\Exception $e) {
-                echo "发生异常:" . $e->getCode() . ' ---- ' . print_r($e->getMessage(), true) . "\n";
-            }
+            if (!empty($batchsql)) {
+                $pdo = DB::getPdo();
+                $sqlstr = implode(";", $batchsql);
+                $erowcount = 0;
+                try {
+                    $erowcount = $pdo->exec($sqlstr);
+                } catch (\Exception $e) {
+                    echo "发生异常:" . $e->getCode() . ' ---- ' . print_r($e->getMessage(), true) . "\n";
+                }
+
+                if (!$erowcount) {
+                    echo "\n发生错误:" . $pdo->errorCode() . ' ---- ' . print_r($pdo->errorInfo(), true) . "\n";
+                    echo "错误sql: " . $sqlstr . "\n\n";
+                } else {
+                    echo "成功运行:" . count($batchsql) . " 条!\n";
+                }
 
-            if (!$erowcount) {
-                echo "\n发生错误:" . $pdo->errorCode() . ' ---- ' . print_r($pdo->errorInfo(), true) . "\n";
-                echo "错误sql: " . $sqlstr . "\n\n";
-            } else {
-                echo "成功运行:" . count($batchsql) . " 条!\n";
             }
+            $redis->close();
+            echo "总请求数" . $this->httpserver->account->get() . "  单个线程消耗时间: " . (microtime(true) - $begint) . " s \n";
 
-        }
-        $redis->close();
-        echo "总请求数" . $this->httpserver->account->get() . "  单个线程消耗时间: " . (microtime(true) - $begint) . " s \n";
-
-        return;
-        // });
+            return;
+        });
     }
 
 

+ 14 - 14
datainf/logic/HttpServerSettelement.php

@@ -282,23 +282,23 @@ class HttpServerSettelement
             foreach ($PageOrder_ids_1 as $p_order_ids) {
                 $nowchange_status = ($i == 1) ? $change_status : 0;
                 $data = json_encode(['ids' => $p_order_ids, 'bettype' => $bettype, 'settype' => $settype, 'game_code' => $game_code, 'match_id' => $match_id, 'change_status' => $nowchange_status], 256);
-                //go(function () use ($data, $redisconfig) {
-                $redis = new \Redis();
-                $ret = $redis->connect($redisconfig['host'], $redisconfig['port']);
-                if (!$ret) {
-                    throw  new \Exception('redis 连接失败', 1106);
-                }
-                if (!empty($redisconfig['passwd'])) {
-                    $ret = $redis->auth($redisconfig['passwd']);
+                go(function () use ($data, $redisconfig) {
+                    $redis = new Swoole\Coroutine\Redis();
+                    $ret = $redis->connect($redisconfig['host'], $redisconfig['port']);
                     if (!$ret) {
-                        throw  new \Exception('redis auth 失败', 1107);
+                        throw  new \Exception('redis 连接失败', 1106);
                     }
-                }
-                $redis->select($redisconfig['db']);
+                    if (!empty($redisconfig['passwd'])) {
+                        $ret = $redis->auth($redisconfig['passwd']);
+                        if (!$ret) {
+                            throw  new \Exception('redis auth 失败', 1107);
+                        }
+                    }
+                    $redis->select($redisconfig['db']);
 
-                $redis->lpush(self::TASKQNUM, $data);
-                //return;
-                // });
+                    $redis->lpush(self::TASKQNUM, $data);
+                    return;
+                });
                 unset($data);
                 $i++;
             }