Skip to content

Commit

Permalink
FIxed BUG for incorrect result of Redis::HMget and Redis::HGetAll. (#…
Browse files Browse the repository at this point in the history
…239)
  • Loading branch information
limingxinleo authored and swoft-bot committed Nov 14, 2018
1 parent b8d5dfa commit 8f3f5a5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Operator/Hashes/HashGetAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ public function getId()
*/
public function parseResponse($data)
{
$result = array();
if ($data === false) {
return false;
}

$result = [];
for ($i = 0; $i < count($data); ++$i) {
$result[$data[$i]] = $data[++$i];
}
Expand Down
6 changes: 5 additions & 1 deletion src/Operator/Hashes/HashGetMultiple.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ public function getId()
*/
public function parseResponse($data)
{
if ($data === false) {
return false;
}

$result = [];
$hashKeys = $this->getArgument(1);
foreach ($data as $key => $value) {
if (! isset($hashKeys[$key])) {
if (!isset($hashKeys[$key])) {
continue;
}

Expand Down
24 changes: 24 additions & 0 deletions test/Cases/HashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ public function testHmsetAndHmget()
];
$values = $this->redis->hMGet($key, ['NotExistKey', 'NotExistKey2']);
$this->assertEquals($data, $values);

$this->redis->set($key, 'xxxxx');
$result = $this->redis->hMGet($key,['key']);
$this->assertFalse($result);

$this->redis->delete($key);
$result = $this->redis->hMGet($key, ['key']);
$this->assertEquals(['key' => false], $result);

$this->redis->sAdd($key, 'xxxxx');
$result = $this->redis->hMGet($key, ['key']);
$this->assertFalse($result);
}

public function testHmsetAndHmgetByCo()
Expand All @@ -43,6 +55,18 @@ public function testHGetAll()

$result = $this->redis->hGetAll($key);
$this->assertEquals(['key' => 'value', 'key2' => 'value2', 'key3' => 'value3'], $result);

$this->redis->set($key, 'xxxxx');
$result = $this->redis->hGetAll($key);
$this->assertFalse($result);

$this->redis->delete($key);
$result = $this->redis->hGetAll($key);
$this->assertEquals([], $result);

$this->redis->sAdd($key, 'xxxxx');
$result = $this->redis->hGetAll($key);
$this->assertFalse($result);
}

public function testHGetAllByCo()
Expand Down

0 comments on commit 8f3f5a5

Please sign in to comment.