Skip to content

Commit

Permalink
smaller lua script
Browse files Browse the repository at this point in the history
  • Loading branch information
halaei committed Oct 13, 2016
1 parent 88c72df commit 50e876a
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,8 @@ public function putMany(array $values, $minutes)
*/
public function add($key, $value, $minutes)
{
$lua = <<<'LUA'
if (redis.call('exists', KEYS[1]) > 0) then
return 0
end
redis.call('setex', KEYS[1], ARGV[2], ARGV[1])
return 1
LUA;
$lua = "return redis.call('exists',KEYS[1])<1 and redis.call('setex',KEYS[1],ARGV[2],ARGV[1])";

$value = $this->serialize($value);

return (bool) $this->connection()->eval($lua, 1, $this->prefix.$key, $value, (int) max(1, $minutes * 60));
Expand Down

0 comments on commit 50e876a

Please sign in to comment.