Skip to content

Commit

Permalink
Merge pull request #24 from swooletw/fix/redis-zscan
Browse files Browse the repository at this point in the history
fix redis zscan
  • Loading branch information
albertcht authored Jan 8, 2024
2 parents cc361bd + e0e9ce2 commit b60a3ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/cache/src/RedisTaggedCacheChunkedEntries.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public function next(): void
$this->nextScanCursor = '0';
}

if ($this->nextScanCursor === $this->scanCursor) {
$this->nextScanCursor = '0';
}

$this->scanCursor = $this->nextScanCursor;

if ($this->scanCursor === '0') {
Expand Down Expand Up @@ -83,16 +87,17 @@ protected function tagId(): ?string

protected function scan(string $tagId, string $cursor): array
{
[$nextCursor, $entries] = $this->store->connection()->zscan(
$entries = $this->store->connection()->zscan(
$this->store->getPrefix() . $tagId,
$cursor,
['match' => '*', 'count' => $this->chunkSize]
'*',
$this->chunkSize
);

if (! is_array($entries)) {
throw new RuntimeException('Entries is not an array.');
}

return [$nextCursor, $entries];
return ["{$cursor}", $entries];
}
}
8 changes: 4 additions & 4 deletions tests/Cache/CacheRedisTaggedCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public function testTagEntriesCanBeStoredForever()
$this->redisProxy
->shouldReceive('zScan')
->once()
->with('prefix:tag:people:entries', '0', ['match' => '*', 'count' => 1000])
->andReturn(['0', ['tag:people:entries:name' => 0, 'tag:people:entries:age' => 0]]);
->with('prefix:tag:people:entries', '0', '*', 1000)
->andReturn(['tag:people:entries:name' => 0, 'tag:people:entries:age' => 0]);
$this->redisProxy
->shouldReceive('zScan')
->once()
->with('prefix:tag:author:entries', '0', ['match' => '*', 'count' => 1000])
->andReturn(['0', ['tag:author:entries:name' => 0, 'tag:author:entries:age' => 0]]);
->with('prefix:tag:author:entries', '0', '*', 1000)
->andReturn(['tag:author:entries:name' => 0, 'tag:author:entries:age' => 0]);
$this->redisProxy->shouldReceive('del')->once()->with(
'prefix:tag:people:entries:name',
'prefix:tag:people:entries:age'
Expand Down

0 comments on commit b60a3ae

Please sign in to comment.