Skip to content

Commit f5aa18c

Browse files
Merge pull request #97 from Xon/scan_fix
Fix scan behavior for multiple iterations for phpredis vs Credis, and update test
2 parents 049ccfb + bed81ad commit f5aa18c

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

Client.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -829,12 +829,12 @@ public function __call($name, $args)
829829
}
830830
break;
831831
case 'scan':
832-
$ref =& $args[0];
833-
if (empty($ref))
832+
$trackedArgs = array(&$args[0]);
833+
if (empty($trackedArgs[0]))
834834
{
835-
$ref = 0;
835+
$trackedArgs[0] = 0;
836836
}
837-
$eArgs = array($ref);
837+
$eArgs = array($trackedArgs[0]);
838838
if (!empty($args[1]))
839839
{
840840
$eArgs[] = 'MATCH';
@@ -850,12 +850,12 @@ public function __call($name, $args)
850850
case 'sscan':
851851
case 'zscan':
852852
case 'hscan':
853-
$ref =& $args[1];
854-
if (empty($ref))
853+
$trackedArgs = array(&$args[1]);
854+
if (empty($trackedArgs[0]))
855855
{
856-
$ref = 0;
856+
$trackedArgs[0] = 0;
857857
}
858-
$eArgs = array($args[0],$ref);
858+
$eArgs = array($args[0],$trackedArgs[0]);
859859
if (!empty($args[2]))
860860
{
861861
$eArgs[] = 'MATCH';
@@ -1300,7 +1300,7 @@ protected function read_reply($name = '', $returnQueued = false)
13001300
return $response;
13011301
}
13021302

1303-
protected function decode_reply($name, $response, array $arguments = array() )
1303+
protected function decode_reply($name, $response, array &$arguments = array() )
13041304
{
13051305
// Smooth over differences between phpredis and standalone response
13061306
switch ($name)
@@ -1351,12 +1351,12 @@ protected function decode_reply($name, $response, array $arguments = array() )
13511351

13521352
case 'scan':
13531353
case 'sscan':
1354-
$ref = array_shift($response);
1354+
$arguments[0] = intval(array_shift($response));
13551355
$response = empty($response[0]) ? array() : $response[0];
13561356
break;
13571357
case 'hscan':
13581358
case 'zscan':
1359-
$ref = array_shift($response);
1359+
$arguments[0] = intval(array_shift($response));
13601360
$response = empty($response[0]) ? array() : $response[0];
13611361
if (!empty($response) && is_array($response))
13621362
{

tests/CredisTest.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -718,11 +718,30 @@ public function testZscan()
718718
}
719719
public function testscan()
720720
{
721-
$this->credis->set('name','Jack');
722-
$this->credis->set('age','33');
721+
$seen = array();
722+
for($i = 0; $i < 100; $i++)
723+
{
724+
$this->credis->set('name.' . $i, 'Jack');
725+
$this->credis->set('age.' . $i, '33');
726+
}
723727
$iterator = null;
724-
$result = $this->credis->scan($iterator,'n*',10);
725-
$this->assertEquals($iterator,0);
726-
$this->assertEquals($result,['name']);
728+
do
729+
{
730+
$result = $this->credis->scan($iterator, 'n*', 10);
731+
if ($result === false)
732+
{
733+
$this->assertEquals($iterator, 0);
734+
break;
735+
}
736+
else
737+
{
738+
foreach($result as $key)
739+
{
740+
$seen[$key] = true;
741+
}
742+
}
743+
}
744+
while($iterator);
745+
$this->assertEquals(count($seen), 100);
727746
}
728747
}

0 commit comments

Comments
 (0)