Skip to content

Commit

Permalink
Revert "Revert "[5.1] Improvements to Redis cache tagging"" (#13731)
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed May 26, 2016
1 parent 5945837 commit ff176e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Cache/RedisTaggedCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function pushKeys($namespace, $key, $reference)
$fullKey = $this->getPrefix().sha1($namespace).':'.$key;

foreach (explode('|', $namespace) as $segment) {
$this->store->connection()->lpush($this->referenceKey($segment, $reference), $fullKey);
$this->store->connection()->sadd($this->referenceKey($segment, $reference), $fullKey);
}
}

Expand Down Expand Up @@ -143,7 +143,7 @@ protected function deleteKeysByReference($reference)
*/
protected function deleteValues($referenceKey)
{
$values = array_unique($this->store->connection()->lrange($referenceKey, 0, -1));
$values = array_unique($this->store->connection()->smembers($referenceKey));

if (count($values) > 0) {
call_user_func_array([$this->store->connection(), 'del'], $values);
Expand Down
16 changes: 8 additions & 8 deletions tests/Cache/CacheTaggedCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function testRedisCacheTagsPushForeverKeysCorrectly()
$redis = new Illuminate\Cache\RedisTaggedCache($store, $tagSet);
$store->shouldReceive('getPrefix')->andReturn('prefix:');
$store->shouldReceive('connection')->andReturn($conn = m::mock('StdClass'));
$conn->shouldReceive('lpush')->once()->with('prefix:foo:forever', 'prefix:'.sha1('foo|bar').':key1');
$conn->shouldReceive('lpush')->once()->with('prefix:bar:forever', 'prefix:'.sha1('foo|bar').':key1');
$conn->shouldReceive('sadd')->once()->with('prefix:foo:forever', 'prefix:'.sha1('foo|bar').':key1');
$conn->shouldReceive('sadd')->once()->with('prefix:bar:forever', 'prefix:'.sha1('foo|bar').':key1');
$store->shouldReceive('forever')->with(sha1('foo|bar').':key1', 'key1:value');

$redis->forever('key1', 'key1:value');
Expand All @@ -90,8 +90,8 @@ public function testRedisCacheTagsPushStandardKeysCorrectly()
$redis = new Illuminate\Cache\RedisTaggedCache($store, $tagSet);
$store->shouldReceive('getPrefix')->andReturn('prefix:');
$store->shouldReceive('connection')->andReturn($conn = m::mock('StdClass'));
$conn->shouldReceive('lpush')->once()->with('prefix:foo:standard', 'prefix:'.sha1('foo|bar').':key1');
$conn->shouldReceive('lpush')->once()->with('prefix:bar:standard', 'prefix:'.sha1('foo|bar').':key1');
$conn->shouldReceive('sadd')->once()->with('prefix:foo:standard', 'prefix:'.sha1('foo|bar').':key1');
$conn->shouldReceive('sadd')->once()->with('prefix:bar:standard', 'prefix:'.sha1('foo|bar').':key1');
$store->shouldReceive('push')->with(sha1('foo|bar').':key1', 'key1:value');

$redis->put('key1', 'key1:value');
Expand All @@ -107,16 +107,16 @@ public function testRedisCacheTagsCanBeFlushed()
$store->shouldReceive('connection')->andReturn($conn = m::mock('StdClass'));

// Forever tag keys
$conn->shouldReceive('lrange')->once()->with('prefix:foo:forever', 0, -1)->andReturn(['key1', 'key2']);
$conn->shouldReceive('lrange')->once()->with('prefix:bar:forever', 0, -1)->andReturn(['key3']);
$conn->shouldReceive('smembers')->once()->with('prefix:foo:forever')->andReturn(['key1', 'key2']);
$conn->shouldReceive('smembers')->once()->with('prefix:bar:forever')->andReturn(['key3']);
$conn->shouldReceive('del')->once()->with('key1', 'key2');
$conn->shouldReceive('del')->once()->with('key3');
$conn->shouldReceive('del')->once()->with('prefix:foo:forever');
$conn->shouldReceive('del')->once()->with('prefix:bar:forever');

// Standard tag keys
$conn->shouldReceive('lrange')->once()->with('prefix:foo:standard', 0, -1)->andReturn(['key4', 'key5']);
$conn->shouldReceive('lrange')->once()->with('prefix:bar:standard', 0, -1)->andReturn(['key6']);
$conn->shouldReceive('smembers')->once()->with('prefix:foo:standard')->andReturn(['key4', 'key5']);
$conn->shouldReceive('smembers')->once()->with('prefix:bar:standard')->andReturn(['key6']);
$conn->shouldReceive('del')->once()->with('key4', 'key5');
$conn->shouldReceive('del')->once()->with('key6');
$conn->shouldReceive('del')->once()->with('prefix:foo:standard');
Expand Down

0 comments on commit ff176e1

Please sign in to comment.