Skip to content

Commit 7a871be

Browse files
themsaidtaylorotwell
authored andcommitted
Return null if cache value is not found (#18984)
1 parent 2665d9b commit 7a871be

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/Illuminate/Cache/RedisStore.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function many(array $keys)
7373
}, $keys));
7474

7575
foreach ($values as $index => $value) {
76-
$results[$keys[$index]] = $this->unserialize($value);
76+
$results[$keys[$index]] = ! is_null($value) ? $this->unserialize($value) : null;
7777
}
7878

7979
return $results;

tests/Cache/CacheRedisStoreTest.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ public function testRedisMultipleValuesAreReturned()
3232
{
3333
$redis = $this->getRedis();
3434
$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
35-
$redis->getRedis()->shouldReceive('mget')->once()->with(['prefix:foo', 'prefix:fizz', 'prefix:norf'])
35+
$redis->getRedis()->shouldReceive('mget')->once()->with(['prefix:foo', 'prefix:fizz', 'prefix:norf', 'prefix:null'])
3636
->andReturn([
3737
serialize('bar'),
3838
serialize('buzz'),
3939
serialize('quz'),
40+
null,
4041
]);
41-
$this->assertEquals([
42-
'foo' => 'bar',
43-
'fizz' => 'buzz',
44-
'norf' => 'quz',
45-
], $redis->many([
46-
'foo', 'fizz', 'norf',
47-
]));
42+
43+
$results = $redis->many(['foo', 'fizz', 'norf', 'null']);
44+
45+
$this->assertEquals('bar', $results['foo']);
46+
$this->assertEquals('buzz', $results['fizz']);
47+
$this->assertEquals('quz', $results['norf']);
48+
$this->assertNull($results['null']);
4849
}
4950

5051
public function testRedisValueIsReturnedForNumerics()

0 commit comments

Comments
 (0)