Skip to content

Commit

Permalink
snappy && fix journal
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubvojacek committed Jul 23, 2020
1 parent d3e572f commit f30caf2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Kdyby/Redis/RedisJournal.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public function write(string $key, array $dp): void
$this->client->zAdd($this->formatKey(self::PRIORITY), $dp[Cache::PRIORITY], $key);
}

if (isset($dp[Cache::EXPIRE])) {
$this->client->send('expire', [$this->formatKey($key, self::TAGS), $dp[Cache::EXPIRE]]);
}

$this->client->exec();
}

Expand All @@ -90,8 +94,7 @@ private function cleanEntry($keys): void
}

// drop tags of entry and priority, in case there are some
$this->client->del($this->formatKey($key, self::TAGS), $this->formatKey($key, self::PRIORITY));
$this->client->zRem($this->formatKey(self::PRIORITY), $key);
$this->client->del($this->formatKey($key, self::TAGS));

$this->client->exec();
}
Expand Down
2 changes: 2 additions & 0 deletions src/Kdyby/Redis/RedisStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public function write(string $key, $data, array $dp): void
}

$store = \json_encode($meta) . Cache::NAMESPACE_SEPARATOR . $data;
$store = \snappy_compress($store);

try {
if (isset($dp[Cache::EXPIRATION])) {
Expand Down Expand Up @@ -334,6 +335,7 @@ private function doMultiRead(array $keys): array
*/
private static function processStoredValue(string $key, string $storedValue): array
{
$storedValue = \snappy_uncompress($storedValue);
[$meta, $data] = \explode(Cache::NAMESPACE_SEPARATOR, $storedValue, 2) + [NULL, NULL];
return [[self::KEY => $key] + \json_decode($meta, TRUE), $data];
}
Expand Down

0 comments on commit f30caf2

Please sign in to comment.