Skip to content

Commit

Permalink
allow tagged keys to increment and decrement (#23578)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDestroyer authored and taylorotwell committed Mar 17, 2018
1 parent e81d166 commit 2a4214c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/Illuminate/Cache/RedisTaggedCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,34 @@ public function put($key, $value, $minutes = null)
parent::put($key, $value, $minutes);
}

/**
* Increment the value of an item in the cache.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function increment($key, $value = 1)
{
$this->pushStandardKeys($this->tags->getNamespace(), $key);

parent::increment($key, $value);
}

/**
* Decrement the value of an item in the cache.
*
* @param string $key
* @param mixed $value
* @return void
*/
public function decrement($key, $value = 1)
{
$this->pushStandardKeys($s->tags->getNamespace(), $key);

parent::decrement($key, $value);
}

/**
* Store an item in the cache indefinitely.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/TaggedCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function increment($key, $value = 1)
}

/**
* Increment the value of an item in the cache.
* Decrement the value of an item in the cache.
*
* @param string $key
* @param mixed $value
Expand Down
18 changes: 18 additions & 0 deletions tests/Cache/CacheTaggedCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,24 @@ public function testTagsWithStringArgument()
$this->assertEquals('bar', $store->tags('bop')->get('foo'));
}

public function testTagsWithIncrementCanBeFlushed()
{
$store = new ArrayStore;
$store->tags('bop')->increment('foo', 5);
$this->assertEquals(5, $store->tags('bop')->get('foo'));
$store->tags('bop')->flush();
$this->assertNull($store->tags('bop')->get('foo'));
}

public function testTagsWithDecrementCanBeFlushed()
{
$store = new ArrayStore;
$store->tags('bop')->decrement('foo', 5);
$this->assertEquals(-5, $store->tags('bop')->get('foo'));
$store->tags('bop')->flush();
$this->assertNull($store->tags('bop')->get('foo'));
}

public function testTagsCacheForever()
{
$store = new ArrayStore;
Expand Down

0 comments on commit 2a4214c

Please sign in to comment.