我使用的是宝塔面板 nginx

首先确认当前项目使用的php版本

然后点开当前版本PHP,安装扩展里面安装redis 

注:只能安装在一个PHP版本里面(不可存在多个版本PHP中)

config文件夹下面的 cache.php

<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <[email protected]>
// +----------------------------------------------------------------------

// +----------------------------------------------------------------------
// | 缓存设置
// +----------------------------------------------------------------------


return [
 
    // 缓存配置为复合类型
    'type'  =>  'complex',
 
    'default'	=>	[
        'type'	=>	'file',
        // 全局缓存有效期(0为永久有效)
        'expire'=>  0,
        // 缓存前缀
        'prefix'=>  'think',
        // 缓存目录
        'path'  =>  '../runtime/cache/',
    ],
 
    'redis'	=>	[
        'type'	=>	'redis',
    ],
    // 添加更多的缓存类型设置
  ];

第二步:

在服务器终端输入

composer

TP5.1+redis

出现这种情况就证明composer情况OK,如果没有,就要自己去安装

cd /mnt/wwwroot/tp51/application 进入此目录后

composer require predis/predis  运行如下命令

安装redis扩展

TP5.1+redis

出现上述情况就是安装成功。

测试

新建test.php

namespace app\api\controller;
use think\facade\Cache;
use app\api\common\controller\Base;
Class Test extends Base
{
        public function redis()
    {
      Cache::store('redis')->set('demo','haixia',100);
     


      
         dump(Cache::store('redis')->get('demo'));
    
    }

}

 针对tp5.1的redis操作,建议进入think\cache\driver\Redis里面查看和一些参数设置

 查看结果,成功

相关文章:

  • 2021-12-19
  • 2021-04-22
  • 2021-08-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
猜你喜欢
  • 2021-11-27
  • 2021-09-01
  • 2021-09-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
相关资源
相似解决方案