Skip to content

Commit e1cae24

Browse files
authored
Fix #247: Cache::getValue() now returns false in case of missing key
1 parent d3f79ac commit e1cae24

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Yii Framework 2 redis extension Change Log
44
2.0.18 under development
55
------------------------
66

7-
- no changes in this release.
7+
- Bug #247: `Cache::getValue()` now returns `false` in case of missing key (rhertogh)
88

99

1010
2.0.17 January 11, 2022

UPGRADE.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ if you want to upgrade from version A to version C and there is
1212
version B between A and C, you need to follow the instructions
1313
for both A and B.
1414

15+
Upgrade from 2.0.17
16+
------------------
17+
18+
* The `Cache::getValue()` method now adheres to the specifications and returns `false` in case of a missing
19+
(or expired) key. This might have impact in the following scenarios:
20+
* You specified a custom `Cache::$serializer`, depending on the serializer used `Cache::get()` might now
21+
return `false` instead of `null` in case of a missing (or expired) key.
22+
* You extended the `Cache` class, are using the protected method `Cache::getValue()` directly and expect
23+
a return value of `null` in case of a missing (or expired) key.
24+
1525
Upgrade from 2.0.13
1626
------------------
1727

src/Cache.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,12 @@ public function exists($key)
195195
*/
196196
protected function getValue($key)
197197
{
198-
return $this->getReplica()->executeCommand('GET', [$key]);
198+
$value = $this->getReplica()->executeCommand('GET', [$key]);
199+
if ($value === null) {
200+
return false; // Key is not in the cache or expired
201+
}
202+
203+
return $value;
199204
}
200205

201206
/**

0 commit comments

Comments
 (0)