The first step in the required information in the queue goods placed in the queue
The second step. Program execution queue
third step. Analyzing the message queue, the length is determined according to whether the task has been completed queue
// a first product inventory stored in the queue.
$ The Redis Redis new new = ();
for (I = $ 1; $ I <= 100; $ I ++) {
redis- $> LPUSH ( 'Good', 'good_id' $ I.);
}
print_r ($ redis-> Lrange ( 'Good', 0, -1)); Exit;
. 2 // program execution queue
header ( " type-Content: text / HTML; charset = UTF-. 8 ");
$ the Redis Redis new new = ();
// data inserted buy
$ userid =" user_id _ "mt_rand (1, 9999) .'_ 'microtime (true.. );
IF (RES = $ $ redis-> lpop ( 'Good')) {
// $ $ redis- left => LLEN ( 'Good'); // remaining "($ left).."
$ redis-> LPUSH ( 'good_res', $ RES);
//file_put_contents('F:\b.txt',$userid "buying success!" $ res "\ n" , FILE_APPEND)...;
//file_put_contents('F:\b.txt ', $ userid "bad luck, then snapped \ n-!", FILE_APPEND to);.
}
Exit;
.. 3 // print the results of
$ the Redis Redis new new = ();
print_r ($ redis-> lrange ( 'good_res ', 0, -1)); exit;