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

Redis queue synchronization to mysql solution

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-08-27 09:06:481037browse

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>

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>

Execute b.php file with php command

<code>php b.php</code>

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

Statement:
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