Skip to content

Commit 65f3a2e

Browse files
[9.x] Fixes usage of Redis::many() with empty array (#47307)
* Fixes retrieve empty array of keys in Redis * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <[email protected]>
1 parent d7ff371 commit 65f3a2e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Illuminate/Cache/RedisStore.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public function get($key)
7474
*/
7575
public function many(array $keys)
7676
{
77+
if (count($keys) === 0) {
78+
return [];
79+
}
80+
7781
$results = [];
7882

7983
$values = $this->connection()->mget(array_map(function ($key) {

tests/Integration/Cache/RedisStoreTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,24 @@ public function testItCanStoreNan()
4545
$this->assertTrue($result);
4646
$this->assertNan(Cache::store('redis')->get('foo'));
4747
}
48+
49+
public function testItMultipleItemsCanBeSetAndRetrieved()
50+
{
51+
$store = Cache::store('redis');
52+
$result = $store->put('foo', 'bar', 10);
53+
$resultMany = $store->putMany([
54+
'fizz' => 'buz',
55+
'quz' => 'baz',
56+
], 10);
57+
$this->assertTrue($result);
58+
$this->assertTrue($resultMany);
59+
$this->assertEquals([
60+
'foo' => 'bar',
61+
'fizz' => 'buz',
62+
'quz' => 'baz',
63+
'norf' => null,
64+
], $store->many(['foo', 'fizz', 'quz', 'norf']));
65+
66+
$this->assertEquals([], $store->many([]));
67+
}
4868
}

0 commit comments

Comments
 (0)