Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Memcache/Redis.php')
-rw-r--r--lib/private/Memcache/Redis.php124
1 files changed, 15 insertions, 109 deletions
diff --git a/lib/private/Memcache/Redis.php b/lib/private/Memcache/Redis.php
index 63180dd8066..9b07da2d99c 100644
--- a/lib/private/Memcache/Redis.php
+++ b/lib/private/Memcache/Redis.php
@@ -37,38 +37,16 @@ class Redis extends Cache implements IMemcacheTTL {
*/
private static $cache = null;
- private $logFile;
-
public function __construct($prefix = '', string $logFile = '') {
parent::__construct($prefix);
- $this->logFile = $logFile;
if (is_null(self::$cache)) {
self::$cache = \OC::$server->getGetRedisFactory()->getInstance();
}
}
- /**
- * entries in redis get namespaced to prevent collisions between ownCloud instances and users
- */
- protected function getNameSpace() {
- return $this->prefix;
- }
-
- private function logEnabled(): bool {
- return $this->logFile !== '' && is_writable(dirname($this->logFile)) && (!file_exists($this->logFile) || is_writable($this->logFile));
- }
-
public function get($key) {
- if ($this->logEnabled()) {
- file_put_contents(
- $this->logFile,
- $this->getNameSpace() . '::get::' . $key . "\n",
- FILE_APPEND
- );
- }
-
- $result = self::$cache->get($this->getNameSpace() . $key);
- if ($result === false && !self::$cache->exists($this->getNameSpace() . $key)) {
+ $result = self::$cache->get($this->getPrefix() . $key);
+ if ($result === false && !self::$cache->exists($this->getPrefix() . $key)) {
return null;
} else {
return json_decode($result, true);
@@ -76,43 +54,19 @@ class Redis extends Cache implements IMemcacheTTL {
}
public function set($key, $value, $ttl = 0) {
- if ($this->logEnabled()) {
- file_put_contents(
- $this->logFile,
- $this->getNameSpace() . '::set::' . $key . '::' . $ttl . '::' . json_encode($value) . "\n",
- FILE_APPEND
- );
- }
-
if ($ttl > 0) {
- return self::$cache->setex($this->getNameSpace() . $key, $ttl, json_encode($value));
+ return self::$cache->setex($this->getPrefix() . $key, $ttl, json_encode($value));
} else {
- return self::$cache->set($this->getNameSpace() . $key, json_encode($value));
+ return self::$cache->set($this->getPrefix() . $key, json_encode($value));
}
}
public function hasKey($key) {
- if ($this->logEnabled()) {
- file_put_contents(
- $this->logFile,
- $this->getNameSpace() . '::hasKey::' . $key . "\n",
- FILE_APPEND
- );
- }
-
- return (bool)self::$cache->exists($this->getNameSpace() . $key);
+ return (bool)self::$cache->exists($this->getPrefix() . $key);
}
public function remove($key) {
- if ($this->logEnabled()) {
- file_put_contents(
- $this->logFile,
- $this->getNameSpace() . '::remove::' . $key . "\n",
- FILE_APPEND
- );
- }
-
- if (self::$cache->del($this->getNameSpace() . $key)) {
+ if (self::$cache->del($this->getPrefix() . $key)) {
return true;
} else {
return false;
@@ -120,15 +74,7 @@ class Redis extends Cache implements IMemcacheTTL {
}
public function clear($prefix = '') {
- if ($this->logEnabled()) {
- file_put_contents(
- $this->logFile,
- $this->getNameSpace() . '::clear::' . $prefix . "\n",
- FILE_APPEND
- );
- }
-
- $prefix = $this->getNameSpace() . $prefix . '*';
+ $prefix = $this->getPrefix() . $prefix . '*';
$keys = self::$cache->keys($prefix);
$deleted = self::$cache->del($keys);
@@ -153,14 +99,6 @@ class Redis extends Cache implements IMemcacheTTL {
if ($ttl !== 0 && is_int($ttl)) {
$args['ex'] = $ttl;
}
- if ($this->logEnabled()) {
- file_put_contents(
- $this->logFile,
- $this->getNameSpace() . '::add::' . $key . '::' . $value . "\n",
- FILE_APPEND
- );
- }
-
return self::$cache->set($this->getPrefix() . $key, $value, $args);
}
@@ -173,15 +111,7 @@ class Redis extends Cache implements IMemcacheTTL {
* @return int | bool
*/
public function inc($key, $step = 1) {
- if ($this->logEnabled()) {
- file_put_contents(
- $this->logFile,
- $this->getNameSpace() . '::inc::' . $key . "\n",
- FILE_APPEND
- );
- }
-
- return self::$cache->incrBy($this->getNameSpace() . $key, $step);
+ return self::$cache->incrBy($this->getPrefix() . $key, $step);
}
/**
@@ -192,18 +122,10 @@ class Redis extends Cache implements IMemcacheTTL {
* @return int | bool
*/
public function dec($key, $step = 1) {
- if ($this->logEnabled()) {
- file_put_contents(
- $this->logFile,
- $this->getNameSpace() . '::dec::' . $key . "\n",
- FILE_APPEND
- );
- }
-
if (!$this->hasKey($key)) {
return false;
}
- return self::$cache->decrBy($this->getNameSpace() . $key, $step);
+ return self::$cache->decrBy($this->getPrefix() . $key, $step);
}
/**
@@ -215,21 +137,13 @@ class Redis extends Cache implements IMemcacheTTL {
* @return bool
*/
public function cas($key, $old, $new) {
- if ($this->logEnabled()) {
- file_put_contents(
- $this->logFile,
- $this->getNameSpace() . '::cas::' . $key . "\n",
- FILE_APPEND
- );
- }
-
if (!is_int($new)) {
$new = json_encode($new);
}
- self::$cache->watch($this->getNameSpace() . $key);
+ self::$cache->watch($this->getPrefix() . $key);
if ($this->get($key) === $old) {
$result = self::$cache->multi()
- ->set($this->getNameSpace() . $key, $new)
+ ->set($this->getPrefix() . $key, $new)
->exec();
return $result !== false;
}
@@ -245,18 +159,10 @@ class Redis extends Cache implements IMemcacheTTL {
* @return bool
*/
public function cad($key, $old) {
- if ($this->logEnabled()) {
- file_put_contents(
- $this->logFile,
- $this->getNameSpace() . '::cad::' . $key . "\n",
- FILE_APPEND
- );
- }
-
- self::$cache->watch($this->getNameSpace() . $key);
+ self::$cache->watch($this->getPrefix() . $key);
if ($this->get($key) === $old) {
$result = self::$cache->multi()
- ->del($this->getNameSpace() . $key)
+ ->del($this->getPrefix() . $key)
->exec();
return $result !== false;
}
@@ -265,10 +171,10 @@ class Redis extends Cache implements IMemcacheTTL {
}
public function setTTL($key, $ttl) {
- self::$cache->expire($this->getNameSpace() . $key, $ttl);
+ self::$cache->expire($this->getPrefix() . $key, $ttl);
}
- public static function isAvailable() {
+ public static function isAvailable(): bool {
return \OC::$server->getGetRedisFactory()->isAvailable();
}
}