{"id":380,"title":"redis\u6d88\u606f\u961f\u5217\u5b9e\u4f8b","good":0,"bad":0,"hit":2696,"created_at":"2018-08-01 17:44:58","content":"
\u751f\u4ea7\u8005a.php<\/p>
\/\/\u5148\u5b58\u5165\u5230\u961f\u5217\uff0c\u7136\u540e\u7528\u540e\u53f0\u4efb\u52a1\u4fdd\u5b58\u6570\u636e\nif (true) {\n $data = [\n 'table' => 't_startup',\n 'data' => $table,\n ];\n require_once 'func\/Redis.php';\n $redis = Redis::getInstance('tcp:\/\/127.0.0.1:6379');\n $client = $redis->client();\n $result = $client->lpush('list_sdk_insert', json_encode($data));\n if (!$result) {\n \/\/\u63d2\u5165\u961f\u5217\u5931\u8d25\u4e1a\u52a1\u5904\u7406\n }\n}<\/pre>
<\/p>\u6d88\u8d39\u8005server.php<\/p>
<?php\n\/**\n * \u540e\u53f0\u4efb\u52a1\uff1a\u4ece\u961f\u5217\u4e2d\u53d6\u6570\u636e\uff0c\u63d2\u5165mysql\n *\/\nset_time_limit(0);\n\nfunction load($param)\n{\n require_once 'func\/Redis.php';\n $redis = Redis::getInstance('tcp:\/\/127.0.0.1:6379');\n $client = $redis->client();\n\n $key = 'list_sdk_insert';\n $i = 0;\n \n while (true) {\n $i++;\n if ($i % 30 == 0) {\n sleep(0.5);\n }\n\n $str = $client->rpop($key);\n if ($str) {\n $obj = json_decode($str);\n $table = $obj->table;\n $data = $obj->data;\n $bus = new \\ZXUN\\Data\\DataTable($table);\n $result = $bus->Add($data);\n if (!$result) {\n \/\/\u63d2\u5165\u5931\u8d25\u7684\u4e1a\u52a1\uff0c\u8868\u672a\u5b9a\n }\n } else {\n sleep(0.5);\n }\n }\n exit();\n\n}<\/pre>
<\/p>"}