Skip to content

Commit

Permalink
[9.x] Fixes usage of Redis::many() with empty array (#47307)
Browse files Browse the repository at this point in the history
* Fixes retrieve empty array of keys in Redis

* Apply fixes from StyleCI

---------

Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
nunomaduro and StyleCIBot authored Jun 1, 2023
1 parent d7ff371 commit 65f3a2e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public function get($key)
*/
public function many(array $keys)
{
if (count($keys) === 0) {
return [];
}

$results = [];

$values = $this->connection()->mget(array_map(function ($key) {
Expand Down
20 changes: 20 additions & 0 deletions tests/Integration/Cache/RedisStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,24 @@ public function testItCanStoreNan()
$this->assertTrue($result);
$this->assertNan(Cache::store('redis')->get('foo'));
}

public function testItMultipleItemsCanBeSetAndRetrieved()
{
$store = Cache::store('redis');
$result = $store->put('foo', 'bar', 10);
$resultMany = $store->putMany([
'fizz' => 'buz',
'quz' => 'baz',
], 10);
$this->assertTrue($result);
$this->assertTrue($resultMany);
$this->assertEquals([
'foo' => 'bar',
'fizz' => 'buz',
'quz' => 'baz',
'norf' => null,
], $store->many(['foo', 'fizz', 'quz', 'norf']));

$this->assertEquals([], $store->many([]));
}
}

0 comments on commit 65f3a2e

Please sign in to comment.