Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Cache;
4
 
5
class RedisLock extends Lock
6
{
7
    /**
8
     * The Redis factory implementation.
9
     *
10
     * @var \Illuminate\Redis\Connections\Connection
11
     */
12
    protected $redis;
13
 
14
    /**
15
     * Create a new lock instance.
16
     *
17
     * @param  \Illuminate\Redis\Connections\Connection  $redis
18
     * @param  string  $name
19
     * @param  int  $seconds
20
     * @param  string|null  $owner
21
     * @return void
22
     */
23
    public function __construct($redis, $name, $seconds, $owner = null)
24
    {
25
        parent::__construct($name, $seconds, $owner);
26
 
27
        $this->redis = $redis;
28
    }
29
 
30
    /**
31
     * Attempt to acquire the lock.
32
     *
33
     * @return bool
34
     */
35
    public function acquire()
36
    {
37
        if ($this->seconds > 0) {
38
            return $this->redis->set($this->name, $this->owner, 'EX', $this->seconds, 'NX') == true;
39
        } else {
40
            return $this->redis->setnx($this->name, $this->owner) === 1;
41
        }
42
    }
43
 
44
    /**
45
     * Release the lock.
46
     *
47
     * @return bool
48
     */
49
    public function release()
50
    {
51
        return (bool) $this->redis->eval(LuaScripts::releaseLock(), 1, $this->name, $this->owner);
52
    }
53
 
54
    /**
55
     * Releases this lock in disregard of ownership.
56
     *
57
     * @return void
58
     */
59
    public function forceRelease()
60
    {
61
        $this->redis->del($this->name);
62
    }
63
 
64
    /**
65
     * Returns the owner value written into the driver for this lock.
66
     *
67
     * @return string
68
     */
69
    protected function getCurrentOwner()
70
    {
71
        return $this->redis->get($this->name);
72
    }
73
 
74
    /**
75
     * Get the name of the Redis connection being used to manage the lock.
76
     *
77
     * @return string
78
     */
79
    public function getConnectionName()
80
    {
81
        return $this->redis->getName();
82
    }
83
}