Skip to content

Commit

Permalink
MDL-63127 cachestore_redis: dont use compression unless specified
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Oct 7, 2019
1 parent f232409 commit 493295e
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions cache/stores/redis/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ public function is_ready() {
public function get($key) {
$value = $this->redis->hGet($this->hash, $key);

if ($this->compressor == self::COMPRESSOR_NONE) {
return $value;
}

return $this->uncompress($value);
}

Expand All @@ -273,6 +277,10 @@ public function get($key) {
public function get_many($keys) {
$values = $this->redis->hMGet($this->hash, $keys);

if ($this->compressor == self::COMPRESSOR_NONE) {
return $values;
}

foreach ($values as &$value) {
$value = $this->uncompress($value);
}
Expand All @@ -288,7 +296,9 @@ public function get_many($keys) {
* @return bool True if the operation succeeded, false otherwise.
*/
public function set($key, $value) {
$value = $this->compress($value);
if ($this->compressor != self::COMPRESSOR_NONE) {
$value = $this->compress($value);
}

return ($this->redis->hSet($this->hash, $key, $value) !== false);
}
Expand All @@ -304,7 +314,11 @@ public function set_many(array $keyvaluearray) {
$pairs = [];
foreach ($keyvaluearray as $pair) {
$key = $pair['key'];
$pairs[$key] = $this->compress($pair['value']);
if ($this->compressor != self::COMPRESSOR_NONE) {
$pairs[$key] = $this->compress($pair['value']);
} else {
$pairs[$key] = $pair['value'];
}
}
if ($this->redis->hMSet($this->hash, $pairs)) {
return count($pairs);
Expand Down

0 comments on commit 493295e

Please sign in to comment.