X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/8fb13ce816b85ac414921ecca420671bf74a3eea..49128f0b9da725de992e427fa341a837bcc2991b:/doc/SortCommand.html diff --git a/doc/SortCommand.html b/doc/SortCommand.html index f89fd7c2..90c8ac7f 100644 --- a/doc/SortCommand.html +++ b/doc/SortCommand.html @@ -16,7 +16,7 @@
the BY option takes a pattern (weight_*
in our example) that is usedin order to generate the key names of the weights used for sorting.Weight key names are obtained substituting the first occurrence of*
with the actual value of the elements on the list (1,2,3,4 in our example).
Our previous example will return just the sorted IDs. Often it isneeded to get the actual objects sorted (object_1, ..., object_4 in theexample). We can do it with the following command:-
+Not Sorting at all
+SORT mylist BY nosort +also the BY option can take a "nosort" specifier. This is useful if you want to retrieve a external key (using GET, read below) but you don't want the sorting overhead.+Retrieving external keys
SORT mylist BY weight_* GET object_*Note that GET can be used multiple times in order to get more keys forevery element of the original List, Set or Sorted Set sorted.Since Redis >= 1.1 it's possible to also GET the list elements itselfusing the special # pattern:-+SORT mylist BY weight_* GET object_* GET #Storing the result of a SORT operation
By default SORT returns the sorted elements as its return value.Using the STORE option instead to return the elements SORT willstore this elements as a Redis List in the specified key.An example:-+SORT mylist BY weight_* STORE resultkeyAn interesting pattern using SORT ... STORE consists in associatingan EXPIRE timeout to the resulting key so that inapplications where the result of a sort operation can be cached forsome time other clients will use the cached list instead to call SORTfor every request. When the key will timeout an updated version ofthe cache can be created using SORT ... STORE again.Note that implementing this pattern it is important to avoid that multipleclients will try to rebuild the cached version of the cacheat the same time, so some form of locking should be implemented(for instance using SETNX).-Return value
Multi bulk reply, specifically a list of sorted elements. - +SORT and Hashes: BY and GET by hash field
+It's possible to use BY and GET options against Hash fields using the following syntax:+SORT mylist BY weight_*->fieldname +SORT mylist GET object_*->fieldname ++The two chars string -> is used in order to signal the name of the Hash field. The key is substituted as documented above with sort BY and GET against normal keys, and the Hash stored at the resulting key is accessed in order to retrieve the specified field.Return value
Multi bulk reply, specifically a list of sorted elements.