Publish Weibo under PHP using Redis Message Queuing (copy)

Source: Internet
Author: User
Tags dsn

Phpredisadmin:github address graphical management interface

git clone https://github.com/ErikDubbelboer/phpRedisAdmin.gitcd phpredisadmingit clone https://github.com/nrk/ Predis.git Vendor

First, install the Redis graphical management interface above to easily manage Redis data

In order to reduce the concurrency of MySQL, the user's microblog is first present in Redis

Suppose users need three fields when publishing, UID (user ID number), username (user name), content (' User's comments ')

For example, the user passes the following information

?
123456789101112131415161718 <?php//此处需要安装phpredis$redisnew Redis();$redis->connect(‘127.0.0.1‘, 6379);        //    连接redis$web_infoarray(‘uid‘=> ‘123456‘,‘username‘ => ‘123‘,‘content‘=>‘123‘);//将数组转成json来存储$list= json_encode($web_info);//lpush向KEY对应的头部添加一个字符串元素$redis->lpush(‘weibo_lists‘,$list);$redis->close();///var_dump(json_encode($web_info));var_dump($list);?>

Here you can see that our Redis already has data.

?
123456789101112131415161718192021222324 //创建一个PDO数据库链接  data.php<?phpclassqq{publicfunctionpost($uid=‘‘,$username=‘‘,$content=‘‘){    try{             $dsn"mysql:host;dbname=localhost;dbname=test";            $dbnewPDO($dsn,‘root‘,‘root‘);                           $db->exec("SET NAMES UTF8");            $sql="insert into test(uid,username,content)values(‘$uid‘,‘$username‘,‘$content‘)";$db->exec($sql);    }catch(PDOException $e){    $e->getMessage();}                } }
?
12345678910111213141516171819202122 //处理redis数据库的数据 并把数据放到MYSQL数据库中<?phpinclude"data.php";$qqnewqq();$redis newRedis();$redis->connect(‘127.0.0.1‘, 6379);            //返回的列表的大小。如果列表不存在或为空,该命令返回0。如果该键不是列表,该命令返回FALSE    if($redis-> lsize(‘weibo_lists‘)){    //从LIST头部删除并返回删除数据        $info$redis->rpop(‘weibo_lists‘);        $info= json_decode($info);        $qq->post($info->uid,$info->username,$info->content);    }$redis->close();var_dump($info); ?>

We can see that the database already has data.

Publish Weibo under PHP using Redis Message Queuing (copy)

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.