请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

不明白为什么安装了Yaconf插件,调用Yaconf类的时候,报错

  <?php

namespace AppLibRedis;


use EasySwooleConfig;
use EasySwooleCoreAbstractInterfaceSingleton;

class Redis
{
    use Singleton;

    public $redis = "";

    private function __construct()
    {

        if (!extension_loaded('redis')) {
            throw new Exception("redis.so文件不存在");
        }

        try {
            $this->redis = new Redis();

//            读取config.php
//            $redisConfig = Config::getInstance()->getConf("redis");
            $redisConfig =  Yaconf::get('redis');
//            var_dump($redisConfig);
            $result = $this->redis->connect($redisConfig['host'], $redisConfig['port'], $redisConfig['time_out']);
        } catch (Exception $e) {
//            throw new Exception($e->getMessage());
            throw new Exception('redis异常');
        }

        if ($result === false) {
            throw new Exception('redis 连接失败');
        }

    }

    public function get($key)
    {
        if (empty($key)) {
            return '';
        }
        return $this->redis->get($key);
    }
}


php.ini如下

运行

php easyswoole start

图片描述

图片描述

正在回答

2回答

你这个是报redis的错误

0 回复 有任何疑惑可以回复我~
  • 提问者 qq_十方_3 #1
    \Yaconf::get('redis'); 这个类是安装了yaconf扩展才有吗,我装了扩展也没有这个类,看视频没见有在哪里定义
    回复 有任何疑惑可以回复我~ 2020-04-09 09:25:45
  • 提问者 qq_十方_3 #2
    非常感谢!
    回复 有任何疑惑可以回复我~ 2020-05-03 20:49:22
singwa 2020-04-09 10:19:27

https://img1.sycdn.imooc.com/szimg/5e8e860e093c0b9b14620074.jpg

这个文件提示语法错误。你看看这个。

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信