This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
RedisResourceManager breaks if being configured via StorageCacheAbstractServiceFactory/array and server key isn't first in options array #109
Labels
Comments
rarog
changed the title
RedisResourceManager breaks if being configured via StorageCacheAbstractServiceFactory/array and service isn't first member of array
RedisResourceManager breaks if being configured via StorageCacheAbstractServiceFactory/array and server key isn't first options array
Jul 21, 2016
rarog
changed the title
RedisResourceManager breaks if being configured via StorageCacheAbstractServiceFactory/array and server key isn't first options array
RedisResourceManager breaks if being configured via StorageCacheAbstractServiceFactory/array and server key isn't first in options array
Jul 21, 2016
It would be simple to just remove the exception at this point and throw it on trying to connect but I need to think about this a little more if this would cause side effects. |
I stubled upon this issue while setting Script to reproduce<?php
require __DIR__ . '/vendor/autoload.php';
$config = [
'adapter' => [
'name' => 'redis',
'options' => [
'server' => [
'host' => 'localhost',
'port' => 6379,
],
]
]
];
// works
$redisCache = \Zend\Cache\StorageFactory::factory($config);
var_dump(get_class($redisCache));
$config = [
'adapter' => [
'name' => 'redis',
'options' => [
'server' => [
'host' => 'localhost',
'port' => 6379,
],
'lib_options' => [
\Redis::OPT_SERIALIZER => \Redis::SERIALIZER_IGBINARY,
],
]
]
];
// works
$redisCache = \Zend\Cache\StorageFactory::factory($config);
var_dump(get_class($redisCache));
$config = [
'adapter' => [
'name' => 'redis',
'options' => [
'lib_options' => [
\Redis::OPT_SERIALIZER => \Redis::SERIALIZER_IGBINARY,
],
'server' => [
'host' => 'localhost',
'port' => 6379,
],
]
]
];
// fails
$redisCache = \Zend\Cache\StorageFactory::factory($config);
var_dump(get_class($redisCache)); |
thomasvargiu
added a commit
to thomasvargiu/zend-cache
that referenced
this issue
Apr 18, 2018
thomasvargiu
added a commit
to thomasvargiu/zend-cache
that referenced
this issue
Apr 18, 2018
Merged
should can be closed in favor of #151 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I take the example from the docs to demonstrate the problem:
'caches' => array( 'Cache\Transient' => array( 'adapter' => 'redis', 'ttl' => 3600, 'options' => array( 'server' => array( 'host'=>'localhost', 'port' => 6379, 'timeout' => 2.5, ), 'database' => 5, 'password' => '', ), 'plugins' => array( 'exception_handler' => array( 'throw_exceptions' => false, ), 'serializer', ), ), ),
The relevant part is the options array.
'options' => array( 'server' => array( 'host'=>'localhost', 'port' => 6379, 'timeout' => 2.5, ), 'database' => 0, 'password' => '', ),
would work, but for example
'options' => array( 'database' => 0, 'server' => array( 'host'=>'localhost', 'port' => 6379, 'timeout' => 2.5, ), 'password' => '', ),
wouldn't.
All the setters in RedisResourceManager look if the id is already initialised, if not, every setter calls setResource with only his own parameter.
setResource merges this with the default array, which has empty array for the server key. At the end of the function setResource always calls normalizeServer, which checks if key host is set and throws an exception, if it's not.
As it is now, the code fails for every initialisation, where server key isn't the first inside the options array, because an exception is thrown.
I'm not making own fix via pull request, because this should be a design decision.
This problem also exists in the LTS 2.4 branch in exactly the same way.
The text was updated successfully, but these errors were encountered: