Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

A really bug of incubator's Phalcon\Mvc\Model\MetaData\Redis in version 2.0.x

In my project, I use incubator's Phalcon\Mvc\Model\MetaData\Redis to store metaDatas, but I found that the program cannot connect to remote redis server, problems like this:

[Tue, 16 Jun 15 08:25:02 +0200][ERROR] Could not connect to the Redisd server 127.0.0.1:6379 D:\wamp\www\wishwall\vendor\phalcon\incubator\Library\Phalcon\Mvc\Model\MetaData\Redis.php(67): Phalcon\Cache\Backend\Redis->save('foo', 'bar') D:\wamp\www\wishwall\vendor\phalcon\incubator\Library\Phalcon\Mvc\Model\MetaData\Base.php(80): Phalcon\Mvc\Model\MetaData\Redis->getCacheBackend() D:\wamp\www\wishwall\vendor\phalcon\incubator\Library\Phalcon\Mvc\Model\MetaData\Redis.php(78): Phalcon\Mvc\Model\MetaData\Base->read('map-wenweipo\mo...') [internal function]: Phalcon\Mvc\Model\MetaData->initialize(Object(Wenweipo\Models\WishContent), NULL, NULL, NULL) [internal function]: Phalcon\Mvc\Model\MetaData->readColumnMapIndex(Object(Wenweipo\Models\WishContent), 1) [internal function]: Phalcon\Mvc\Model\MetaData->hasAttribute(Object(Wenweipo\Models\WishContent), 'ischecked') [internal function]: Phalcon\Mvc\Model\Query->getExpression(Array, true) [internal function]: Phalcon\Mvc\Model\Query->getExpression(Array, true) [internal function]: Phalcon\Mvc\Model\Query->getExpression(Array, true) D:\wamp\www\wishwall\app\controllers\IndexController.php(41): Phalcon\Paginator\Adapter\QueryBuilder->getPaginate() D:\wamp\www\wishwall\public\index.php(32): Phalcon\Mvc\Application->handle() {main}

Then I follow the source of MetaData Redis ,found that it use Phalcon\Cache\Backend\Redis for Redis cache. But it's options are wrong:

protected function getCacheBackend()
{
    if (null === $this->redis) {
        $this->redis = new CacheBackend(
            new CacheFrontend(array('lifetime' => $this->options['lifetime'])),
            array(
                'redis' => $this->options['redis'],
            )
        );
    }

    return $this->redis;
}

In version 2.0.x, Phalcon\Cache\Backend\Redis are integrated into framework, and it only support options like this:

//Create the Cache setting redis connection options $cache = new Phalcon\Cache\Backend\Redis($frontCache, array( 'host' => 'localhost', 'port' => 6379, 'auth' => 'foobared', 'persistent' => false ));

So what can I do now?

edited Jun '15

I believe Phalcon\Cache\Backend\Redis was moved from Incubator (at Phalcon 2.0?) and written into the the Phalcon module itself, so you may be running an old version of Incubator?

https://docs.phalconphp.com/en/latest/api/Phalcon%5Cache%5Backend%5Redis.html

https://github.com/phalcon/incubator/tree/master/Library/Phalcon/Cache/Backend (redis missing)



1.9k
Accepted
answer

As you know, older incubator has Redis backend class defined. If I use an older version, the class will been conflict defined.

I believe Phalcon\Cache\Backend\Redis was moved from Incubator (at Phalcon 2.0?) and written into the the Phalcon module itself, so you may be running an old version of Incubator?

https://docs.phalconphp.com/en/latest/api/Phalcon%5Cache%5Backend%5Redis.html

https://github.com/phalcon/incubator/tree/master/Library/Phalcon/Cache/Backend (redis missing)