Completed
Push — develop ( 4d7190...4d7190 )
by Stan
02:29 queued 18s
created

Connection::hsetnx()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Krenor\Prometheus\Storage\Redis;
4
5
abstract class Connection
6
{
7
    /**
8
     * @var \Predis\Client
9
     */
10
    protected $client;
11
12
    /**
13
     * @see https://redis.io/commands/hgetall
14
     *
15
     * @param string $key
16
     *
17
     * @return array
18
     */
19 12
    public function hgetall(string $key): array
20
    {
21 12
        return $this->client->hgetall($key);
22
    }
23
24
    /**
25
     * @see https://redis.io/commands/lrange
26
     *
27
     * @param string $key
28
     * @param int $start
29
     * @param int $stop
30
     *
31
     * @return array
32
     */
33 2
    public function lrange(string $key, int $start, int $stop): array
34
    {
35 2
        return $this->client->lrange($key, $start, $stop);
36
    }
37
38
    /**
39
     * @see https://redis.io/commands/hincrbyfloat
40
     *
41
     * @param string $key
42
     * @param string $field
43
     * @param float $value
44
     *
45
     * @return float
46
     */
47 8
    public function hincrbyfloat(string $key, string $field, float $value): float
48
    {
49 8
        return $this->client->hincrbyfloat($key, $field, $value);
50
    }
51
52
    /**
53
     * @see https://redis.io/commands/hset
54
     *
55
     * @param string $key
56
     * @param string $field
57
     * @param mixed $value
58
     *
59
     * @return int
60
     */
61 1
    public function hset(string $key, string $field, $value): int
62
    {
63 1
        return $this->client->hset($key, $field, $value);
64
    }
65
66
    /**
67
     * @see https://redis.io/commands/hsetnx
68
     *
69
     * @param string $key
70
     * @param string $field
71
     * @param mixed $value
72
     *
73
     * @return int
74
     */
75 1
    public function hsetnx(string $key, string $field, $value): int
76
    {
77 1
        return $this->client->hsetnx($key, $field, $value);
78
    }
79
80
    /**
81
     * @see https://redis.io/commands/rpush
82
     *
83
     * @param string $key
84
     * @param array $values
85
     *
86
     * @return int
87
     */
88 2
    public function rpush(string $key, array $values): int
89
    {
90 2
        return $this->client->rpush($key, ...$values);
91
    }
92
93
    /**
94
     * @see https://redis.io/commands/flushdb
95
     *
96
     * @return bool
97
     */
98 6
    public function flushdb(): bool
99
    {
100 6
        return $this->client->flushdb();
101
    }
102
103
    /**
104
     * @param string $method
105
     * @param array $parameters
106
     *
107
     * @return mixed
108
     */
109
    public function __call(string $method, array $parameters = [])
110
    {
111
        return $this->client->{strtolower($method)}(...$parameters);
112
    }
113
}
114