🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
(先安装redis再看php.ini里面redis扩展开了没有) #### 1、在框架根目录config里面新建redis.php文件配置ip及端口:如下: ~~~ <?php return [ 'host' => '127.0.0.1', 'port' => '6379', ]; ~~~ #### 2、在根目录extend里新建module目录,并在其里面建Redis.php文件,文件内容如下: ~~~ namespace module; //这里容易报redis404 看看use对了没有 class Redis extends \Redis { public static function redis() { $con = new \Redis(); $con->connect(config('redis.host'), config('redis.port'), 5); return $con; } } ~~~ ### 3、在项目根目录thinkphp目录里helper.php里设置redis助手函数,加入如下内容: ~~~ if (!function_exists('redis')) { /** * 获取容器对象实例 * @return Container */ function redis() { return \module\Redis::redis();       } } ~~~ ### 4、在控制器里使用: ~~~ redis()->set('xxx',3); redis()-->get('xxx') ~~~