PredisCache.php in Plug 7
File
lib/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 $result;
}
protected function doFetchMultiple(array $keys) {
$fetchedItems = call_user_func_array(array(
$this->client,
'mget',
), $keys);
return array_filter(array_combine($keys, $fetchedItems));
}
protected function doContains($id) {
return $this->client
->exists($id);
}
protected function doSave($id, $data, $lifeTime = 0) {
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 => false,
Cache::STATS_MISSES => false,
Cache::STATS_UPTIME => $info['Server']['uptime_in_seconds'],
Cache::STATS_MEMORY_USAGE => $info['Memory']['used_memory'],
Cache::STATS_MEMORY_AVAILABLE => false,
);
}
}