13
13
*/
14
14
namespace Webman \RedisQueue ;
15
15
16
- use Workerman \ Timer ;
17
- use Workerman \ Worker ;
16
+ use RedisException ;
17
+ use Throwable ;
18
18
19
19
class RedisConnection extends \Redis
20
20
{
21
21
/**
22
22
* @var array
23
23
*/
24
- protected $ config = [];
24
+ protected array $ config = [];
25
25
26
26
/**
27
27
* @param array $config
28
28
* @return void
29
+ * @throws RedisException
29
30
*/
30
- public function connectWithConfig (array $ config = [])
31
+ public function connectWithConfig (array $ config = []): void
31
32
{
32
- static $ timer ;
33
33
if ($ config ) {
34
34
$ this ->config = $ config ;
35
35
}
@@ -45,24 +45,19 @@ public function connectWithConfig(array $config = [])
45
45
if (!empty ($ this ->config ['prefix ' ])) {
46
46
$ this ->setOption (\Redis::OPT_PREFIX , $ this ->config ['prefix ' ]);
47
47
}
48
- if (Worker::getAllWorkers () && !$ timer ) {
49
- $ timer = Timer::add ($ this ->config ['ping ' ] ?? 55 , function () {
50
- $ this ->execCommand ('ping ' );
51
- });
52
- }
53
48
}
54
49
55
50
/**
56
51
* @param $command
57
52
* @param ...$args
58
53
* @return mixed
59
- * @throws \ Throwable
54
+ * @throws Throwable
60
55
*/
61
56
protected function execCommand ($ command , ...$ args )
62
57
{
63
58
try {
64
59
return $ this ->{$ command }(...$ args );
65
- } catch (\ Throwable $ e ) {
60
+ } catch (Throwable $ e ) {
66
61
$ msg = strtolower ($ e ->getMessage ());
67
62
if ($ msg === 'connection lost ' || strpos ($ msg , 'went away ' )) {
68
63
$ this ->connectWithConfig ();
@@ -75,10 +70,11 @@ protected function execCommand($command, ...$args)
75
70
/**
76
71
* @param $queue
77
72
* @param $data
78
- * @param $delay
73
+ * @param int $delay
79
74
* @return bool
75
+ * @throws Throwable
80
76
*/
81
- public function send ($ queue , $ data , $ delay = 0 )
77
+ public function send ($ queue , $ data , int $ delay = 0 ): bool
82
78
{
83
79
$ queue_waiting = '{redis-queue}-waiting ' ;
84
80
$ queue_delay = '{redis-queue}-delayed ' ;
0 commit comments