I have been using Redis as a cache and noticed that it was quite slow. I am using the Phalcon\Cache\Frontend\Data and Phalcon\Cache\Backend\Redis as a cache for my models. I've noticed that it is at times 40x slower than using a regular redis connection.
Here is my connections for both (normal frontend/backend cache) and just using Redis:
$di->set('cache', function() use ($config) {
$redis = new Redis();
$redis->connect("localhost", "6379");
$frontend = new Phalcon\Cache\Frontend\Data(array(
'lifetime' => 3600
));
$cache = new Phalcon\Cache\Backend\Redis($frontend, array(
'redis' => $redis
));
return $cache;
});
$di->set('cache2', function() use ($config) {
$redis = new Redis();
$redis->connect("localhost", "6379");
return $redis;
});
For a test, in a controller, I will do:
$this->cache->save("test", 123);
I'll load another page once that data is set to not have it be cached in the frontend:
$start = microtime(true);
$this->cache2->get("test");
$end = microtime(true);
echo "Total Time: ".($end - $start)."<br />";
$start = microtime(true);
$this->cache->get("test");
$end = microtime(true);
echo "Total Time: ".($end - $start)."<br />";
I'll run the previous code and get:
Total Time: 0.00025105476379395
Total Time: 0.0061139850616455
Any reason this could be that slow? Is it just overhead with the library?