住房建设部官方网站,常见服务器,网站标题被别人改了 应该怎么办,wordpress设置登录页面第一种方法#xff1a;使用insert into 插入从Redis每次获取100条数据#xff0c;根据条件去插入到Mysql数据库中#xff1a;条件#xff1a;如果当前队列中的值大于1000条#xff0c;则会自动的条用该方法#xff0c;该方法每次获取从队列的头部每次获取100掉数据插入到…第一种方法使用insert into 插入从Redis每次获取100条数据根据条件去插入到Mysql数据库中条件如果当前队列中的值大于1000条则会自动的条用该方法该方法每次获取从队列的头部每次获取100掉数据插入到Mysql数据库中同时以当前队列的长度为插入条件。1000为原始数据从队列头获取100条插入到Mysql数据同时删除已经插入的数据再通过队列的长度判断是否继续插入直到循环不满足条件为止。[1]获取头100条数据$redis-lRange($liveKey,0,99)[2]删除头100条数据$redis-lTrim($liveKey, 100, -1);[1]获取当前队列长度$redis-lLen($liveKey);public functionredisSaveMysqlAction(){$liveKey $this-request-getQuery(liveKey);if(empty($liveKey)){$result array(errcode 500, errmsg this parameter is empty!);return $this-toJson($result);}$redis new\Redis();$redis-connect(1.1.2.16, 6379);$redisInfo $redis-lRange($liveKey,0,99);$dataLength $redis-lLen($liveKey);while($dataLength 200) {try{$this-db-begin();foreach ($redisInfo as $action) {$sql INSERT INTO livecomment (liveId,username,createTime,userId,content) VALUES (?, ? ,?,? ,?);$this-db-execute($sql, array(json_decode($action,true)[roomId],json_decode($action,true)[userName],json_decode($action,true)[createTime],json_decode($action,true)[userId],json_decode($action,true)[content],));}$redis-set(message_insert_success, 1);$redis-lTrim($liveKey, 100, -1);$redisInfo $redis-lRange($liveKey,0,99); // 这句也要重新的获取不然就会插入重复的数据也就是获取删除后的数据$dataLength $redis-lLen($liveKey); //注意这句一定要加上的做为下一次的判断标准当插入完后和删除后重新获取列表的长度作为条件依据$redis-set(dataLength_backenk, $dataLength);$this-db-commit();}catch (\Exception $e) {$redis-set(message_insert_fail, 0);$this-db-rollback();}}$redis-set(log.$liveKey,$redis-incr(request_counts));$result array(errcode 200, errmsg Data Insert into Success!,datadataLength:.$dataLength.liveKey:.$liveKey);return $this-toJson($result);第二种方法使用优化SQL语句将SQL语句进行拼接使用 insert into table () values (),(),(),()然后再一次性插入如果字符串太长,则需要配置下MYSQL在mysql 命令行中运行 set global max_allowed_packet 2*1024*1024*10;拼接后的字符串insert into twenty_million (value) values(50),(50),(50),(50),(50),(50),(50),(50),(50),(50)实际案例/*** 获取Redis数据批量的保存到Redis中去解析Redis数据的json格式*/public functionRedisSaveToMysqlJsonAction(){$redis RedisInstance::getInstance();$redis-select(1);$redisInfo $redis-lRange(message01,0,9999);$dataLength $redis-lLen(message01);$redis-set(dataLength_front,$dataLength);$t1microtime(true);while($dataLength 20000) {try{$this-db-begin();$sql INSERT INTO stream_name (name,createTime,userId,content) VALUES;foreach ($redisInfo as $action) {$sql . ( . json_decode($action, true)[userName] . , . json_decode($action, true)[createTime] . , . json_decode($action, true)[userId] . , . json_decode($action, true)[content] . ),;}$sql rtrim($sql, ,);$this-db-execute($sql);$redis-lTrim(message01, 10000, -1);$redisInfo $redis-lRange(message01,0,9999);$dataLength $redis-lLen(message01);$this-db-commit();}catch (\Exception $e) {$redis-set(message_catch, json_encode($e));$this-db-rollback();}}echo ENDTIME:.(microtime(true)-$t1).;echo success;die;}输出结果为ENDTIME:3.0146479606628(s)success