PredisCache.php in Zircon Profile 8.0
File
vendor/doctrine/cache/lib/Doctrine/Common/Cache/PredisCache.php
View source
<?php
namespace Doctrine\Common\Cache;
use Predis\Client;
class PredisCache extends CacheProvider {
private $client;
public function __construct(Client $client) {
$this->client = $client;
}
protected function doFetch($id) {
$result = $this->client
->get($id);
if (null === $result) {
return false;
}
return unserialize($result);
}
protected function doFetchMultiple(array $keys) {
$fetchedItems = call_user_func_array(array(
$this->client,
'mget',
), $keys);
return array_filter(array_combine($keys, array_map('unserialize', $fetchedItems)));
}
protected function doContains($id) {
return $this->client
->exists($id);
}
protected function doSave($id, $data, $lifeTime = 0) {
$data = serialize($data);
if ($lifeTime > 0) {
$response = $this->client
->setex($id, $lifeTime, $data);
}
else {
$response = $this->client
->set($id, $data);
}
return $response === true || $response == 'OK';
}
protected function doDelete($id) {
return $this->client
->del($id) > 0;
}
protected function doFlush() {
$response = $this->client
->flushdb();
return $response === true || $response == 'OK';
}
protected function doGetStats() {
$info = $this->client
->info();
return array(
Cache::STATS_HITS => $info['Stats']['keyspace_hits'],
Cache::STATS_MISSES => $info['Stats']['keyspace_misses'],
Cache::STATS_UPTIME => $info['Server']['uptime_in_seconds'],
Cache::STATS_MEMORY_USAGE => $info['Memory']['used_memory'],
Cache::STATS_MEMORY_AVAILABLE => false,
);
}
}