This article mainly shares with you the application examples of redis in php, mainly in the form of code, hoping to help everyone.
<?php // 将消息存于 redis 队列中 $redis = new Redis('127.0.0.1', 6379); $redis->connect(); $weiboInfo = array( 'uid' => get_uid(), 'content' => get_content(), 'timestamp' => time(), ); $redis->lpush('weibo_list', json_encode($weibo_info)); $redis->close(); // 利用 cron 程序遍历 redis 队列进行数据库操作 $redis = new Redis('127.0.0.1', 6379); $redis->connect(); $weibo = new Weibo(); while (true) { if ($redis->lsize('weibo_list') > 0) { $info = json_decode($redis->rpop('weibo_list')); $weibo->post($info->uid, $info->content, $info->timestamp); } else { sleep(1); } } $redis->close();
Related recommendations:
PHP and Redis realize rush buying and flash sales under high concurrency
Sharing of common usage scenarios of Redis
The above is the detailed content of Application examples of redis in php. For more information, please follow other related articles on the PHP Chinese website!