我使用的是tp5.1
安装redis 扩展不细节描述
phpstudy 安装的redis 需要修改默认配置文件
步骤1:
redis 的配置修改:
notify-keyspace-events "Ex"
重启redis
步骤2:
创建公用redis类
<?php
namespace app\command\Controller;
use think\cache\driver\Redis;
class MyRedis
{
private $redis;
public function __construct($host = '127.0.0.1', $port = 6379)
{
$this->redis = new Redis();
$this->redis->config('notify-keyspace-events','Ex');//开启redis key 过期通知(修改配置文件失效可加上)
$this->redis->connect($host, $port);
$this->redis->auth('123456');
}
public function setex($key, $time, $val)
{
return $this->redis->setex($key, $time, $val);
}
public function set($key, $val)
{
return $this->redis->set($key, $val);
}
public function get($key)
{
return $this->redis->get($key);
}
public function e

本文详细介绍了如何在ThinkPHP 5.1环境中安装Redis扩展,配置过期事件,并创建MyRedis类进行数据操作。通过实例展示了如何在订单业务中使用Redis存储和清除过期订单,同时提供了关键代码片段和命令行监听方法。
最低0.47元/天 解锁文章
5526

被折叠的 条评论
为什么被折叠?



