FCALL

Syntax
FCALL function numkeys [key [key ...]] [arg [arg ...]]
Available since:
7.0.0
Time complexity:
Depends on the function that is executed.
ACL categories:
@slow, @scripting,

调用一个函数。

函数通过FUNCTION LOAD命令加载到服务器。 第一个参数是加载函数的名称。

第二个参数是输入键名参数的数量,后面是函数访问的所有键。 在Lua中,这些输入键的名称作为回调函数的第一个参数的表提供给函数。

重要提示: 为了确保函数在独立和集群部署中的正确执行,函数访问的所有键名必须明确作为输入键参数提供。 函数应仅访问那些名称作为输入参数提供的键。 函数绝不应访问那些通过编程生成的名称或基于数据库中存储的数据结构内容的键。

任何额外的输入参数不应表示键的名称。 这些是常规参数,并作为回调的第二个参数传递到Lua表中。

欲了解更多信息,请参阅Redis ProgrammabilityIntroduction to Redis Functions页面。

示例

以下示例将创建一个名为 mylib 的库,其中包含一个函数 myfunc,该函数返回它接收到的第一个参数。

redis> FUNCTION LOAD "#!lua name=mylib \n redis.register_function('myfunc', function(keys, args) return args[1] end)"
"mylib"
redis> FCALL myfunc 0 hello
"hello"

RESP2/RESP3 回复

The return value depends on the function that was executed.
RATE THIS PAGE
Back to top ↑