温馨提示×

tp5框架中如何使用redis

小新
313
2020-12-18 15:10:00
栏目: 云计算

tp5框架中如何使用redis

tp5框架中使用redis的示例:

打开tp5框架的编辑器,输入以下代码使用redis:

/**

* @Author: Davax<23136891@qq.com>

* @Date: 2020-04-22 09:28:01

* @Last Modified by: Davax

* @Last Modified time: 2020-04-22 11:21:49

*/

namespace app\admin\Controller;

use think\Controller;

Class Test extends Controller{

public $redis;

public function __construct(){

$this->redis = new \Redis();

$this->redis->connect('127.0.0.1',6379);

}

public function index()

{

$redis = $this->redis;

echo $redis->ping();

$a = $redis->set('kl11',22);

$v = $redis->get('kl11');

print_r($v);

}

public function test(){

$redis = $this->redis;

$redis->incr('name');

$redis->expire('name','60');//設置有效時間為1分鐘

print_r($redis->get('name'));

}

}

0