-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not keep session connection opened
- Loading branch information
1 parent
71d5891
commit 326d607
Showing
2 changed files
with
59 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Distantmagic\Resonance; | ||
|
||
use Redis; | ||
|
||
readonly class RedisConnection | ||
{ | ||
public Redis $redis; | ||
|
||
public function __construct( | ||
RedisConfiguration $redisConfiguration, | ||
private RedisConnectionPoolRepository $redisConnectionPoolRepository, | ||
string $redisPrefix, | ||
private string $connectionPoolName = 'default', | ||
) { | ||
$redisPrefix = $redisConfiguration | ||
->connectionPoolConfiguration | ||
->get($connectionPoolName) | ||
->prefix | ||
; | ||
|
||
$this->redis = $this | ||
->redisConnectionPoolRepository | ||
->getConnection($connectionPoolName) | ||
; | ||
$this->redis->setOption(Redis::OPT_PREFIX, $redisPrefix); | ||
} | ||
|
||
public function __destruct() | ||
{ | ||
$this->redisConnectionPoolRepository->putConnection( | ||
$this->connectionPoolName, | ||
$this->redis, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters