Not much nonsense to say, directly to everyone to paste the code, the specific code is as follows:
<?phpnamespace backend\controllers;use yii;use yii\web\controller;/*** */class GoodsController extends Controller{ Public $enableCsrfValidation =false;public Function Actioninfo () {$data =yii:: $app->db->createcommand ("SELECT * From goods ")->queryall (), Return $this->render (' Index ', [' data ' = $data]); Public Function Actionxx () {$id =yii:: $app->request->get (' id '); $data =yii:: $app->db->createcommand (" SELECT * from goods where id= ' $id ' ")->queryone (), Return $this->render (' info ', [' data ' = $data]); Public Function Actionadd () {$a =yii:: $app->redis;if (yii:: $app->request->ispost) {$data =yii:: $app- Request->post (); $res =yii:: $app->db->createcommand ()->insert (' goods ', $data)->execute (); if ($res) { for ($i =0; $i < $data [' counts ']; $i + +) {$a->lpush (' goods ', 1);} return $this->redirect (Array (' Goods/info '));} Else{echo "Add failed";}} Else{return $this->render (' Add ');}} Public Function Actionorder () {$redis =yii:: $app->redis; $count = $redis->lpop ('Goods '), if (Empty ($count)) {echo ' insufficient inventory ';d ie;} $res =yii:: $app->db->createcommand ("Update goods set counts=counts-1 where id=1 and counts>0")->execute (); if ($res) {echo "Second Kill succeeded";} Else{echo "second kill Failed";}}? >