1 | <?php |
||
13 | class RedisSetDriver implements DriverInterface |
||
14 | { |
||
15 | use MaxItemsTrait; |
||
16 | use ShutdownTrait; |
||
17 | use SerializerAwareTrait; |
||
18 | |||
19 | private $queues = []; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | private $scheduleKey; |
||
25 | |||
26 | /** |
||
27 | * @var Redis |
||
28 | */ |
||
29 | private $redis; |
||
30 | |||
31 | /** |
||
32 | * @var integer |
||
33 | */ |
||
34 | private $refreshInterval; |
||
35 | |||
36 | /** |
||
37 | * Create new RedisSetDriver |
||
38 | * |
||
39 | * This driver is using redis set. With send message it add new item to set |
||
40 | * and in wait() command it is reading new items in this set. |
||
41 | * This driver doesn't use redis pubsub functionality, only redis sets. |
||
42 | * |
||
43 | * Managing connection to redis is up to you and you have to create it outsite |
||
44 | * of this class. You have to have enabled native Redis php extension. |
||
45 | * |
||
46 | * @see examples/redis |
||
47 | 21 | * |
|
48 | * @param Redis $redis |
||
49 | 21 | * @param string $key |
|
50 | 3 | * @param integer $refreshInterval |
|
51 | * @param string $scheduleKey |
||
52 | */ |
||
53 | 18 | public function __construct(Redis $redis, string $key = 'hermes', int $refreshInterval = 1, string $scheduleKey = 'hermes_schedule') |
|
62 | 6 | ||
63 | /** |
||
64 | 6 | * {@inheritdoc} |
|
65 | 6 | */ |
|
66 | public function send(MessageInterface $message, int $priority = Dispatcher::PRIORITY_MEDIUM): bool |
||
76 | 6 | ||
77 | 6 | public function setupPriorityQueue(string $name, int $priority): void |
|
82 | 6 | ||
83 | 3 | private function getKey(int $priority): string |
|
90 | 6 | ||
91 | 6 | /**s |
|
92 | 4 | * {@inheritdoc} |
|
93 | * |
||
94 | 6 | * @throws ShutdownException |
|
95 | */ |
||
96 | public function wait(Closure $callback, array $priorities = []): void |
||
141 | |||
142 | private function pop(string $key): ?string |
||
151 | } |
||
152 |