From c9c1f18a58f75c7c39fe850536e198771cc99e7a Mon Sep 17 00:00:00 2001 From: Geoff Garside Date: Tue, 9 Dec 2014 10:40:32 +0000 Subject: [PATCH 1/2] Add failing test case for SORT .. BY pattern. --- redis_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/redis_test.go b/redis_test.go index 5547981..8a61816 100644 --- a/redis_test.go +++ b/redis_test.go @@ -782,6 +782,29 @@ func (t *RedisTest) TestCmdKeysSort(c *C) { c.Assert(sort.Val(), DeepEquals, []string{"1", "2"}) } +func (t *RedisTest) TestCmdKeysSortBy(c *C) { + lPush := t.client.LPush("list", "1") + c.Assert(lPush.Err(), IsNil) + c.Assert(lPush.Val(), Equals, int64(1)) + lPush = t.client.LPush("list", "3") + c.Assert(lPush.Err(), IsNil) + c.Assert(lPush.Val(), Equals, int64(2)) + lPush = t.client.LPush("list", "2") + c.Assert(lPush.Err(), IsNil) + c.Assert(lPush.Val(), Equals, int64(3)) + + set := t.client.Set("weight_1", "5") + c.Assert(set.Err(), IsNil) + set = t.client.Set("weight_2", "2") + c.Assert(set.Err(), IsNil) + set = t.client.Set("weight_3", "8") + c.Assert(set.Err(), IsNil) + + sort := t.client.Sort("list", redis.Sort{Offset: 0, Count: 2, Order: "ASC", By: "weight_*"}) + c.Assert(sort.Err(), IsNil) + c.Assert(sort.Val(), DeepEquals, []string{"2", "1"}) +} + func (t *RedisTest) TestCmdKeysTTL(c *C) { ttl := t.client.TTL("key") c.Assert(ttl.Err(), IsNil) From daade895aa47f71bd05859fc609e4e633660ed0f Mon Sep 17 00:00:00 2001 From: Geoff Garside Date: Tue, 9 Dec 2014 10:41:03 +0000 Subject: [PATCH 2/2] Add missing "BY" argument to Sort args list. Fixes "ERR syntax error" issue with Sort{By: "pattern"}. --- commands.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands.go b/commands.go index 1fc22aa..6068bab 100644 --- a/commands.go +++ b/commands.go @@ -196,7 +196,7 @@ type Sort struct { func (c *Client) Sort(key string, sort Sort) *StringSliceCmd { args := []string{"SORT", key} if sort.By != "" { - args = append(args, sort.By) + args = append(args, "BY", sort.By) } if sort.Offset != 0 || sort.Count != 0 { args = append(args, "LIMIT", formatFloat(sort.Offset), formatFloat(sort.Count))