diff --git a/src/Illuminate/Cache/RedisStore.php b/src/Illuminate/Cache/RedisStore.php index 7d11aee529b8..2226c979617e 100755 --- a/src/Illuminate/Cache/RedisStore.php +++ b/src/Illuminate/Cache/RedisStore.php @@ -124,11 +124,7 @@ public function putMany(array $values, $minutes) */ public function add($key, $value, $minutes) { - $lua = "return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])"; - - return (bool) $this->connection()->eval( - $lua, 1, $this->prefix.$key, $this->serialize($value), (int) max(1, $minutes * 60) - ); + return (bool) $this->connection()->set($key, $value, 'EX', (int) max(1, $minutes * 60), 'NX'); } /** diff --git a/tests/Cache/RedisCacheIntegrationTest.php b/tests/Cache/RedisCacheIntegrationTest.php index e0ac96d53fba..786cf6fb8761 100644 --- a/tests/Cache/RedisCacheIntegrationTest.php +++ b/tests/Cache/RedisCacheIntegrationTest.php @@ -31,6 +31,7 @@ public function testRedisCacheAddTwice() $repository = new Repository($store); $this->assertTrue($repository->add('k', 'v', 60)); $this->assertFalse($repository->add('k', 'v', 60)); + $this->assertGreaterThan(3500, $this->redis->connection()->ttl('k')); } /** @@ -42,6 +43,7 @@ public function testRedisCacheAddFalse() $repository = new Repository($store); $repository->forever('k', false); $this->assertFalse($repository->add('k', 'v', 60)); + $this->assertEquals(-1, $this->redis->connection()->ttl('k')); } /**