SORT_RO(3valkey)
π SORT_RO π
okay bestie so this is SORT_RO from the Valkey Command Manual and it is literally the chill, read-only version of SORT and I'm obsessed π
β¨ NAME β¨
sort_ro β gives you back the sorted elements of a list, a set, or a sorted set π
β¨ SYNOPSIS β¨
SORT_RO key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern
...]] [ASC | DESC] [ALPHA]
β¨ DESCRIPTION β¨
okay so it's the read-only variant of the valkey-sort(7) SORT command. It's exactly like the original SORT except it flat-out refuses the STORE option, and because of that you can safely run it on read-only replicas. no cap. π¦
here's the tea tho: since the original SORT has a STORE option, it's technically flagged as a writing command in the Valkey command table. which means read-only replicas in a Valkey Cluster will redirect it to the primary instance, even if the connection is in read-only mode (peep the valkey-readonly(7) READONLY command of Valkey Cluster if you wanna know more π).
so the SORT_RO variant exists specifically to let you get SORT behavior on read-only replicas without breaking compatibility on command flags. iconic behavior honestly. π
if you want more deets, go see the original SORT. iykyk. β¨
β¨ REPLY β¨
valkey-protocol(7) Array reply: a list of sorted elements. that's it, that's the reply π
β¨ COMPLEXITY β¨
O(N+M*log(M)) where N is the number of elements in the list or set to sort, and M is the number of returned elements. and when the elements are not sorted, the complexity is O(N). math queen behavior fr fr π
β¨ ACL CATEGORIES β¨
@dangerous @list @read @set @slow @sortedset
β¨ HISTORY β¨
- Available since:
7.0.0π
β¨ EXAMPLES β¨
SORT_RO mylist BY weight_*->fieldname GET object_*->fieldname
β¨ SEE ALSO β¨
copy(3valkey), del(3valkey), dump(3valkey), exists(3valkey), expire(3valkey), expireat(3valkey), expiretime(3valkey), keys(3valkey), migrate(3valkey), move(3valkey), object(3valkey), object-encoding(3valkey), object-freq(3valkey), object-help(3valkey), object-idletime(3valkey), object-refcount(3valkey), persist(3valkey), pexpire(3valkey), pexpireat(3valkey), pexpiretime(3valkey), pttl(3valkey), randomkey(3valkey), rename(3valkey), renamenx(3valkey), restore(3valkey), scan(3valkey), sort(3valkey), touch(3valkey), ttl(3valkey), type(3valkey), unlink(3valkey), wait(3valkey), waitaof(3valkey)
ok that's the whole page bestie, go slay π
this lil cutie is from version 9.0.0, dated 2025-10-21, and it lives in the SORT_RO(3valkey) page π«Ά bye ily
π¦ where this page comes from
- fedora 44: valkey-doc 9.0.3-2.fc44 Β· CC-BY-SA-4.0
- fedora 44: valkey-doc 9.0.6-1.fc44 Β· CC-BY-SA-4.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms