SORT_RO(3valkey)

πŸ“¦
version 9.0.6 Β· 2 versions
, in fedora 44

πŸ’– 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