diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-06-08 18:01:49 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2015-06-12 17:28:09 +0200 |
commit | a9ff242f6abd54c9f8d55d5818b658b76d7807b3 (patch) | |
tree | af40e59f31175806278bd0876a391e6bcff0741a /lib | |
parent | 520a74187639bbe73bbc4336f349586c8e19e06e (diff) | |
download | nextcloud-server-a9ff242f6abd54c9f8d55d5818b658b76d7807b3.tar.gz nextcloud-server-a9ff242f6abd54c9f8d55d5818b658b76d7807b3.zip |
switch to using watch to implement cas and cad on redis
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/memcache/redis.php | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/lib/private/memcache/redis.php b/lib/private/memcache/redis.php index 1ef9417eaf9..30619c356bc 100644 --- a/lib/private/memcache/redis.php +++ b/lib/private/memcache/redis.php @@ -31,10 +31,6 @@ class Redis extends Cache implements IMemcache { */ private static $cache = null; - private static $casScript; - - private static $cadScript; - public function __construct($prefix = '') { parent::__construct($prefix); if (is_null(self::$cache)) { @@ -59,29 +55,6 @@ class Redis extends Cache implements IMemcache { self::$cache->connect($host, $port, $timeout); - self::$casScript = self::$cache->script('load', ' -local key = ARGV[1] -local old = ARGV[2] -local new = ARGV[3] - -if redis.call(\'get\', key) == old then - redis.call(\'set\', key, new) - return true -end - -return false'); - - self::$cadScript = self::$cache->script('load', ' -local key = ARGV[1] -local old = ARGV[2] - -if redis.call(\'get\', key) == old then - redis.call(\'del\', key) - return true -end - -return false'); - if (isset($config['dbindex'])) { self::$cache->select($config['dbindex']); } @@ -184,7 +157,18 @@ return false'); * @return bool */ public function cas($key, $old, $new) { - return (bool) self::$cache->evalSha(self::$casScript, [$this->getNamespace() . $key, json_encode($old), json_encode($new)]); + if (!is_int($new)) { + $new = json_encode($new); + } + self::$cache->watch($this->getNamespace() . $key); + if ($this->get($key) === $old) { + $result = self::$cache->multi() + ->set($this->getNamespace() . $key, $new) + ->exec(); + return ($result === false) ? false : true; + } + self::$cache->unwatch(); + return false; } /** @@ -195,12 +179,20 @@ return false'); * @return bool */ public function cad($key, $old) { - return (bool)self::$cache->evalSha(self::$cadScript, [$this->getNamespace() . $key, json_encode($old)]); + self::$cache->watch($this->getNamespace() . $key); + if ($this->get($key) === $old) { + $result = self::$cache->multi() + ->del($this->getNamespace() . $key) + ->exec(); + return ($result === false) ? false : true; + } + self::$cache->unwatch(); + return false; } static public function isAvailable() { return extension_loaded('redis') - && version_compare(phpversion('redis'), '2.2.5', '>='); + && version_compare(phpversion('redis'), '2.2.5', '>='); } } |