Home > Backend Development > PHP Tutorial > Redis queue synchronization to mysql solution

Redis queue synchronization to mysql solution

WBOY
Release: 2016-08-27 09:06:48
Original
995 people have browsed it

crontab is too inefficient. Is there a more efficient one

Reply content:

crontab is too inefficient. Is there a more efficient one

Use the redis queue, data lpush enters, and then open another process, while(true){brpop/rpop queue}

The following uses php as an example:

Code in a.php file

<code>$redis->Redis();
$redis->connect($host, $port, $db);
$redis->lpush('list', $data);</code>
Copy after login

Code in the b.php file

<code>$redis->Redis();
$redis->connect($host, $port, $db);
while(true) {
    $data = $redis->brpop('list', 0);
    if ($data) {
        // 连接mysql操作
        // 插入数据
    }
}</code>
Copy after login

Execute b.php file with php command

<code>php b.php</code>
Copy after login

It is recommended to use asynchronous processing
Only operate the redis queue, and use other asynchronous programs to achieve synchronization

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template