Skip to content

Commit

Permalink
fix global timer lock on redis cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
hhxsv5 committed Jan 6, 2023
1 parent dbf7a0f commit e1098fb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Swoole/Timer/CronJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static function getGlobalTimerCacheKey()

public static function getGlobalTimerLock()
{
/**@var \Illuminate\Redis\Connections\PhpRedisConnection $redis */
/**@var \Illuminate\Redis\RedisManager $redis */
$redis = app('redis');

$key = self::getGlobalTimerCacheKey();
Expand All @@ -115,14 +115,14 @@ protected static function getCurrentInstanceId()

public static function isGlobalTimerAlive()
{
/**@var \Illuminate\Redis\Connections\PhpRedisConnection $redis */
$redis = app('redis');
/**@var \Redis|\RedisCluster|\Predis\Client $redis */
$redis = app('redis')->client(); // Fix exists() always returns false for some older version of Laravel, see https://github.com/illuminate/redis/commit/62ff6a06a9c91902d3baa7feda20bab5e807606f
return (bool)$redis->exists(self::getGlobalTimerCacheKey());
}

public static function isCurrentTimerAlive()
{
/**@var \Illuminate\Redis\Connections\PhpRedisConnection $redis */
/**@var \Illuminate\Redis\RedisManager $redis */
$redis = app('redis');
$key = self::getGlobalTimerCacheKey();
$instanceId = $redis->get($key);
Expand All @@ -131,7 +131,7 @@ public static function isCurrentTimerAlive()

public static function renewGlobalTimerLock($expire)
{
/**@var \Illuminate\Redis\Connections\PhpRedisConnection $redis */
/**@var \Illuminate\Redis\RedisManager $redis */
$redis = app('redis');
return (bool)$redis->expire(self::getGlobalTimerCacheKey(), $expire);
}
Expand Down

0 comments on commit e1098fb

Please sign in to comment.