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);
        }
    }
相关推荐
北京精诚软件2 小时前
11月10工单通重大更新:工艺路线、生产管理等多模块 BUG 修复 + 报表优化,体验再升级!
bug
tobybo1 天前
【BUG调查日记】用于压测的机器人进程内存压不住且脱离分配器的管理
服务器·bug·压力测试
spencer_tseng1 天前
Lombok.jar bug
bug·jar·lombok
海蓝可知天湛2 天前
Ubuntu24.10禁用该源...+vmware无法复制黏贴“天坑闭环”——从 DNS 诡异解析到 Ubuntu EOL 引发的 apt 404排除折腾记
linux·服务器·安全·ubuntu·aigc·bug
程序员小远3 天前
快速定位bug,编写测试用例
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·bug
老友@3 天前
一次由 PageHelper 分页污染引发的 Bug 排查实录
java·数据库·bug·mybatis·pagehelper·分页污染
黄昏恋慕黎明3 天前
测试之bug篇
bug
LXY_BUAA4 天前
《计算机操作系统》_并发 bug 和应对 (死锁/数据竞争/原子性违反;防御性编程和动态分析)20251106
bug
没有韭菜的饺子4 天前
记录一个IDEA的神奇bug
bug