@@ -16,7 +16,7 @@ class AsyncRedisTransport
16
16
*/
17
17
protected $ connection ;
18
18
19
- function __construct (Array $ connectionConfig )
19
+ public function __construct (Array $ connectionConfig )
20
20
{
21
21
$ this ->connection = \Yii::$ app ->{$ connectionConfig ['connection ' ]};
22
22
}
@@ -26,6 +26,11 @@ public static function getQueueKey($queueName, $progress = false)
26
26
return "queue: $ queueName " . ($ progress ? ':progress ' : null );
27
27
}
28
28
29
+ public static function getChannelKey ($ queueName )
30
+ {
31
+ return "channel: $ queueName " ;
32
+ }
33
+
29
34
/**
30
35
* @param string $text
31
36
* @param string $queueName
@@ -34,7 +39,7 @@ public static function getQueueKey($queueName, $progress = false)
34
39
public function send ($ text , $ queueName )
35
40
{
36
41
$ return = $ this ->connection ->executeCommand ('LPUSH ' , [self ::getQueueKey ($ queueName ), $ text ]);
37
- $ this ->connection ->executeCommand ('PUBLISH ' , [self ::getQueueKey ($ queueName ), 'new ' ]);
42
+ $ this ->connection ->executeCommand ('PUBLISH ' , [self ::getChannelKey ($ queueName ), 'new ' ]);
38
43
return $ return ;
39
44
}
40
45
@@ -70,7 +75,7 @@ public function waitAndReceive($queueName)
70
75
$ task = $ this ->receive ($ queueName );
71
76
if (!$ task ) {
72
77
// subscribe to queue events
73
- $ this ->connection ->executeCommand ('SUBSCRIBE ' , [self ::getQueueKey ($ queueName )]);
78
+ $ this ->connection ->executeCommand ('SUBSCRIBE ' , [self ::getChannelKey ($ queueName )]);
74
79
while (!$ task ) {
75
80
// wait for message
76
81
$ response = $ this ->connection ->parseResponse ('' );
@@ -80,12 +85,12 @@ public function waitAndReceive($queueName)
80
85
}
81
86
82
87
// unsubscribe to release redis connection context
83
- $ this ->connection ->executeCommand ('UNSUBSCRIBE ' , [self ::getQueueKey ($ queueName )]);
88
+ $ this ->connection ->executeCommand ('UNSUBSCRIBE ' , [self ::getChannelKey ($ queueName )]);
84
89
$ task = $ this ->receive ($ queueName );
85
90
86
91
// if someone else got our task - subscribe again and wait
87
92
if (!$ task ) {
88
- $ this ->connection ->executeCommand ('SUBSCRIBE ' , [self ::getQueueKey ($ queueName )]);
93
+ $ this ->connection ->executeCommand ('SUBSCRIBE ' , [self ::getChannelKey ($ queueName )]);
89
94
}
90
95
}
91
96
}
@@ -121,7 +126,7 @@ public function purge($queueName)
121
126
* @return bool
122
127
* @throws Exception
123
128
*/
124
- function disconnect ()
129
+ public function disconnect ()
125
130
{
126
131
if ($ this ->connection ) {
127
132
$ this ->connection ->close ();
0 commit comments