Skip to content

Commit

Permalink
Return null if cache value is not found (#18984)
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid authored and taylorotwell committed Apr 28, 2017
1 parent 2665d9b commit 7a871be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function many(array $keys)
}, $keys));

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

return $results;
Expand Down
17 changes: 9 additions & 8 deletions tests/Cache/CacheRedisStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@ public function testRedisMultipleValuesAreReturned()
{
$redis = $this->getRedis();
$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
$redis->getRedis()->shouldReceive('mget')->once()->with(['prefix:foo', 'prefix:fizz', 'prefix:norf'])
$redis->getRedis()->shouldReceive('mget')->once()->with(['prefix:foo', 'prefix:fizz', 'prefix:norf', 'prefix:null'])
->andReturn([
serialize('bar'),
serialize('buzz'),
serialize('quz'),
null,
]);
$this->assertEquals([
'foo' => 'bar',
'fizz' => 'buzz',
'norf' => 'quz',
], $redis->many([
'foo', 'fizz', 'norf',
]));

$results = $redis->many(['foo', 'fizz', 'norf', 'null']);

$this->assertEquals('bar', $results['foo']);
$this->assertEquals('buzz', $results['fizz']);
$this->assertEquals('quz', $results['norf']);
$this->assertNull($results['null']);
}

public function testRedisValueIsReturnedForNumerics()
Expand Down

0 comments on commit 7a871be

Please sign in to comment.