Code Duplication    Length = 61-61 lines in 2 locations

src/Lock/PhpRedisLock.php 1 location

@@ 19-79 (lines=61) @@
16
 *
17
 * @author leo108 <[email protected]>
18
 */
19
class PhpRedisLock extends LockAbstract
20
{
21
    /**
22
     * phpredis connection
23
     *
24
     * @var
25
     */
26
    protected $client;
27
28
    /**
29
     * @param $client Redis
30
     */
31
    public function __construct(Redis $client)
32
    {
33
        parent::__construct();
34
35
        $this->client = $client;
36
    }
37
38
    /**
39
     * @param  string $name
40
     * @param  bool   $blocking
41
     * @return bool
42
     */
43
    protected function getLock($name, $blocking)
44
    {
45
        if (!$this->client->setnx($name, serialize($this->getLockInformation()))) {
46
            return false;
47
        }
48
49
        return true;
50
    }
51
52
    /**
53
     * Release lock
54
     *
55
     * @param  string $name name of lock
56
     * @return bool
57
     */
58
    public function releaseLock($name)
59
    {
60
        if (isset($this->locks[$name]) && $this->client->del($name)) {
61
            unset($this->locks[$name]);
62
63
            return true;
64
        }
65
66
        return false;
67
    }
68
69
    /**
70
     * Check if lock is locked
71
     *
72
     * @param  string $name name of lock
73
     * @return bool
74
     */
75
    public function isLocked($name)
76
    {
77
        return false !== $this->client->get($name);
78
    }
79
}
80

src/Lock/PredisRedisLock.php 1 location

@@ 19-79 (lines=61) @@
16
 *
17
 * @author Kamil Dziedzic <[email protected]>
18
 */
19
class PredisRedisLock extends LockAbstract
20
{
21
    /**
22
     * Predis connection
23
     *
24
     * @var
25
     */
26
    protected $client;
27
28
    /**
29
     * @param $client Predis\Client
30
     */
31
    public function __construct(Predis\Client $client)
32
    {
33
        parent::__construct();
34
35
        $this->client = $client;
36
    }
37
38
    /**
39
     * @param  string $name
40
     * @param  bool   $blocking
41
     * @return bool
42
     */
43
    protected function getLock($name, $blocking)
44
    {
45
        if (!$this->client->setnx($name, serialize($this->getLockInformation()))) {
46
            return false;
47
        }
48
49
        return true;
50
    }
51
52
    /**
53
     * Release lock
54
     *
55
     * @param  string $name name of lock
56
     * @return bool
57
     */
58
    public function releaseLock($name)
59
    {
60
        if (isset($this->locks[$name]) && $this->client->del($name)) {
61
            unset($this->locks[$name]);
62
63
            return true;
64
        }
65
66
        return false;
67
    }
68
69
    /**
70
     * Check if lock is locked
71
     *
72
     * @param  string $name name of lock
73
     * @return bool
74
     */
75
    public function isLocked($name)
76
    {
77
        return null !== $this->client->get($name);
78
    }
79
}
80