Skip to content

Commit

Permalink
Update for amphp/redis:^2
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Aug 20, 2023
1 parent 026b998 commit 2641f03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/Db/Driver/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@

namespace danog\MadelineProto\Db\Driver;

use Amp\Redis\Redis as RedisRedis;
use Amp\Redis\Connection\ReconnectingRedisLink;
use Amp\Redis\RedisClient;
use Amp\Redis\RedisConfig;
use Amp\Redis\RemoteExecutorFactory;
use Amp\Sync\LocalKeyedMutex;
use danog\MadelineProto\Settings\Database\Redis as DatabaseRedis;

use function Amp\Redis\createRedisConnector;

/**
* Redis driver wrapper.
*
* @internal
*/
final class Redis
{
/** @var array<RedisRedis> */
/** @var array<RedisClient> */
private static array $connections = [];

private static ?LocalKeyedMutex $mutex = null;
public static function getConnection(DatabaseRedis $settings): RedisRedis
public static function getConnection(DatabaseRedis $settings): RedisClient
{
self::$mutex ??= new LocalKeyedMutex;
$dbKey = $settings->getKey();
Expand All @@ -45,7 +48,7 @@ public static function getConnection(DatabaseRedis $settings): RedisRedis
->withPassword($settings->getPassword())
->withDatabase($settings->getDatabase());

self::$connections[$dbKey] = new RedisRedis((new RemoteExecutorFactory($config))->createQueryExecutor());
self::$connections[$dbKey] = new RedisClient(new ReconnectingRedisLink(createRedisConnector($config)));
self::$connections[$dbKey]->ping();
}
} finally {
Expand Down
4 changes: 2 additions & 2 deletions src/Db/RedisArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace danog\MadelineProto\Db;

use Amp\Redis\Redis as RedisRedis;
use Amp\Redis\RedisClient;
use danog\MadelineProto\Db\Driver\Redis;
use danog\MadelineProto\Logger;
use danog\MadelineProto\Settings\Database\Redis as DatabaseRedis;
Expand All @@ -32,7 +32,7 @@
*/
final class RedisArray extends DriverArray
{
private RedisRedis $db;
private RedisClient $db;

/**
* Initialize on startup.
Expand Down

0 comments on commit 2641f03

Please sign in to comment.