{
  "schema_version": 2,
  "id": "commands/eval",
  "title": "EVAL",
  "url": "https://redis.io/docs/latest/commands/eval/",
  "summary": "Executes a server-side Lua script.",
  "since": "2.6.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": "09e00de0481c5e0b811acfae5eeebe6765325e51abc52b5f776ce3e0cfae4cb3",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "> [!NOTE]\n> This command's behavior varies in clustered Redis environments. See the [multi-key operations](https://redis.io/docs/latest/develop/using-commands/multi-key-operations) page for more information.\n\nExecutes a server-side [Lua](https:lua.org) script with the embedded Redis [Lua 5.1](https://redis.io/docs/latest/develop/programmability/lua-api) interpreter. The first argument is the script’s source code.\n\nThe second argument is the number of input key name arguments, followed by all the keys accessed by the script.\nThese input key names are made available to the script as the [`KEYS` global runtime variable](https://redis.io/docs/latest/develop/programmability/lua-api#the-keys-global-variable).\nAny additional input arguments should not represent names of keys.\n\n**Important:**\nto ensure the correct execution of scripts, both in standalone and clustered deployments, all keys that a script accesses must be explicitly provided as input key arguments.\nScripts should only access keys whose names are given as input arguments.\nScripts should never access keys with programmatically-generated names or based on the contents of data structures stored in the database.\n\n**Note:**\nin some cases, users will abuse Lua `EVAL` by embedding values in the script instead of providing them as arguments, thus generating a different script on each call to `EVAL`.\nThese values are added to the Lua interpreter and cached in Redis, consuming a large amount of memory over time.\n\nStarting with Redis 7.4, Redis evicts scripts loaded with `EVAL` or [`EVAL_RO`](https://redis.io/docs/latest/commands/eval_ro) from the script cache when the cache reaches a certain size. Redis evicts the least recently used scripts first. You can view the number of evicted scripts with the `evicted_scripts` field in [`INFO`](https://redis.io/docs/latest/commands/info).\n\nPlease refer to the [Redis Programmability](https://redis.io/docs/latest/develop/programmability) and [Introduction to Eval Scripts](https://redis.io/docs/latest/develop/programmability/eval-intro) for more information about Lua scripts."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>script</code></summary>\n\nThe Lua script to evaluate.\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 script accesses, provided to it via the Lua global `KEYS` runtime 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 script via the Lua `ARGV` variable.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "The following example will run a script that returns the first argument that 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 script that was executed.\n\n**RESP3:**\n\nThe return value depends on the script that was executed."
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "> EVAL \"return ARGV[1]\" 0 hello\n\"hello\"",
      "section_id": "examples"
    }
  ]
}
