命令自定义指令,连接redis,提示类不存在

浏览:5661 发布日期:2019/11/11 分类:ThinkPHP6专区
需求:
有个邮件发送的消息队列,新建了Crontab自定义指令
代码如下:(同样的代码通过http访问URL运行没有问题)protected function execute(Input $input, Output $output)
    {   
        

        $type = $input->getArgument('type');
        if($type=='Process_Notice_Email'){
            $output->writeln($type);
            ini_set('default_socket_timeout', -1);    //不超时 
    
            $Redis=new ExtendCommon\MyRedis();    // 创建redis类
            $Sendmail=new ExtendCommon\Sendmail();  // 创建邮件发送类

            while (true) {
                try{
                        $result=$Redis->brpop('Notice_Wechat');    //出队列,阻塞模式
                        if($results){
                                $content=$results['1'];
                                $res=$Sendmail->send_email($content); //发送模板消息
                                $output->writeln("Error:".$res);
                        }
        
                        usleep(100000); //睡眠0.1秒
        
                }catch(Exception $e){
                        $output->writeln("Error:".$e->getMessage());
                }
            }
        }
    }
运行php think Crontab Process_Notice_Email
提示 Class 'Redis' not found
redis是自己封装的
提示错误行代码如下:if(self::$redis==null){
            self::$redis = new \Redis();
        }
不知道怎么解决???
最佳答案
评论( 相关
后面还有条评论,点击查看>>