1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Asiries335\redisSteamPhp; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Asiries335\redisSteamPhp\Data\Constants; |
8
|
|
|
use Asiries335\redisSteamPhp\Dto\StreamCommandCallTransporter; |
9
|
|
|
|
10
|
|
|
final class StreamGroupConsumer extends RedisStream |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Create group Consumer |
14
|
|
|
* |
15
|
|
|
* @param string $groupName |
16
|
|
|
* @param bool $isShowFullHistoryStream |
17
|
|
|
* |
18
|
|
|
* @return bool |
19
|
|
|
* |
20
|
|
|
* @throws \Exception |
21
|
|
|
*/ |
22
|
1 |
|
public function create(string $groupName, bool $isShowFullHistoryStream = true) : bool |
23
|
|
|
{ |
24
|
1 |
|
$transporter = new StreamCommandCallTransporter( |
25
|
|
|
[ |
26
|
1 |
|
'command' => Constants::COMMAND_XGROUP, |
27
|
|
|
'args' => [ |
28
|
1 |
|
Constants::COMMAND_OPTION_XGROUP_CREATE, |
29
|
1 |
|
$this->_streamName, |
30
|
1 |
|
$groupName, |
31
|
1 |
|
(int) $isShowFullHistoryStream |
32
|
|
|
] |
33
|
|
|
] |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
try { |
37
|
1 |
|
return (bool) $this->_client->call($transporter); |
38
|
|
|
} catch (\Exception $exception) { |
39
|
|
|
throw $exception; |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Delete group Consumer |
45
|
|
|
* |
46
|
|
|
* @param string $groupName |
47
|
|
|
* |
48
|
|
|
* @return bool |
49
|
|
|
* |
50
|
|
|
* @throws \Exception |
51
|
|
|
*/ |
52
|
1 |
|
public function destroy(string $groupName) : bool |
53
|
|
|
{ |
54
|
1 |
|
$transporter = new StreamCommandCallTransporter( |
55
|
|
|
[ |
56
|
1 |
|
'command' => Constants::COMMAND_XGROUP, |
57
|
|
|
'args' => [ |
58
|
1 |
|
Constants::COMMAND_OPTION_XGROUP_DESTROY, |
59
|
1 |
|
$this->_streamName, |
60
|
1 |
|
$groupName, |
61
|
|
|
] |
62
|
|
|
] |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
try { |
66
|
1 |
|
return (bool) $this->_client->call($transporter); |
67
|
|
|
} catch (\Exception $exception) { |
68
|
|
|
throw $exception; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Delete consumer from group |
74
|
|
|
* |
75
|
|
|
* @param string $groupName |
76
|
|
|
* @param string $consumerName |
77
|
|
|
* |
78
|
|
|
* @return bool |
79
|
|
|
* |
80
|
|
|
* @throws \Exception |
81
|
|
|
*/ |
82
|
1 |
|
public function deleteConsumer(string $groupName, string $consumerName) : bool |
83
|
|
|
{ |
84
|
1 |
|
$transporter = new StreamCommandCallTransporter( |
85
|
|
|
[ |
86
|
1 |
|
'command' => Constants::COMMAND_XGROUP, |
87
|
|
|
'args' => [ |
88
|
1 |
|
Constants::COMMAND_OPTION_XGROUP_DELCONSUMER, |
89
|
1 |
|
$this->_streamName, |
90
|
1 |
|
$groupName, |
91
|
1 |
|
$consumerName |
92
|
|
|
] |
93
|
|
|
] |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
try { |
97
|
1 |
|
return (bool) $this->_client->call($transporter); |
98
|
|
|
} catch (\Exception $exception) { |
99
|
|
|
throw $exception; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |