1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dazzle\Redis\Command\Compose; |
4
|
|
|
|
5
|
|
|
use Dazzle\Redis\Command\Builder; |
6
|
|
|
use Dazzle\Redis\Command\Enum; |
7
|
|
|
use Dazzle\Redis\Driver\Request; |
8
|
|
|
|
9
|
|
|
trait ApiChannelTrait |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @param Request $request |
13
|
|
|
* @return mixed |
14
|
|
|
*/ |
15
|
|
|
abstract function dispatch(Request $request); |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @override |
19
|
|
|
* @inheritDoc |
20
|
|
|
*/ |
21
|
|
|
public function pSubscribe(...$patterns) |
22
|
|
|
{ |
23
|
|
|
// TODO: Implement pSubscribe() method. |
24
|
|
|
$command = Enum::PSUBSCRIBE; |
25
|
|
|
$args = $patterns; |
26
|
|
|
|
27
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @override |
32
|
|
|
* @inheritDoc |
33
|
|
|
*/ |
34
|
|
|
public function pubSub($command, array $args = []) |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
// TODO: Implement pubSub() method. |
37
|
|
|
$command = Enum::PUBSUB; |
38
|
|
|
|
39
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @override |
44
|
|
|
* @inheritDoc |
45
|
|
|
*/ |
46
|
|
View Code Duplication |
public function publish($channel, $message) |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
// TODO: Implement publish() method. |
49
|
|
|
$command = Enum::PUBLISH; |
50
|
|
|
$args = [$channel, $message]; |
51
|
|
|
|
52
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @override |
57
|
|
|
* @inheritDoc |
58
|
|
|
*/ |
59
|
|
|
public function pUnsubscribe(...$patterns) |
60
|
|
|
{ |
61
|
|
|
// TODO: Implement pUnsubscribe() method. |
62
|
|
|
$command = Enum::PUNSUBSCRIBE; |
63
|
|
|
$args = $patterns; |
64
|
|
|
|
65
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @override |
70
|
|
|
* @inheritDoc |
71
|
|
|
*/ |
72
|
|
|
public function unSubscribe(...$channels) |
73
|
|
|
{ |
74
|
|
|
// TODO: Implement unSubscribe() method. |
75
|
|
|
$command = Enum::UNSUBSCRIBE; |
76
|
|
|
$args = $channels; |
77
|
|
|
|
78
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @override |
83
|
|
|
* @inheritDoc |
84
|
|
|
*/ |
85
|
|
|
public function subscribe(...$channels) |
86
|
|
|
{ |
87
|
|
|
// TODO: Implement subscribe() method. |
88
|
|
|
$command = Enum::SUBSCRIBE; |
89
|
|
|
$args = $channels; |
90
|
|
|
|
91
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
92
|
|
|
} |
93
|
|
|
} |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.