X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FCache%2FRedisCache.php;h=5dbb963882917d3be47bed7d0383380cb3b9993d;hb=017a57cf1e2b7db6bed4abf7167b4086af73311c;hp=40cb56d35cdaa9939c7cc998f006b0059125ede4;hpb=34e4968c060d0860f72f1d0120751e6cf8513dcb;p=friendica.git diff --git a/src/Core/Cache/RedisCache.php b/src/Core/Cache/RedisCache.php index 40cb56d35c..5dbb963882 100644 --- a/src/Core/Cache/RedisCache.php +++ b/src/Core/Cache/RedisCache.php @@ -1,19 +1,35 @@ . + * + */ namespace Friendica\Core\Cache; use Exception; -use Friendica\Core\Cache; -use Friendica\Core\Config\Configuration; +use Friendica\Core\BaseCache; +use Friendica\Core\Config\IConfig; use Redis; /** * Redis Cache. This driver is based on Memcache driver - * - * @author Hypolite Petovan - * @author Roland Haeder */ -class RedisCache extends AbstractCache implements IMemoryCache +class RedisCache extends BaseCache implements IMemoryCache { /** * @var Redis @@ -23,7 +39,7 @@ class RedisCache extends AbstractCache implements IMemoryCache /** * @throws Exception */ - public function __construct(string $hostname, Configuration $config) + public function __construct(string $hostname, IConfig $config) { if (!class_exists('Redis', false)) { throw new Exception('Redis class isn\'t available'); @@ -38,8 +54,10 @@ class RedisCache extends AbstractCache implements IMemoryCache $redis_pw = $config->get('system', 'redis_password'); $redis_db = $config->get('system', 'redis_db', 0); - if (!$this->redis->connect($redis_host, $redis_port)) { + if (isset($redis_port) && !@$this->redis->connect($redis_host, $redis_port)) { throw new Exception('Expected Redis server at ' . $redis_host . ':' . $redis_port . ' isn\'t available'); + } elseif (!@$this->redis->connect($redis_host)) { + throw new Exception('Expected Redis server at ' . $redis_host . ' isn\'t available'); } if (isset($redis_pw) && !$this->redis->auth($redis_pw)) { @@ -95,7 +113,7 @@ class RedisCache extends AbstractCache implements IMemoryCache /** * (@inheritdoc) */ - public function set($key, $value, $ttl = Cache::FIVE_MINUTES) + public function set($key, $value, $ttl = Duration::FIVE_MINUTES) { $cachekey = $this->getCacheKey($key); @@ -121,7 +139,9 @@ class RedisCache extends AbstractCache implements IMemoryCache public function delete($key) { $cachekey = $this->getCacheKey($key); - return ($this->redis->delete($cachekey) > 0); + $this->redis->del($cachekey); + // Redis doesn't have an error state for del() + return true; } /** @@ -139,7 +159,7 @@ class RedisCache extends AbstractCache implements IMemoryCache /** * (@inheritdoc) */ - public function add($key, $value, $ttl = Cache::FIVE_MINUTES) + public function add($key, $value, $ttl = Duration::FIVE_MINUTES) { $cachekey = $this->getCacheKey($key); $cached = serialize($value); @@ -150,7 +170,7 @@ class RedisCache extends AbstractCache implements IMemoryCache /** * (@inheritdoc) */ - public function compareSet($key, $oldValue, $newValue, $ttl = Cache::FIVE_MINUTES) + public function compareSet($key, $oldValue, $newValue, $ttl = Duration::FIVE_MINUTES) { $cachekey = $this->getCacheKey($key); @@ -193,8 +213,11 @@ class RedisCache extends AbstractCache implements IMemoryCache return false; } - public function __toString() + /** + * {@inheritDoc} + */ + public function getName() { - return self::TYPE_REDIS; + return Type::REDIS; } }