{
  "schema_version": 2,
  "id": "operate/oss_and_stack/stack-with-enterprise/deprecated-features/triggers-and-functions/Quick_Start_RI",
  "title": "Quick start using Redis Insight",
  "url": "https://redis.io/docs/latest/operate/oss_and_stack/stack-with-enterprise/deprecated-features/triggers-and-functions/quick_start_ri/",
  "summary": "Get started with triggers and functions using Redis Insight",
  "aliases": [
    "/develop/interact/programmability/triggers-and-functions/quick_start_cli/"
  ],
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-10-02T14:53:57+01:00",
  "page_type": "content",
  "content_hash": "00fb1d287818964ee1d01ead3df018ffe6a8996e2730f365035514688d01066c",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Make sure that you have [Redis Stack installed](https://redis.io/docs/latest/operate/oss_and_stack/install/install-stack) and running. Alternatively, you can create a [free Redis Cloud account](https://redis.com/try-free/?utm_source=redisio&utm_medium=referral&utm_campaign=2023-09-try_free&utm_content=cu-redis_cloud_users).\n\nIf you haven't already installed Redis Insight, you can download the latest version [here](https://redis.com/redis-enterprise/redis-insight/?_ga=2.232184223.127667221.1704724457-86137583.1685485233&_gl=1*1gygred*_ga*ODYxMzc1ODMuMTY4NTQ4NTIzMw..*_ga_8BKGRQKRPV*MTcwNDkyMzExMC40MDEuMS4xNzA0OTI3MjQ2LjUyLjAuMA..*_gcl_au*MTQzODY1OTU4OS4xNzAxMTg0MzY0). If this is your first time using Redis Insight, you may wish to read through the [Redis Insight guide](https://redis.io/docs/latest/develop/tools/insight) before continuing with this guide."
    },
    {
      "id": "connect-to-redis-stack",
      "title": "Connect to Redis Stack",
      "role": "content",
      "text": "Open the Redis Insight application, and connect to your database by clicking on its database alias.\n\n![](https://redis.io/docs/latest/images/triggers-and-functions/tf-rdi-0.png)"
    },
    {
      "id": "load-a-library",
      "title": "Load a library",
      "role": "content",
      "text": "Click on the triggers and functions icon and then on **+ Library** as shown below.\n\n![](https://redis.io/docs/latest/images/triggers-and-functions/tf-rdi-1.png)\n\nAdd your code to the **Library Code** section of the right-hand panel and then click **Add Library**.\n\n![](https://redis.io/docs/latest/images/triggers-and-functions/tf-rdi-2.png)\n\nYou'll see the following when the library was added:\n\n![](https://redis.io/docs/latest/images/triggers-and-functions/tf-rdi-3.png)\n\nThe `TFCALL` command is used to execute the JavaScript Function. If the command fails, an error will be returned. Click on the **>_ CLI**  button in the lower left-hand corner to open a console window and then run the command shown below.\n\n![](https://redis.io/docs/latest/images/triggers-and-functions/tf-rdi-3a.png)\n\nTo update a library you can edit the library code directly in the interface by clicking on the edit (pencil) icon. When you save your changes, the libary will be reloaded.\n\n![](https://redis.io/docs/latest/images/triggers-and-functions/tf-rdi-4.png)"
    },
    {
      "id": "uploading-an-external-file",
      "title": "Uploading an external file",
      "role": "content",
      "text": "Click on the **+ Add Library** button as before and, instead of adding the code directly into the editor, click on the **Upload** button, select the file from your file browser, and then click on **Add Library**. The file needs to contain the header, which contains the engine identifier, the API version, and the library name: `#!js api_version=1.0 name=myFirstLibrary`.\n\n![](https://redis.io/docs/latest/images/triggers-and-functions/tf-rdi-5.png)"
    },
    {
      "id": "creating-triggers",
      "title": "Creating triggers",
      "role": "content",
      "text": "Functions within Redis can respond to events using keyspace triggers. While the majority of these events are initiated by command invocations, they also include events that occur when a key expires or is removed from the database.\n\nFor the full list of supported events, please refer to the [Redis keyspace notifications page](https://redis.io/docs/latest/develop/pubsub/keyspace-notifications#events-generated-by-different-commands/?utm_source=redis\\&utm_medium=app\\&utm_campaign=redisinsight_triggers_and_functions_guide).\n\nThe following code creates a new keyspace trigger that adds a new field to a new or updated hash with the latest update time.\n\n[code example]\n\nUpdate the existing library as before and then, using the Redis Insight console, add a new hash with the required prefix to trigger the function.\n\n[code example]\n\nRun the [`HGETALL`](https://redis.io/docs/latest/commands/hgetall) command to check if the last updated time is added to the example.\n\n[code example]"
    }
  ],
  "examples": [
    {
      "id": "creating-triggers-ex0",
      "language": "javascript",
      "code": "#!js name=myFirstLibrary api_version=1.0\n\nfunction addLastUpdatedField(client, data) {\n    if(data.event == 'hset') {\n        var currentDateTime = Date.now();\n        client.call('hset', data.key, 'last_updated', currentDateTime.toString());\n    }\n} \n\n// Register the KeySpaceTrigger 'AddLastUpdated' for keys with the prefix 'fellowship'\n// with the callback function 'addLastUpdatedField'.\nredis.registerKeySpaceTrigger('addLastUpdated', 'fellowship:', addLastUpdatedField);\"",
      "section_id": "creating-triggers"
    },
    {
      "id": "creating-triggers-ex1",
      "language": "Shell",
      "code": "> HSET fellowship:1 name \"Frodo Baggins\" title \"The One Ring Bearer\"",
      "section_id": "creating-triggers"
    },
    {
      "id": "creating-triggers-ex2",
      "language": "Shell",
      "code": "> HGETALL fellowship:1\n1) \"name\"\n2) \"Frodo Baggins\"\n3) \"title\"\n4) \"The One Ring Bearer\"\n5) \"last_updated\"\n6) \"1693238681822\"",
      "section_id": "creating-triggers"
    }
  ]
}
