PredisStorage::moveFromZSetToList()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
nc 2
nop 3
1
<?php
2
/**
3
 * Created by solly [01.11.17 14:06]
4
 */
5
6
namespace insolita\cqueue\Storage;
7
8
use insolita\cqueue\Contracts\StorageInterface;
9
use Predis\ClientInterface;
10
11
class PredisStorage implements StorageInterface
12
{
13
    /**
14
     * @var \Predis\ClientInterface
15
     */
16
    private $redis;
17
    
18
    public function __construct(ClientInterface $client)
19
    {
20
        $this->redis = $client;
21
    }
22
    
23
    public function delete($key)
24
    {
25
        return $this->redis->del([$key]);
26
    }
27
    
28
    public function listCount($key): int
29
    {
30
        return $this->redis->llen($key) ?? 0;
31
    }
32
    
33
    public function listItems($key): array
34
    {
35
        return $this->redis->lrange($key, 0, -1);
36
    }
37
    
38
    public function listPop($key)
39
    {
40
        return $this->redis->rpop($key);
41
    }
42
    
43
    public function listPush($key, array $values)
44
    {
45
        if (!empty($values)) {
46
            $this->redis->lpush($key, $values);
47
        }
48
    }
49
    
50
    public function zSetCount($key): int
51
    {
52
        return $this->redis->zcard($key) ?? 0;
53
    }
54
    
55
    public function zSetItems($key): array
56
    {
57
        return $this->redis->zrange($key, 0, -1);
58
    }
59
    
60
    public function zSetExpiredItems($key, $score): array
61
    {
62
        return $this->redis->zrevrangebyscore($key, $score, '-inf');
63
    }
64
    
65
    public function zSetPush($key, $score, $identity)
66
    {
67
        return $this->redis->zadd($key, [$identity => $score]);
68
    }
69
    
70
    public function zSetRem($key, $identity)
71
    {
72
        return $this->redis->zrem($key, $identity);
73
    }
74
    
75
    public function zSetExists($key, $identity): bool
76
    {
77
        $score = $this->redis->zScore($key, $identity);
78
        return (!is_null($score) && $score !== false);
79
    }
80
    
81
    public function moveFromZSetToList($listKey, $zSetKey, $item)
82
    {
83
        if ($this->redis->zrem($zSetKey, $item) == 1) {
84
            $this->redis->lpush($listKey, [$item]);
85
        }
86
        //If key not in set ?
87
    }
88
}
89