Skip to content

Commit c9c8f91

Browse files
committed
use "redis.call" instead of "redis.pcall"; use "evalsha" instead of "eval"
1 parent f477d1a commit c9c8f91

20 files changed

+83
-74
lines changed

src/Commands/Command.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,14 @@ protected function luaSetTtl($ttl)
145145
$script = '';
146146
} elseif ($ttl == Model::TTL_PERSIST) {
147147
$script = <<<LUA
148-
redis.pcall('persist', v);
148+
redis.call('persist', v);
149149
LUA;
150150
} else {
151151
$script = <<<LUA
152-
redis.pcall('expire', v, $ttl);
152+
redis.call('expire', v, $ttl);
153153
LUA;
154154
}
155155

156156
return $script;
157157
}
158-
}
158+
}

src/Commands/GetCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public function getScript()
1717
$script = <<<LUA
1818
local values = {};
1919
for i,v in ipairs(KEYS) do
20-
values[#values+1] = redis.pcall('get',v);
20+
values[#values+1] = redis.call('get',v);
2121
end
2222
return {KEYS,values};
2323
LUA;
2424
return $script;
2525
}
26-
}
26+
}

src/Commands/GetsetHashCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ public function getScript()
1212
local values = {};
1313
local setTtl = $setTtl;
1414
for i,v in ipairs(KEYS) do
15-
local ttl = redis.pcall('ttl', v);
16-
values[#values+1] = redis.pcall('hgetall',v);
17-
redis.pcall('del',v);
15+
local ttl = redis.call('ttl', v);
16+
values[#values+1] = redis.call('hgetall',v);
17+
redis.call('del',v);
1818
local j=1
1919
while j<#ARGV do
20-
redis.pcall('hset',v,ARGV[j],ARGV[j+1]);
20+
redis.call('hset',v,ARGV[j],ARGV[j+1]);
2121
j=j+2
2222
end
2323
if setTtl == 1 then
2424
$luaSetTtl
2525
elseif ttl >= 0 then
26-
redis.pcall('expire',v,ttl)
26+
redis.call('expire',v,ttl)
2727
end
2828
end
2929
return {KEYS,values};
3030
LUA;
3131
return $script;
3232
}
33-
}
33+
}

src/Commands/GetsetListCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ public function getScript()
1212
local values = {};
1313
local setTtl = $setTtl;
1414
for i,v in ipairs(KEYS) do
15-
local ttl = redis.pcall('ttl', v);
16-
values[#values+1] = redis.pcall('lrange',v,0,-1);
17-
redis.pcall('del',v);
15+
local ttl = redis.call('ttl', v);
16+
values[#values+1] = redis.call('lrange',v,0,-1);
17+
redis.call('del',v);
1818
for j=1,#ARGV do
19-
redis.pcall('rpush',v,ARGV[j]);
19+
redis.call('rpush',v,ARGV[j]);
2020
end
2121
if setTtl == 1 then
2222
$luaSetTtl
2323
elseif ttl >= 0 then
24-
redis.pcall('expire',v,ttl)
24+
redis.call('expire',v,ttl)
2525
end
2626
end
2727
return {KEYS,values};
2828
LUA;
2929
return $script;
3030
}
31-
}
31+
}

src/Commands/GetsetSetCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ public function getScript()
1212
local values = {};
1313
local setTtl = $setTtl;
1414
for i,v in ipairs(KEYS) do
15-
local ttl = redis.pcall('ttl', v);
16-
values[#values+1] = redis.pcall('smembers',v);
17-
redis.pcall('del',v);
15+
local ttl = redis.call('ttl', v);
16+
values[#values+1] = redis.call('smembers',v);
17+
redis.call('del',v);
1818
for j=1,#ARGV do
19-
redis.pcall('sadd',v,ARGV[j]);
19+
redis.call('sadd',v,ARGV[j]);
2020
end
2121
if setTtl == 1 then
2222
$luaSetTtl
2323
elseif ttl >= 0 then
24-
redis.pcall('expire',v,ttl)
24+
redis.call('expire',v,ttl)
2525
end
2626
end
2727
return {KEYS,values};
2828
LUA;
2929
return $script;
3030
}
31-
}
31+
}

