TP5使用redis

 1 <?php  2 namespace app\api\controller;  3 use app\api\controller\Common_base;  4 use think\cache\driver\Redis;  5 
 6
 7 class a extends Common_base  8 {  9 
10     public function b(){ 11         extract($_REQUEST); 12         if (!$a|| !$b) { 13             die(json_encode(array('result' => 'fail', 'msg' => 'fail'))); 14  } 15         $key= $a."-".$b; 16         //redis參數
17         $options= [ 18             'host'       => '127.0.0.1',
19             'port'       => 6379,
20             'password'   => 'xxxxx',
21             'select'     => 0,
22             'timeout'    => 0,
23             'expire'     => 0,
24             'persistent' => false,
25             'prefix'     => '',
26  ]; 27         $redis=new Redis($options);//實例化redis
28         $handler = $redis->handler();//獲得句柄
29         $handler->hDel('tasks',$key); 30         $handler->hDel('taskuptime',$key); 31         $handler->del($key); 32         die(json_encode(array('result' => 'success', 'msg' => 'success'))); 33 
34  } 35 }

 

相關文章
相關標籤/搜索