当我将 Lua 脚本注册到 redis 客户端时:
script = redis_client.register_script(lua_string)
然后使用默认客户端运行脚本:
script(keys, args)
这会在内部自动使用 evalsha 还是每次都将整个脚本发送到服务器?
是的。这是(删节的)源代码:
class Script(object):
def __call__(self, keys=[], args=[], client=None):
if isinstance(client, BasePipeline):
# Make sure the pipeline can register the script before executing.
client.scripts.add(self)
return client.evalsha(self.sha, len(keys), *args)