{
  "schema_version": 2,
  "id": "commands/fcall",
  "title": "FCALL",
  "url": "https://redis.io/docs/latest/commands/fcall/",
  "summary": "Invokes a function.",
  "since": "7.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:48:32+01:00",
  "page_type": "content",
  "content_hash": "874ae1e7a841329e5125507ff7144ceda2792a7d3393b48d0dcd8dc613283f69",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Invoke a function.\n\nFunctions are loaded to the server with the [`FUNCTION LOAD`](https://redis.io/docs/latest/commands/function-load) command.\nThe first argument is the name of a loaded function.\n\nThe second argument is the number of input key name arguments, followed by all the keys accessed by the function.\nIn Lua, these input keys names are available to the function as a table that is the callback's first argument.\n\n**Important:**\nTo ensure the correct execution of functions, both in standalone and clustered deployments, all the key names that a function accesses must be explicitly provided as input key arguments.\nThe function should only access keys whose names are given as input arguments.\nFunctions should never access keys with programmatically-generated names or based on the contents of data structures stored in the database.\n\nAny additional input arguments should not represent names of keys.\nThese are regular arguments and are passed in a Lua table as the callback's second argument.\n\nFor more information please refer to the [Redis Programmability](https://redis.io/docs/latest/develop/programmability) and [Introduction to Redis Functions](https://redis.io/docs/latest/develop/programmability/functions-intro) pages."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>function</code></summary>\n\nThe name of the function to call.\n\n</details>\n\n<details open><summary><code>numkeys</code></summary>\n\nThe number of key names that follow. Arguments after the keys are passed as regular arguments.\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>key [key ...]</code></summary>\n\nThe key names the function accesses, provided to it via the Lua  `KEYS` global variable. There must be exactly `numkeys` of them.\n\n</details>\n\n<details open><summary><code>arg [arg ...]</code></summary>\n\nAdditional arguments provided to the function via the Lua `ARGV` variable.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "The following example will create a library named `mylib` with a single function, `myfunc`, that returns the first argument it gets.\n\n[code example]"
    },
    {
      "id": "redis-software-and-redis-cloud-compatibility",
      "title": "Redis Software and Redis Cloud compatibility",
      "role": "content",
      "text": "| Redis<br />Software | Redis<br />Cloud | <span style=\"min-width: 9em; display: table-cell\">Notes</span> |\n|:----------------------|:-----------------|:------|\n| <span title=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; Active-Active</nobr></span> | <span title=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; Active-Active</nobr></span> |  |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\nThe return value depends on the function that was executed.\n\n**RESP3:**\n\nThe return value depends on the function that was executed."
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "redis> FUNCTION LOAD \"#!lua name=mylib \\n redis.register_function('myfunc', function(keys, args) return args[1] end)\"\n\"mylib\"\nredis> FCALL myfunc 0 hello\n\"hello\"",
      "section_id": "examples"
    }
  ]
}
