X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/ab72b4833d2054231437acccec36f32f07290075..7fc98533392f455974d546c88bd4d41c85e6fe6d:/doc/SortCommand.html diff --git a/doc/SortCommand.html b/doc/SortCommand.html index 7ed3eb01..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).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:+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