diff --git a/src/main/java/redis/clients/jedis/SortingParams.java b/src/main/java/redis/clients/jedis/SortingParams.java index 66fd997..2129025 100644 --- a/src/main/java/redis/clients/jedis/SortingParams.java +++ b/src/main/java/redis/clients/jedis/SortingParams.java @@ -26,8 +26,25 @@ public class SortingParams { * @return the SortingParams Object */ public SortingParams by(final String pattern) { + return by(pattern.getBytes(Protocol.UTF8)); + } + + /** + * Sort by weight in keys. + *
+ * Takes a pattern that is used in 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. + *
+ * The pattern for a normal key/value pair is "keyname*" and for a value in + * a hash "keyname*->fieldname". + * + * @param pattern + * @return the SortingParams Object + */ + public SortingParams by(final byte[] pattern) { params.add(BY.raw); - params.add(pattern.getBytes(Protocol.UTF8)); + params.add(pattern); return this; } @@ -117,4 +134,27 @@ public class SortingParams { } return this; } + + /** + * Retrieving external keys from the result of the search. + *
+ * Takes a pattern that is used in order to generate the key names of the + * result of sorting. The key names are obtained substituting the first + * occurrence of * with the actual value of the elements on the list. + *
+ * The pattern for a normal key/value pair is "keyname*" and for a value in + * a hash "keyname*->fieldname". + *
+ * To get the list itself use the char # as pattern.
+ *
+ * @param patterns
+ * @return the SortingParams Object
+ */
+ public SortingParams get(byte[]... patterns) {
+ for (final byte[] pattern : patterns) {
+ params.add(GET.raw);
+ params.add(pattern);
+ }
+ return this;
+ }
}
\ No newline at end of file
diff --git a/src/test/java/redis/clients/jedis/tests/commands/SortingCommandsTest.java b/src/test/java/redis/clients/jedis/tests/commands/SortingCommandsTest.java
index 6864dae..4032eb3 100644
--- a/src/test/java/redis/clients/jedis/tests/commands/SortingCommandsTest.java
+++ b/src/test/java/redis/clients/jedis/tests/commands/SortingCommandsTest.java
@@ -6,8 +6,29 @@ import java.util.List;
import org.junit.Test;
import redis.clients.jedis.SortingParams;
+import redis.clients.jedis.tests.JedisTest;
public class SortingCommandsTest extends JedisCommandTestBase {
+ final byte[] bfoo = {0x01, 0x02, 0x03, 0x04};
+// final byte[] bfoo = {'b', 'f', 'o', 'o'};
+ final byte[] bbar1 = {0x05, 0x06, 0x07, 0x08, '1'};
+ final byte[] bbar2 = {0x05, 0x06, 0x07, 0x08, '2'};
+ final byte[] bbar3 = {0x05, 0x06, 0x07, 0x08, '3'};
+ final byte[] bbar10 = {0x05, 0x06, 0x07, 0x08, '1', '0'};
+ final byte[] bbarstar = {0x05, 0x06, 0x07, 0x08, '*'};
+// final byte[] bbar1 = {'b', 'b', 'a', 'r', '1'};
+// final byte[] bbar2 = {'b', 'b', 'a', 'r', '2'};
+// final byte[] bbar3 = {'b', 'b', 'a', 'r', '3'};
+// final byte[] bbarstar = {'b', 'b', 'a', 'r', '*'};
+// final byte[] bbarstar = {0x05, 0x06, 0x07, 0x08, '*'};
+ final byte[] bcar1 = {0x0A, 0x0B, 0x0C, 0x0D, '1'};
+ final byte[] bcar2 = {0x0A, 0x0B, 0x0C, 0x0D, '2'};
+ final byte[] bcar10 = {0x0A, 0x0B, 0x0C, 0x0D, '1', '0'};
+ final byte[] bcarstar = {0x0A, 0x0B, 0x0C, 0x0D, '*'};
+ final byte[] b1 = {'1'};
+ final byte[] b2 = {'2'};
+ final byte[] b3 = {'3'};
+ final byte[] b10 = {'1', '0'};
@Test
public void sort() {
jedis.lpush("foo", "3");
@@ -22,6 +43,20 @@ public class SortingCommandsTest extends JedisCommandTestBase {
expected.add("3");
assertEquals(expected, result);
+
+ //Binary
+ jedis.lpush(bfoo, b3);
+ jedis.lpush(bfoo, b2);
+ jedis.lpush(bfoo, b1);
+
+ List