Use redis's list data structure to execute SQL statements in batches

Source: Internet
Author: User
There are more than such records in the database. each record contains the Chinese name of the region and the English name of the region (for example,). I want to use the redis queue lpush and rpop for batch update, I have already written the SQL statement (for example, I wrote the code in this way (for example). I wrote more than 3 thousand SQL statements...

There are more than such records in the database. each record contains the Chinese name of the region and the English name of the region (for example)

Now I want to use the redis queue lpush and rpop for batch update. I have written the SQL statement (for example)

I wrote the code like this (for example). I saved more than SQL statements into the list (lpush), and prepared to execute each time (rpop) one by one, I don't know how to write it next. I want to ask you how to write it next. now I have put the SQL statement into the list; and I want to view the list value under cli. Chinese characters seem to contain garbled characters (such ), I added -- raw when I started the cli. please answer it.

Thank you ~

Reply content:

There are more than such records in the database. each record contains the Chinese name of the region and the English name of the region (for example)

Now I want to use the redis queue lpush and rpop for batch update. I have written the SQL statement (for example)

I wrote the code like this (for example). I saved more than SQL statements into the list (lpush), and prepared to execute each time (rpop) one by one, I don't know how to write it next. I want to ask you how to write it next. now I have put the SQL statement into the list; and I want to view the list value under cli. Chinese characters seem to contain garbled characters (such ), I added -- raw when I started the cli. please answer it.

Thank you ~

Thank you!
In fact, you don't need redis. you can put all the SQL statements in one file and read and execute one SQL statement?

Function getSql () {$ fp = fopen(' SQL .txt ', 'r'); while (! Feof ($ fp) {yield fgets ($ fp) ;}} foreach (getSql () as $ SQL) {executeSql ($ SQL);} function executeSql () {// execution Statement}

Insert into base_region (region_name, en_name) values ('China', 'Zhongguo'), ('Beijing', 'Beijing '),..., ('Shanghai', 'Shanghai') on duplicate key update en_name = values (en_name );

A SQL statement with a very low overhead can be done (the performance of a database connection is similar to that of batch insert into data ).

Pay attention to the following two points:

  1. You need to splice the values of () in values (), (), and () using a for loop.

  2. Region_name must be a unique index. you can add a unique index to this field temporarily. after the SQL statement is executed, drop it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.