{
  "id": "rg-jexecute",
  "title": "RG.JEXECUTE",
  "url": "https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/gears-v1/jvm/commands/rg-jexecute/",
  "summary": "Executes a Java function.",
  "tags": [
    "docs",
    "operate",
    "stack"
  ],
  "last_updated": "2026-04-22T11:55:45+02:00",
  "page_type": "content",
  "content_hash": "0c50bbacaa2dcdfce012a942f46e2d159b56ba62a74adb2d0d38ab43a4538d0b",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "[code example]\n\nExecutes a Java function.\n\nThe code runs immediately if it uses [`GearsBuilder.run()`](https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/gears-v1/jvm/classes/gearsbuilder/run). Code that uses [`GearsBuilder.register()`](https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/gears-v1/jvm/classes/gearsbuilder/register) will run later, every time certain events occur in the database."
    },
    {
      "id": "arguments",
      "title": "Arguments",
      "role": "parameters",
      "text": "| Name | Description |\n|------|-------------|\n| path.to.main.class | The path to the main class in the JAR |\n| JAR file | A JAR file that contains the RedisGears code to run or register |\n| UPGRADE | Upgrades registered code to a new version |"
    },
    {
      "id": "returns",
      "title": "Returns",
      "role": "returns",
      "text": "If the executed code calls [`GearsBuilder.run()`](https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/gears-v1/jvm/classes/gearsbuilder/run), it returns the output of the executed code.\n\nFor registered code, it returns the string \"`OK`\" instead."
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "The executed code in this example [runs](https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/gears-v1/jvm/classes/gearsbuilder/run) immediately:\n\n[code example]\n\nThis example [registers](https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/gears-v1/jvm/classes/gearsbuilder/register) the RedisGears code to run every time certain database events occur:\n\n[code example]\n\nHere's an example of how to upgrade registered code to a new version:\n\n[code example]"
    }
  ],
  "examples": [
    {
      "id": "overview-ex0",
      "language": "sh",
      "code": "RG.JEXECUTE <path.to.main.class> [UPGRADE] <JAR file>",
      "section_id": "overview"
    },
    {
      "id": "examples-ex0",
      "language": "sh",
      "code": "$ redis-cli -x RG.JEXECUTE com.domain.packagename.Reviews < /tmp/rgjvmtest-0.0.1-SNAPSHOT.jar\n1) 1) \"3.6666666666666665\"\n2) (empty array)",
      "section_id": "examples"
    },
    {
      "id": "examples-ex1",
      "language": "sh",
      "code": "$ redis-cli -x RG.JEXECUTE com.domain.packagename.App < /tmp/rgjvmtest-0.0.1-SNAPSHOT.jar\nOK",
      "section_id": "examples"
    },
    {
      "id": "examples-ex2",
      "language": "sh",
      "code": "$ redis-cli -x RG.JEXECUTE com.domain.packagename.App UPGRADE < /tmp/rgjvmtest-0.0.2-SNAPSHOT.jar\nOK",
      "section_id": "examples"
    }
  ]
}
