eval
Description
Evaluate a LUA script serverside
在服务器端执行LUA脚本
Parameters
script string.
args array, optional.
num_keys int, optional.
Return value
Mixed. What is returned depends on what the LUA script itself returns, which could be a scalar value (int/string), or an array. Arrays that are returned can also contain other arrays, if that's how it was set up in your LUA script. If there is an error executing the LUA script, the getLastError() function can tell you the message that came back from Redis (e.g. compile error).
这个函数返回的结果是函数传输的LUA脚本的执行结果。结果可以是一个普通的数据类型,也可以使一个数组,数组内也可以嵌套数组。无论返回的结果是什么,都是取决于你的LUA脚本是如何执行的。如果你传输的LUA脚本存在错误,那么getLastError()能够返回出REDIS对于这个错误的具体消息。
Examples
$redis->eval("return 1"); // Returns an integer: 1 $redis->eval("return {1,2,3}"); // Returns Array(1,2,3) $redis->del('mylist'); $redis->rpush('mylist','a'); $redis->rpush('mylist','b'); $redis->rpush('mylist','c'); // Nested response: Array(1,2,3,Array('a','b','c')); $redis->eval("return {1,2,3,redis.call('lrange','mylist',0,-1)}}");