| 1 | <?php |
||
| 5 | class Redis |
||
| 6 | { |
||
| 7 | private static $pid = 0; |
||
| 8 | private static $redis = null; |
||
| 9 | |||
| 10 | public static function get() |
||
| 11 | { |
||
| 12 | if (self::$redis === null || self::$pid !== getmypid()) { |
||
| 13 | $config = Config::getInstance(); |
||
| 14 | |||
| 15 | self::$redis = new \Redis(); |
||
| 16 | self::$redis->connect($config->get('redisServer', '127.0.0.1'), $config->get('redisPort', 6379), 3600); |
||
| 17 | self::$pid = getmypid(); |
||
| 18 | } |
||
| 19 | return self::$redis; |
||
| 20 | } |
||
| 21 | |||
| 22 | public static function canRun(string $key, int $mutex = 60) |
||
| 32 | } |
||
| 33 |