Skip to content

Commit

Permalink
Merge branch 'master' into 9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-ivanov committed Jul 11, 2022
2 parents 3ea8ad9 + 17ef96e commit 02f5274
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}],
"require": {
"php": "^8.0.2",
"arvenil/ninja-mutex": "^0.6",
"arvenil/ninja-mutex": "dev-master#82cbb2c",
"illuminate/console": "^9.0",
"illuminate/support": "^9.0",
"ramsey/collection": "^1.2"
Expand Down
13 changes: 8 additions & 5 deletions src/Mutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use NinjaMutex\Lock\FlockLock;
use NinjaMutex\Lock\LockAbstract;
use NinjaMutex\Lock\MemcachedLock;
use NinjaMutex\Lock\MySqlLock;
use NinjaMutex\Lock\MySQLPDOLock;
use NinjaMutex\Lock\PhpRedisLock;
use NinjaMutex\Lock\PredisRedisLock;
use NinjaMutex\Mutex as NinjaMutex;
Expand Down Expand Up @@ -38,7 +38,7 @@ class Mutex
*/
public function __construct(Command $command)
{
/** @var WithoutOverlapping $command */
/** @var Command|WithoutOverlapping $command */
$this->command = $command;

$mutexName = $command->getMutexName();
Expand All @@ -58,11 +58,14 @@ public function getNinjaMutexLock(): LockAbstract
$strategy = $this->command->getMutexStrategy();
switch ($strategy) {
case 'mysql':
return new MySqlLock(
return new MySQLPDOLock(
'mysql:' . implode(';', [
'host=' . config('database.connections.mysql.host'),
'port=' . config('database.connections.mysql.port', 3306),
]),
config('database.connections.mysql.username'),
config('database.connections.mysql.password'),
config('database.connections.mysql.host'),
config('database.connections.mysql.port', 3306)
config('database.connections.mysql.options'),
);

case 'redis':
Expand Down
11 changes: 7 additions & 4 deletions tests/MutexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Mockery\Mock;
use NinjaMutex\Lock\FlockLock;
use NinjaMutex\Lock\MemcachedLock;
use NinjaMutex\Lock\MySqlLock;
use NinjaMutex\Lock\MySQLPDOLock;
use NinjaMutex\Lock\PhpRedisLock;
use NinjaMutex\Lock\PredisRedisLock;
use Predis\Client as PredisClient;
Expand Down Expand Up @@ -65,11 +65,14 @@ public function it_supports_mysql_strategy()
$this->command->expects('getMutexStrategy')->andReturn('mysql');

$mutex = new Mutex($this->command);
$expectedLock = new MySqlLock(
$expectedLock = new MySqlPdoLock(
'mysql:' . implode(';', [
'host=' . config('database.connections.mysql.host'),
'port=' . config('database.connections.mysql.port', 3306),
]),
config('database.connections.mysql.username'),
config('database.connections.mysql.password'),
config('database.connections.mysql.host'),
config('database.connections.mysql.port', 3306)
config('database.connections.mysql.options'),
);
$this->assertEquals($expectedLock, $mutex->getNinjaMutexLock());
}
Expand Down

0 comments on commit 02f5274

Please sign in to comment.