{
  "schema_version": 2,
  "id": "develop/reference/errors/common/readonly",
  "title": "READONLY error",
  "url": "https://redis.io/docs/latest/develop/reference/errors/common/readonly/",
  "summary": "A command that changes data was sent to a read-only replica.",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-11-02T15:10:28+01:00",
  "page_type": "content",
  "content_hash": "1826678725dc69a8b2a8354aa31116b570a4767bc17a605fa3205461f06b04f9",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Redis returns this error when you send a command that changes data to a replica. A replica keeps a copy of a primary's data, and by default it's read-only. Only the primary accepts writes.\n\n[code example]\n\nIn redis-py, this error is `ReadOnlyError: You can't write against a read only replica.`\n\nA Lua function, or a script that starts with a `#!lua` line, gets the same error on a replica before it starts, unless it has the `no-writes` flag. A script without that line gets the error when it calls a command that changes data, with the script's details added to the end."
    },
    {
      "id": "example",
      "title": "Example",
      "role": "example",
      "text": "[code example]"
    },
    {
      "id": "how-to-fix-it",
      "title": "How to fix it",
      "role": "content",
      "text": "Check which node you're connected to with [`ROLE`](https://redis.io/docs/latest/commands/role). A replica replies with `slave` as the first item.\n\n- **You meant to connect to the primary.** Check the host and port in your app's configuration.\n- **The primary changed.** After a failover, a replica becomes the new primary, and the old primary can come back as a replica. An app that connects to a fixed address then ends up on a replica. Use a client that finds the current primary for you, through [Redis Sentinel](https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel).\n\nDon't make the replica writable to work around this error. The `replica-read-only no` setting exists for historical reasons, and writes to a replica can make its data differ from the primary's. See [Read-only replica](https://redis.io/docs/latest/operate/oss_and_stack/management/replication#read-only-replica)."
    }
  ],
  "examples": [
    {
      "id": "overview-ex0",
      "language": "plaintext",
      "code": "READONLY You can't write against a read only replica.",
      "section_id": "overview"
    },
    {
      "id": "example-ex0",
      "language": "plaintext",
      "code": "> SET mykey \"value\"\n(error) READONLY You can't write against a read only replica.\n> GET mykey\n\"value\"",
      "section_id": "example"
    }
  ]
}
