ThinkPHP5+Redis 引入Redis并可调用Redis原生函数

∫`不撒娇的折耳猫 2020-6-30 1862

1、确保已经安装了Redis扩展

2、找到config.php,修改如下Redis配置信息

// +----------------------------------------------------------------------
    // | 缓存设置
    // +----------------------------------------------------------------------
    'cache'                  => [
        // 驱动方式
        'type'   => 'Redis',
        // 缓存保存目录
        'path'   => CACHE_PATH,
        // 缓存前缀
        'prefix' => '',
        // 缓存有效期 0表示永久缓存
        'expire' => 0,
        'host' => '127.0.0.1',
        'port' => '6379',
        'password' => '',
    ],

3、控制器测试是否可以

namespace app\index\controller
use think\Cache
use think\Controller;
class Show extends Controller
{
    /**
     * Notes:程序运行前的准备工
     * User: Wendy_33
     * Time: 2020/6/30  15:10
     */
    public function firstStep(){
        //开启Redis
        $redis = Cache::store('redis')->handler();
        $redis->select(1);
        echo $redis->ping();
        exit;
    }
}


最新回复 (0)
发新帖