Skip to content

Commit

Permalink
Return an integer reply for EXISTS
Browse files Browse the repository at this point in the history
  • Loading branch information
kjnsn committed Jun 4, 2018
1 parent bd2af73 commit e921119
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/M6Web/Component/RedisMock/RedisMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ public function type($key)
public function exists($key)
{
if ($this->deleteOnTtlExpired($key)) {
return $this->returnPipedInfo(false);
return $this->returnPipedInfo(0);
}

return $this->returnPipedInfo(array_key_exists($key, self::$dataValues[$this->storage]));
return $this->returnPipedInfo(array_key_exists($key, self::$dataValues[$this->storage]) ? 1 : 0);
}

public function del($key)
Expand Down
48 changes: 24 additions & 24 deletions tests/units/RedisMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public function testSetGetDelExists()
$redisMock = new Redis();

$this->assert
->boolean($redisMock->exists('test'))
->isFalse()
->integer($redisMock->exists('test'))
->isIdenticalTo(0)
->variable($redisMock->get('test'))
->isNull()
->integer($redisMock->del('test'))
Expand All @@ -26,8 +26,8 @@ public function testSetGetDelExists()
->isEqualTo('OK')
->string($redisMock->type('test'))
->isEqualTo('string')
->boolean($redisMock->exists('test'))
->isTrue()
->integer($redisMock->exists('test'))
->isEqualTo(1)
->string($redisMock->get('test'))
->isEqualTo('something')
->integer($redisMock->del('test'))
Expand All @@ -36,15 +36,15 @@ public function testSetGetDelExists()
->isNull()
->string($redisMock->type('test'))
->isEqualTo('none')
->boolean($redisMock->exists('test'))
->isFalse()
->integer($redisMock->exists('test'))
->isEqualTo(0)

->string($redisMock->setex('test1', 5, 'something'))
->isEqualTo('OK')
->string($redisMock->type('test1'))
->isEqualTo('string')
->boolean($redisMock->exists('test1'))
->isTrue()
->integer($redisMock->exists('test1'))
->isEqualTo(1)
->string($redisMock->get('test1'))
->isEqualTo('something')
->integer($redisMock->del('test1'))
Expand All @@ -53,8 +53,8 @@ public function testSetGetDelExists()
->isNull()
->string($redisMock->type('test1'))
->isEqualTo('none')
->boolean($redisMock->exists('test1'))
->isFalse()
->integer($redisMock->exists('test1'))
->isEqualTo(0)

->string($redisMock->set('test1', 'something'))
->isEqualTo('OK')
Expand Down Expand Up @@ -98,12 +98,12 @@ public function testSetGetDelExists()
->isEqualTo('none')
->string($redisMock->set('test', 'something', 1))
->isEqualTo('OK')
->boolean($redisMock->exists('test'))
->isTrue();
->integer($redisMock->exists('test'))
->isEqualTo(1);
sleep(2);
$this->assert
->boolean($redisMock->exists('test'))
->isFalse();
->integer($redisMock->exists('test'))
->isEqualTo(0);

//setnx
$this->assert
Expand Down Expand Up @@ -1352,8 +1352,8 @@ public function testLPushRPushLRemLTrim()
->isEqualTo(array('test' => array('raoul', 'something')))
->string($redisMock->ltrim('test', -1, 0))
->isIdenticalTo('OK')
->boolean($redisMock->exists('test'))
->isIdenticalTo(false)
->integer($redisMock->exists('test'))
->isIdenticalTo(0)
->integer($redisMock->lpush('test', 'raoul'))
->isIdenticalTo(1)
->array($redisMock->getData())
Expand Down Expand Up @@ -1415,12 +1415,12 @@ public function testFlushDb()
$this->assert
->string($redisMock->set('test', 'a'))
->isEqualTo('OK')
->boolean($redisMock->exists('test'))
->isTrue()
->integer($redisMock->exists('test'))
->isEqualTo(1)
->string($redisMock->flushdb())
->isEqualTo('OK')
->boolean($redisMock->exists('test'))
->isFalse();
->integer($redisMock->exists('test'))
->isEqualTo(0);
}

public function testPipeline()
Expand Down Expand Up @@ -1646,10 +1646,10 @@ public function testTwoSeparateStorage()
$redisMock2->selectStorage('alternateStorage');

$this->assert
->boolean($redisMock1->exists('key1'))
->isTrue()
->boolean($redisMock2->exists('key1'))
->isFalse()
->integer($redisMock1->exists('key1'))
->isEqualTo(1)
->integer($redisMock2->exists('key1'))
->isEqualTo(0)
;

$redisMock2->set('key1', 'value2');
Expand Down

0 comments on commit e921119

Please sign in to comment.