SORT_RO
SORT_RO key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC | DESC] [ALPHA]
- Available since:
- Redis Open Source 7.0.0
- Time complexity:
- O(N+M*log(M)) where N is the number of elements in the list or set to sort, and M the number of returned elements. When the elements are not sorted, complexity is O(N).
- ACL categories:
-
@read,@set,@sortedset,@list,@slow,@dangerous, - Compatibility:
- Redis Software and Redis Cloud compatibility
Read-only variant of the SORT command. It is exactly like the original SORT but refuses the STORE option and can safely be used in read-only replicas.
Since the original 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 command of Redis Cluster).
The SORT_RO variant was introduced in order to allow SORT behavior in read-only replicas without breaking compatibility on command flags.
See original SORT for more details.
Required arguments
key
The name of the key to sort. It may hold a list, set, or sorted set.
Optional arguments
BY pattern
Sort 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.
LIMIT offset count
Return a slice of the sorted result: skip offset elements and return up to count.
GET pattern [GET pattern ...]
Return 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.
ASC | DESC
Sort in ascending (ASC, the default) or descending (DESC) order.
ALPHA
Sort the elements lexicographically instead of numerically.
Examples
SORT_RO mylist BY weight_*->fieldname GET object_*->fieldname
Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Standard |
✅ Standard |