From f30caf20f99a3b345fdd25f778f08e9b62e09174 Mon Sep 17 00:00:00 2001 From: Jakub Vojacek Date: Thu, 23 Jul 2020 08:58:34 +0200 Subject: [PATCH] snappy && fix journal --- src/Kdyby/Redis/RedisJournal.php | 7 +++++-- src/Kdyby/Redis/RedisStorage.php | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Kdyby/Redis/RedisJournal.php b/src/Kdyby/Redis/RedisJournal.php index da6ea9b..0c50c32 100644 --- a/src/Kdyby/Redis/RedisJournal.php +++ b/src/Kdyby/Redis/RedisJournal.php @@ -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(); } @@ -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(); } diff --git a/src/Kdyby/Redis/RedisStorage.php b/src/Kdyby/Redis/RedisStorage.php index dea5013..261cf41 100644 --- a/src/Kdyby/Redis/RedisStorage.php +++ b/src/Kdyby/Redis/RedisStorage.php @@ -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])) { @@ -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]; }