Reference: http://www.cnblogs.com/lisqiong/p/6039460.html
Reference: http://blog.csdn.net/shaobingj126/article/details/50585035
Message Queuing: A container that holds messages during the transmission of a message. The Message Queue Manager acts as an intermediary when relaying a message from its source to its destination. The primary purpose of the queue is to provide routing and guarantee the delivery of the message, and if the recipient is unavailable when the message is sent, Message Queuing retains the message until it can be successfully passed
Scenario: Asynchronous processing, application decoupling, traffic clipping, and message communication four scenarios
1. Asynchronous processing
Scene Description: After the user registration, you need to send a registration email and registration text.
Note : Consider async in Ajax yourself.
2. Application decoupling
The General Order system and the inventory system are one, but if there is a problem on one side, then the order fails.
- Order system: After the user orders, the order system completes the persistent processing, writes the message to the message queue, returns the user orders the order to succeed.
- Inventory System: Subscribe to the order of the message, the use of pull/push way, to obtain the order information, inventory system according to the order information, inventory operations.
- If: The inventory system will not be used properly when order is being given. Also does not affect the normal order, because after placing orders, the order system to write to the message queue will no longer care about other subsequent operations. Realize the application decoupling of order system and inventory system.
Note: It feels particularly like behavior-driven, where each behavior is stored in Message Queuing
3, the flow of anti-front (generally in the second kill or group robbery activities widely used)
Note: the average seconds to kill the order will be particularly much, but the database can not be processed one time so much, so it is possible to first exist in the message queue, no matter how fast I enter the speed, the speed is certain. I don't know if it's part of the funnel model.
Redis Extension for PHP: Https://github.com/phpredis/phpredis
1) Redis function Rpush,lpop
2). Crontab of Linux
Creating demo.php and index.php
<?PHP$redis=NewRedis ();$redis->connect (' 127.0.0.1 ', 6379); $password= ' 123456 '; $redis->auth ($password); $arr=Array(' h ', ' e ', ' l ', ' l ', ' o ', ' w ', ' O ', ' r ', ' L ', ' d '); foreach($arr as $k=$v){ $redis->rpush ("MyList",$v); }
<?PHP$redis=NewRedis ();$redis->connect (' 127.0.0.1 ', 6379); $password= ' 123456 '; $redis->auth ($password); //list type out of team operation $value=$redis->lpop (' MyList '); if($value){ Echo"The value of the team."$value; }Else{ Echo"Team out."; } ?>
Set up timed tasks
*/1 * * * * Root php/wwwroot/workplace/redis/index.php
*/3 * * * * Root php/wwwroot/workplace/redis/demo.php
Php+redis Implementing Message Queuing