Fixed TypeError: array_combine(): Argument #2 ($values) must be of type array, bool when using Redis

TickTackk

Well-known member
Affected version
2.2.12
Code:
TypeError: array_combine(): Argument #2 ($values) must be of type array, bool given src/XF/Cache/RedisCache.php:62
Generated by: Unknown account Mar 31, 2023 at 8:42 AM
Stack trace
#0 src/XF/Cache/RedisCache.php(62): array_combine(Array, false)
#1 src/vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php(92): XF\Cache\RedisCache->doFetchMultiple(Array)
#2 src/XF/DataRegistry.php(115): Doctrine\Common\Cache\CacheProvider->fetchMultiple(Array)
#3 src/XF/DataRegistry.php(83): XF\DataRegistry->readFromCache(Array, Array)
#4 src/XF/DataRegistry.php(228): XF\DataRegistry->get(Array)
#5 src/XF/App.php(1927): XF\DataRegistry->offsetGet('classExtensions')
#6 src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container))
#7 src/XF/App.php(1598): XF\Container->offsetGet('extension.class...')
#8 src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container))
#9 src/XF/App.php(2976): XF\Container->offsetGet('extension')
#10 src/XF/App.php(3004): XF\App->extension()
#11 src/XF/App.php(1424): XF\App->extendClass('XF\\AddOn\\Manage...')
#12 src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container))
#13 src/XF/App.php(2455): XF\Container->offsetGet('addon.manager')
#14 src/XF/App.php(2026): XF\App->setupAddOnComposerAutoload()
#15 src/XF/Pub/App.php(94): XF\App->setup(Array)
#16 src/XF.php(497): XF\Pub\App->setup(Array)
#17 src/XF.php(520): XF::setupApp('XF\\Pub\\App')
#18 index.php(20): XF::runApp('XF\\Pub\\App')
#19 {main}
Request state
array(4) {
  ["url"] => string(1) "/"
  ["referrer"] => bool(false)
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}

In \XF\Cache\RedisCache::doFetchMultiple()
PHP:
    protected function doFetchMultiple(array $keys)
    {
        $redis = $this->getRedis();
        $fetchedItems = array_combine($keys, $redis->mget($keys));

        // Redis mget returns false for keys that do not exist. So we need to filter those out unless it's the real data.
        $foundItems = [];

        foreach ($fetchedItems AS $key => $value)
        {
            if ($value === false)
            {
                continue;
            }

            $foundItems[$key] = $this->unserialize($value);
        }

        return $foundItems;
    }
mget() can return false in cases such as Redis server is down.

Issue: https://github.com/phpredis/phpredis/issues/1921
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.13).

Change log:
Gracefully handle Redis mget failures
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom