colinmollenhour/credis 1.17 bug

复制代码
Call to a member function getMode() on null

vendor\colinmollenhour\credis\Client.php(783): Credis_Client->assertNotPipelineOrMulti('Credis_Client::...')

错误代码

php 复制代码
#Credis_Client vendor\colinmollenhour\credis\Client.php

   /**
     * @param ?int $Iterator
     * @param string $pattern
     * @param int $count
     * @return bool|array
     * @throws CredisException
     */
    public function scan(&$Iterator, $pattern = null, $count = null) {
        $this->assertNotPipelineOrMulti(__METHOD__);
        return $this->__call('scan', array(&$Iterator, $pattern, $count));
    }

    /**
     * @param string $caller
     * @return void
     * @throws CredisException
     */
    protected function assertNotPipelineOrMulti($caller) {
        if ($this->standalone && ($this->isMulti || $this->usePipeline) ||
            // phpredis triggers a php fatal error, so do the check before
            !$this->standalone && ($this->redis->getMode() === Redis::MULTI || $this->redis->getMode() === Redis::PIPELINE)) {
            throw new CredisException('multi()/pipeline() mode can not be used with ' . $caller);
        }
    }

报错是这个代码 "this-\>redis-\>getMode()",其中this->redis为空。

调用代码

php 复制代码
$client = new Credis_Client();
$r = $client->select(15);
$data = $client->scan($client, "keywords:*", 1);
var_dump($data);

此时代码正常

php 复制代码
$host = '127.0.0.1';
$port = 6379;
$timeout = null;
$persistent = '';
$db = 15;
$client = new Credis_Client($host,$port,$timeout ,$persistent,$db);

$data = $client->scan($client, "keywords:*", 1);
var_dump($data);
var_dump(123);

会报上面的错误,就是Credis_Client构造里$this->redis没初始化。

使用懒加载,都是调用方法之后实现连接,实例化$this->redis。

可以按照正常顺序调用,也可以改代码。

修改后代码

php 复制代码
protected function assertNotPipelineOrMulti($caller) {
        if (empty($this->redis)) {
            $this->connect();
        }
        if ($this->standalone && ($this->isMulti || $this->usePipeline) ||
            // phpredis triggers a php fatal error, so do the check before
            !$this->standalone && ($this->redis->getMode() === Redis::MULTI || $this->redis->getMode() === Redis::PIPELINE)) {
            throw new CredisException('multi()/pipeline() mode can not be used with ' . $caller);
        }
    }
相关推荐
Jay Kay3 天前
Event loop is closed when AsyncClient exists in multiple event_loops.
bug
JHC0000004 天前
发现个微信客户端的bug
微信·bug
wow_DG7 天前
【Python✨】VS Code 秒开 Python 类型检查:一招 mypy + settings.json 让你的 Bug 原地现形!
python·json·bug
驱动探索者9 天前
Zephyr 获取 cpu 占用率异常bug分析
bug·rtos·zephyr
薛定e的猫咪9 天前
【调试技巧】vscode 四种断点调试,快速定位 bug
ide·vscode·python·bug
万粉变现经纪人10 天前
如何解决 pip install 编译报错 ‘cl.exe’ not found(缺少 VS C++ 工具集)问题
开发语言·c++·人工智能·python·pycharm·bug·pip
月小满11 天前
DataV轮播时其他组件的内容也一起滚动 修复bug的方法
前端·vue.js·bug·大屏端
桃子丫11 天前
AD转 Cadence学习指南-BUG篇
bug
testtraveler11 天前
[Fix] ImportError: libtorch_cpu.so: undefined symbol: iJIT_NotifyEvent
pytorch·python·bug
测试者家园11 天前
从“找 bug”到“降风险”:测试思维模式的底层迁移
软件测试·bug·风险管理·持续测试·测试基础·智能化测试·测试思维模式