RedisClusterAdapter::setSuccess()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
c 2
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace LeoCarmo\CircuitBreaker\Adapters;
4
5
class RedisClusterAdapter extends RedisAdapter
6
{
7
    /**
8
     * @param string $service
9
     * @param int $timeWindow
10
     * @return bool
11
     */
12
    public function incrementFailure(string $service, int $timeWindow): bool
13
    {
14
        $serviceName = $this->makeNamespace($service) . ':failures';
15
16
        if (! $this->redis->get($serviceName)) {
17
            $this->redis->incr($serviceName);
18
            return (bool) $this->redis->expire($serviceName, $timeWindow);
19
        }
20
21
        return (bool) $this->redis->incr($serviceName);
22
    }
23
24
    /**
25
     * @param string $service
26
     */
27
    public function setSuccess(string $service): void
28
    {
29
        $serviceName = $this->makeNamespace($service);
30
31
        $this->redis->del($serviceName . ':open');
32
        $this->redis->del($serviceName . ':failures');
33
        $this->redis->del($serviceName . ':half_open');
34
    }
35
}
36