Passed
Push — master ( d4f709...8319cd )
by Mike
07:40 queued 01:16
created

PredisAdapter::ping()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 6
1
<?php
2
3
namespace MGDigital\BusQue\Redis\Predis;
4
5
use MGDigital\BusQue\Exception\RedisException;
6
use MGDigital\BusQue\Redis\RedisAdapterInterface;
7
use Predis\ClientInterface;
8
use Predis\Connection\ConnectionException as PredisConnectionException;
9
10
class PredisAdapter implements RedisAdapterInterface
11
{
12
13
    private $client;
14
15
    public function __construct(ClientInterface $client)
16
    {
17
        $this->client = $client;
18
    }
19
20
    public function ping()
21
    {
22
        try {
23
            $this->client->ping();
24
        } catch (PredisConnectionException $e) {
25
            throw new RedisException();
26
        }
27
    }
28
29
    public function bRPopLPush(string $source, string $destination, int $timeout = null)
30
    {
31
        try {
32
            return $this->client->brpoplpush($source, $destination, $timeout);
33
        } catch (PredisConnectionException $e) {
34
            throw new RedisException();
35
        }
36
    }
37
38
    public function hGet(string $key, string $field)
39
    {
40
        try {
41
            return $this->client->hget($key, $field);
42
        } catch (PredisConnectionException $e) {
43
            throw new RedisException();
44
        }
45
    }
46
47
    public function sAdd(string $key, array $members)
48
    {
49
        try {
50
            $this->client->sadd($key, $members);
51
        } catch (PredisConnectionException $e) {
52
            throw new RedisException();
53
        }
54
    }
55
56
    public function sIsMember(string $key, string $value): bool
57
    {
58
        try {
59
            return $this->client->sismember($key, $value);
60
        } catch (PredisConnectionException $e) {
61
            throw new RedisException();
62
        }
63
    }
64
65
    public function sMembers(string $key): array
66
    {
67
        try {
68
            return $this->client->smembers($key);
69
        } catch (PredisConnectionException $e) {
70
            throw new RedisException();
71
        }
72
    }
73
74
    public function lLen(string $key): int
75
    {
76
        try {
77
            return $this->client->llen($key);
78
        } catch (PredisConnectionException $e) {
79
            throw new RedisException();
80
        }
81
    }
82
83
    public function lRange(string $key, int $offset = 0, int $limit = 10): array
84
    {
85
        try {
86
            return $this->client->lrange($key, $offset, $limit);
87
        } catch (PredisConnectionException $e) {
88
            throw new RedisException();
89
        }
90
    }
91
92 View Code Duplication
    public function zScore(string $key, string $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
93
    {
94
        try {
95
            $score = $this->client->zscore($key, $value);
96
        } catch (PredisConnectionException $e) {
97
            throw new RedisException();
98
        }
99
        return $score === null ? $score : intval($score);
100
    }
101
102
    public function del(string $key)
103
    {
104
        try {
105
            $this->client->del($key);
106
        } catch (PredisConnectionException $e) {
107
            throw new RedisException();
108
        }
109
    }
110
111
    public function evalScript(string $path, array $args)
112
    {
113
        $command = new LuaFileCommand($path);
114
        $command->setArguments($args);
115
        return $this->client->executeCommand($command);
116
    }
117
}
118