Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

We have the following class:

class MyClass {
    public function __construct($lockFactory) {
        $this->lockFactory = $lockFactory;
    }

    public function acquireLock($uuid) {
        $lock = $this->lockFactory->createLock($uuid);
        return $lock->acquire();
    }
    public function releaseLock($uuid) {
        $lock = $this->lockFactory->createLock($uuid);
        $lock->release();
    }
}

And the following test

$redis = new Redis();
$redis->connect('redis', 'redis-host');
$lockFactory = new LockFactory(new RedisStore($redis));

$uuid = "6a4eae27-0f75-4df8-bb52-3c902eb2367d";
$myClass = new MyClass()
$acquired1 = $myClass->acquireLock($uuid);

// This lock gets acquired as expected
$this->assertTrue($acquired1);

$acquired2 = $myClass->acquireLock($uuid);

// This lock fails to get acquired because we already acquired it, as expected
$this->assertFalse($acquired2);

$myClass->releaseLock($uuid);

$acquired3 = $myClass->acquireLock($uuid);

// We would expect this to get acquired because we released it above, but the below assertion fails
$this->assertTrue($acquired3);

Why does it appear that releasing the lock isn't working? From our understanding of the symfony locking component, release should delete the resource in Redis, allowing the lock to be acquired again


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
387 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...