RedisLock::unlock()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace BrainExe\Core\Application;
4
5
use BrainExe\Core\Annotations\Service;
6
use BrainExe\Core\Traits\RedisTrait;
7
8
/**
9
 * @Service
10
 * @api
11
 */
12
class RedisLock
13
{
14
    private const PREFIX = 'lock:';
15
16
    use RedisTrait;
17
18
    /**
19
     * @param string $name
20
     * @param int $lockTime
21
     * @return bool $got_lock
22
     */
23 1
    public function lock(string $name, int $lockTime) : bool
24
    {
25 1
        $redis = $this->getRedis();
26
27 1
        return (bool)$redis->set(self::PREFIX . $name, '1', 'EX', $lockTime, 'NX');
28
    }
29
30
    /**
31
     * @param string $name
32
     */
33 1
    public function unlock(string $name)
34
    {
35 1
        $this->getRedis()->del(self::PREFIX . $name);
36 1
    }
37
}
38