Skip to content

Commit 0966e0c

Browse files
committed
Merge branch '10.x'
2 parents 12cbfa5 + 9b97007 commit 0966e0c

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/Illuminate/Cache/RedisTaggedCache.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@ public function add($key, $value, $ttl = null)
1919
if ($ttl !== null) {
2020
$seconds = $this->getSeconds($ttl);
2121

22-
if ($seconds <= 0) {
23-
return false;
22+
if ($seconds > 0) {
23+
$this->tags->addEntry(
24+
$this->itemKey($key),
25+
$seconds
26+
);
2427
}
2528
}
2629

27-
$this->tags->addEntry(
28-
$this->itemKey($key),
29-
$seconds
30-
);
31-
3230
return parent::add($key, $value, $ttl);
3331
}
3432

@@ -48,15 +46,13 @@ public function put($key, $value, $ttl = null)
4846

4947
$seconds = $this->getSeconds($ttl);
5048

51-
if ($seconds <= 0) {
52-
return false;
49+
if ($seconds > 0) {
50+
$this->tags->addEntry(
51+
$this->itemKey($key),
52+
$seconds
53+
);
5354
}
5455

55-
$this->tags->addEntry(
56-
$this->itemKey($key),
57-
$seconds
58-
);
59-
6056
return parent::put($key, $value, $ttl);
6157
}
6258

tests/Integration/Cache/RedisStoreTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ public function testItCanStoreNan()
7676
$this->assertNan(Cache::store('redis')->get('foo'));
7777
}
7878

79+
public function testItCanExpireWithZeroTTL()
80+
{
81+
Cache::store('redis')->clear();
82+
83+
$result = Cache::store('redis')->put('foo', 10, 10);
84+
$this->assertTrue($result);
85+
86+
$result = Cache::store('redis')->put('foo', 10, 0);
87+
$this->assertTrue($result);
88+
89+
$value = Cache::store('redis')->get('foo');
90+
$this->assertNull($value);
91+
}
92+
7993
public function testTagsCanBeAccessed()
8094
{
8195
Cache::store('redis')->clear();
@@ -146,6 +160,9 @@ public function testPastTtlTagEntriesAreNotAdded()
146160

147161
Cache::store('redis')->tags(['votes'])->add('person-1', 0, new DateTime('yesterday'));
148162

163+
$value = Cache::store('redis')->tags(['votes'])->get('person-1');
164+
$this->assertNull($value);
165+
149166
$keyCount = Cache::store('redis')->connection()->keys('*');
150167
$this->assertEquals(0, count($keyCount));
151168
}

0 commit comments

Comments
 (0)