src/Commands/GetsetStringCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ public function getScript()
2121
local values = {};
2222
local setTtl = $setTtl;
2323
for i,v in ipairs(KEYS) do
24-
local ttl = redis.pcall('ttl', v);
25-
values[#values+1] = redis.pcall('getset',v,ARGV[1]);
24+
local ttl = redis.call('ttl', v);
25+
values[#values+1] = redis.call('getset',v,ARGV[1]);
2626
if setTtl == 1 then
2727
$luaSetTtl
2828
elseif ttl >= 0 then
29-
redis.pcall('expire',v,ttl)
29+
redis.call('expire',v,ttl)
3030
end
3131
end
3232
return {KEYS,values};
3333
LUA;
3434
return $script;
3535
}
36-
}
36+
}

src/Commands/GetsetZsetCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ public function getScript()
1212
local values = {};
1313
local setTtl = $setTtl;
1414
for i,v in ipairs(KEYS) do
15-
local ttl = redis.pcall('ttl', v);
16-
values[#values+1] = redis.pcall('zrange', v, 0, -1);
17-
redis.pcall('del',v);
15+
local ttl = redis.call('ttl', v);
16+
values[#values+1] = redis.call('zrange', v, 0, -1);
17+
redis.call('del',v);
1818
local j=1;
1919
while j<#ARGV do
20-
redis.pcall('zadd',v,ARGV[j],ARGV[j+1]);
20+
redis.call('zadd',v,ARGV[j],ARGV[j+1]);
2121
j=j+2
2222
end
2323
if setTtl == 1 then
2424
$luaSetTtl
2525
elseif ttl >= 0 then
26-
redis.pcall('expire',v,ttl)
26+
redis.call('expire',v,ttl)
2727
end
2828
end
2929
return {KEYS,values};
3030
LUA;
3131
return $script;
3232
}
33-
}
33+
}

src/Commands/HgetallCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public function getScript()
2222
$script = <<<LUA
2323
local values = {};
2424
for i,v in ipairs(KEYS) do
25-
values[#values+1] = redis.pcall('hgetall',v);
25+
values[#values+1] = redis.call('hgetall',v);
2626
end
2727
return {KEYS,values};
2828
LUA;
2929
return $script;
3030
}
31-
}
31+
}

src/Commands/HmsetCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ public function getScript()
2424
local values = {};
2525
local setTtl = '$setTtl';
2626
for i,v in ipairs(KEYS) do
27-
local ttl = redis.pcall('ttl', v)
27+
local ttl = redis.call('ttl', v)
2828
$delScript
2929
local j=1
3030
while j<#ARGV do
31-
values[i]=redis.pcall('hset',v,ARGV[j],ARGV[j+1]);
31+
values[i]=redis.call('hset',v,ARGV[j],ARGV[j+1]);
3232
j=j+2
3333
end
3434
if setTtl == '1' then
3535
$luaSetTtl
3636
elseif ttl > 0 then
37-
redis.pcall('expire', v, ttl);
37+
redis.call('expire', v, ttl);
3838
end
3939
end
4040
return {KEYS,values};
4141
LUA;
4242
return $script;
4343
}
44-
}
44+
}

src/Commands/KeysCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public function getScript()
99
local values={}
1010
for i,v in ipairs(KEYS) do
1111
if string.find(v,'?')~=nil or string.find(v,'*')~=nil then
12-
values[#values+1]=redis.pcall('keys',v)
13-
else if redis.pcall('exists',v)==1 then
12+
values[#values+1]=redis.call('keys',v)
13+
else if redis.call('exists',v)==1 then
1414
values[#values+1] = {v}
1515
end
1616
end
@@ -36,4 +36,4 @@ public function parseResponse($data)
3636

3737
return array_values($keys);
3838
}
39-
}
39+
}

0 commit comments

Comments
 (0)