Queue::removeMessages()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace LeoCarmo\RedisQueue;
4
5
use LeoCarmo\RedisQueue\Exceptions\QueueWithoutConnectionException;
6
7
abstract class Queue
8
{
9
10
    use RedisClient;
11
12
    /**
13
     * @param string $queue
14
     * @param string $worker
15
     * @return string
16
     */
17
    protected static function getProcessingQueueName(string $queue, string $worker)
18
    {
19
        return "{$queue}-worker-{$worker}";
20
    }
21
22
    /**
23
     * @param string $queue
24
     * @return string
25
     */
26
    protected static function getDeadQueueName(string $queue)
27
    {
28
        return "{$queue}-dead";
29
    }
30
31
    /**
32
     * @param string $queue
33
     * @param string $source
34
     * @param string $destination
35
     *
36
     * @throws QueueWithoutConnectionException
37
     */
38
    protected static function moveMessages(string $queue, string $source, string $destination)
39
    {
40
        do {
41
            $value = self::client($queue)->rpoplpush($source, $destination);
42
        } while ($value !== false);
43
    }
44
45
    /**
46
     * @param string $queue
47
     * @param string $key
48
     * @return bool
49
     *
50
     * @throws QueueWithoutConnectionException
51
     */
52
    protected static function removeMessages(string $queue, string $key)
53
    {
54
        return (bool) self::client($queue)->del($key);
55
    }
56
57
    /**
58
     * @param string $queue
59
     * @param string $key
60
     * @return int
61
     *
62
     * @throws QueueWithoutConnectionException
63
     */
64
    protected static function countMessages(string $queue, string $key)
65
    {
66
        return (int) self::client($queue)->lLen($key);
67
    }
68
69
    /**
70
     * @param string $queue
71
     * @param string $key
72
     * @param int $start
73
     * @param int $end
74
     * @return array
75
     *
76
     * @throws QueueWithoutConnectionException
77
     */
78
    protected static function getMessages(string $queue, string $key, int $start, int $end)
79
    {
80
        return self::client($queue)->lRange(
81
            $key, $start, $end
82
        );
83
    }
84
}
85