Skip to content

Commit

Permalink
Revert "[5.4] no eval for RedisStore::add() [requires Redis version >…
Browse files Browse the repository at this point in the history
…= 2.6.12]" (#17484)
  • Loading branch information
taylorotwell authored Jan 22, 2017
1 parent 13b0fe7 commit 3a8dd6b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ public function putMany(array $values, $minutes)
*/
public function add($key, $value, $minutes)
{
return (bool) $this->connection()->set($key, $value, 'EX', (int) max(1, $minutes * 60), 'NX');
$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)
);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions tests/Cache/RedisCacheIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ 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'));
}

/**
Expand All @@ -43,7 +42,6 @@ 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'));
}

/**
Expand Down

0 comments on commit 3a8dd6b

Please sign in to comment.