We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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\wish_wall\vendor\phalcon\incubator\Library\Phalcon\Mvc\Model\MetaData\Redis.php(67): Phalcon\Cache\Backend\Redis->save('foo', 'bar') D:\wamp\www\wish_wall\vendor\phalcon\incubator\Library\Phalcon\Mvc\Model\MetaData\Base.php(80): Phalcon\Mvc\Model\MetaData\Redis->getCacheBackend() D:\wamp\www\wish_wall\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\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\wish_wall\app\controllers\IndexController.php(41): Phalcon\Paginator\Adapter\QueryBuilder->getPaginate()

D:\wamp\www\wish_wall\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.phalcon.io/en/latest/api/Phalcon_Cache_Backend_Redis.html

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



3.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.phalcon.io/en/latest/api/Phalcon_Cache_Backend_Redis.html

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