Skip to content
Snippets Groups Projects
Commit ae971568 authored by Mateusz Charytoniuk's avatar Mateusz Charytoniuk
Browse files

fix: redis session gc

parent fc627961
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,6 @@ declare(strict_types=1); ...@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Distantmagic\Resonance; namespace Distantmagic\Resonance;
use Ds\Map; use Ds\Map;
use Redis;
readonly class Session readonly class Session
{ {
...@@ -24,7 +23,12 @@ readonly class Session ...@@ -24,7 +23,12 @@ readonly class Session
public function persist(): void public function persist(): void
{ {
$this->getRedisConnection()->set( $redisConnection = new RedisConnection(
$this->redisConnectionPoolRepository,
$this->getRedisPrefix(),
);
$redisConnection->redis->set(
$this->id, $this->id,
$this->serializer->serialize($this->data->toArray()) $this->serializer->serialize($this->data->toArray())
); );
...@@ -32,7 +36,12 @@ readonly class Session ...@@ -32,7 +36,12 @@ readonly class Session
private function getPersistedData(): mixed private function getPersistedData(): mixed
{ {
$storedValue = $this->getRedisConnection()->get($this->id); $redisConnection = new RedisConnection(
$this->redisConnectionPoolRepository,
$this->getRedisPrefix(),
);
$storedValue = $redisConnection->redis->get($this->id);
if (!is_string($storedValue) || empty($storedValue)) { if (!is_string($storedValue) || empty($storedValue)) {
return null; return null;
...@@ -41,7 +50,7 @@ readonly class Session ...@@ -41,7 +50,7 @@ readonly class Session
return $this->serializer->unserialize($storedValue); return $this->serializer->unserialize($storedValue);
} }
private function getRedisConnection(): Redis private function getRedisPrefix(): string
{ {
$redisPrefix = $this->redisConfiguration $redisPrefix = $this->redisConfiguration
->connectionPoolConfiguration ->connectionPoolConfiguration
...@@ -49,12 +58,7 @@ readonly class Session ...@@ -49,12 +58,7 @@ readonly class Session
->prefix ->prefix
; ;
$redisConnection = new RedisConnection( return $redisPrefix.'.session';
redisConnectionPoolRepository: $this->redisConnectionPoolRepository,
redisPrefix: $redisPrefix.'session:',
);
return $redisConnection->redis;
} }
private function restoreSessionData(): array private function restoreSessionData(): array
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment