{
  "schema_version": 2,
  "id": "commands/sort_ro",
  "title": "SORT_RO",
  "url": "https://redis.io/docs/latest/commands/sort_ro/",
  "summary": "Returns the sorted elements of a list, a set, or a sorted set.",
  "since": "7.0.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": "e3088294fb90c18c4cb12939f55251d86e1cce3a8b6bc4e7c58d57083fc57a50",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Read-only variant of the [`SORT`](https://redis.io/docs/latest/commands/sort) command. It is exactly like the original [`SORT`](https://redis.io/docs/latest/commands/sort) but refuses the `STORE` option and can safely be used in read-only replicas.\n\nSince the original [`SORT`](https://redis.io/docs/latest/commands/sort) has a `STORE` option it is technically flagged as a writing command in the Redis command table. For this reason read-only replicas in a Redis Cluster will redirect it to the master instance even if the connection is in read-only mode (see the [`READONLY`](https://redis.io/docs/latest/commands/readonly) command of Redis Cluster).\n\nThe `SORT_RO` variant was introduced in order to allow [`SORT`](https://redis.io/docs/latest/commands/sort) behavior in read-only replicas without breaking compatibility on command flags.\n\nSee original [`SORT`](https://redis.io/docs/latest/commands/sort) for more details."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nThe name of the key to sort. It may hold a list, set, or sorted set.\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>BY pattern</code></summary>\n\nSort by the values of the external keys matched by `pattern` (each `*` is replaced by an element) instead of by the elements themselves. A pattern with no `*`, or a hash-field pattern that resolves the same for all elements, skips sorting.\n\n</details>\n\n<details open><summary><code>LIMIT offset count</code></summary>\n\nReturn a slice of the sorted result: skip `offset` elements and return up to `count`.\n\n</details>\n\n<details open><summary><code>GET pattern [GET pattern ...]</code></summary>\n\nReturn the values of the external keys matched by `pattern` for each sorted element. Use `GET #` to also return the element itself. May be given multiple times.\n\n</details>\n\n<details open><summary><code>ASC | DESC</code></summary>\n\nSort in ascending (`ASC`, the default) or descending (`DESC`) order.\n\n</details>\n\n<details open><summary><code>ALPHA</code></summary>\n\nSort the elements lexicographically instead of numerically.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "[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\n[Array reply](../../develop/reference/protocol-spec#arrays): a list of sorted elements.\n\n**RESP3:**\n\n[Array reply](../../develop/reference/protocol-spec#arrays): a list of sorted elements."
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "SORT_RO mylist BY weight_*->fieldname GET object_*->fieldname",
      "section_id": "examples"
    }
  ]
}
