public interface Sort extends Query
Query
, provides for specifying and chaining the query predicates. The results of the sort directive are returned
as an ordered List
of byte[]
values.
Sort instances are obtained directly from the JRedis
client, by calling the eponymous method JRedis#sort(String)
, which expects
a key name as its required arguments.
[Note: this provides the pattern for all future query types: required args are specified in the method that returns the Query
form.]
As with all Query
forms,
do not forget to call Query.exec()
at the end!
Usage:
List
Sort specification elements are all optional. You could simply say:
List
Sort specification elements are also can appear in any order -- the client implementation will send them to the server in the order expected by the protocol, although it is good form to specify the predicates in natural order:
List
Query.Support
Modifier and Type | Method and Description |
---|---|
Sort |
ALPHA()
sort is be default numeric -- use this to indicate lexiographic alphanumeric sort
|
<K> Sort |
BY(K pattern)
species the BY clause
|
Sort |
DESC()
default sort is ASCending -- use this in your sort to specify DESC sort
|
<K> Sort |
GET(K pattern)
specifies the GET clause
|
Sort |
LIMIT(long from,
long count)
Specifies the LIMIT class: from is the initial index, count is the number of results
|
<K> Sort |
STORE(K destKey)
Store the sort results in another key.
|
<K> Sort BY(K pattern)
<K> Sort GET(K pattern)
Sort LIMIT(long from, long count)
from
- limit sort results to element at index 'from'count
- limit sort results to count - results will be result[from] to result[from+count], inclusve.Sort DESC()
Sort ALPHA()
<K> Sort STORE(K destKey)
This command alters the semantics of the Query.exec()
(or Query.execAsync()()
to return a list of size 1, with the single entry being the long value representing the size
of the created (store destination) list.
// NOTE: this is a Long List - javadoc doesn't print the brackets. // ListstoreResult = DefaultCodec.toLong(jredis.sort(srcSet).DESC().STORE(destKey).exec()); // the STORE() option changes result semantics -- now we expect our list to have a single entry // for the size of the stored list // size = sortedSet.get(0); System.out.format("Sorted list (size: %d):\n", size);
Copyright © 2009–2019. All rights reserved.