From ff176e10f5b450eba1608307d36c2f3428268ae6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 26 May 2016 15:02:01 -0500 Subject: [PATCH] Revert "Revert "[5.1] Improvements to Redis cache tagging"" (#13731) --- src/Illuminate/Cache/RedisTaggedCache.php | 4 ++-- tests/Cache/CacheTaggedCacheTest.php | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Illuminate/Cache/RedisTaggedCache.php b/src/Illuminate/Cache/RedisTaggedCache.php index faf7d7ebea68..457429146c06 100644 --- a/src/Illuminate/Cache/RedisTaggedCache.php +++ b/src/Illuminate/Cache/RedisTaggedCache.php @@ -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); } } @@ -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); diff --git a/tests/Cache/CacheTaggedCacheTest.php b/tests/Cache/CacheTaggedCacheTest.php index 7e18ce9aaf29..f94111b2a4bd 100644 --- a/tests/Cache/CacheTaggedCacheTest.php +++ b/tests/Cache/CacheTaggedCacheTest.php @@ -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'); @@ -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'); @@ -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');