diff --git a/pkg/conformance/client_single_sorted_test.go b/pkg/conformance/client_single_sorted_test.go index ad79b89..f81f5d7 100644 --- a/pkg/conformance/client_single_sorted_test.go +++ b/pkg/conformance/client_single_sorted_test.go @@ -194,14 +194,14 @@ func Test_Client_Single_Sorted_Create_Value(t *testing.T) { if len(res) != 3 { t.Fatal("expected", 3, "got", len(res)) } - if res[0] != "zap" { - t.Fatal("expected", "zap", "got", res[0]) + if res[0] != "bar" { + t.Fatal("expected", "bar", "got", res[0]) } if res[1] != "foo" { t.Fatal("expected", "foo", "got", res[1]) } - if res[2] != "bar" { - t.Fatal("expected", "bar", "got", res[2]) + if res[2] != "zap" { + t.Fatal("expected", "zap", "got", res[2]) } } @@ -223,11 +223,11 @@ func Test_Client_Single_Sorted_Create_Value(t *testing.T) { if len(res) != 2 { t.Fatal("expected", 2, "got", len(res)) } - if res[0] != "zap" { - t.Fatal("expected", "zap", "got", res[0]) + if res[0] != "bar" { + t.Fatal("expected", "bar", "got", res[0]) } - if res[1] != "bar" { - t.Fatal("expected", "bar", "got", res[1]) + if res[1] != "zap" { + t.Fatal("expected", "zap", "got", res[1]) } } } @@ -656,11 +656,11 @@ func Test_Client_Single_Sorted_Delete_Value(t *testing.T) { } { - err = cli.Sorted().Create().Score("ssk", "foo", 8.0) + err = cli.Sorted().Create().Score("ssk", "zap", 5.0) if err != nil { t.Fatal(err) } - err = cli.Sorted().Create().Score("ssk", "bar", 7.0) + err = cli.Sorted().Create().Score("ssk", "foo", 8.0) if err != nil { t.Fatal(err) } @@ -668,7 +668,7 @@ func Test_Client_Single_Sorted_Delete_Value(t *testing.T) { if err != nil { t.Fatal(err) } - err = cli.Sorted().Create().Score("ssk", "zap", 5.0) + err = cli.Sorted().Create().Score("ssk", "bar", 7.0) if err != nil { t.Fatal(err) } @@ -682,17 +682,17 @@ func Test_Client_Single_Sorted_Delete_Value(t *testing.T) { if len(res) != 4 { t.Fatal("expected", 4, "got", len(res)) } - if res[0] != "foo" { - t.Fatal("expected", "foo", "got", res[0]) + if res[0] != "zap" { + t.Fatal("expected", "zap", "got", res[0]) } - if res[1] != "bar" { - t.Fatal("expected", "bar", "got", res[1]) + if res[1] != "baz" { + t.Fatal("expected", "baz", "got", res[1]) } - if res[2] != "baz" { - t.Fatal("expected", "baz", "got", res[2]) + if res[2] != "bar" { + t.Fatal("expected", "bar", "got", res[2]) } - if res[3] != "zap" { - t.Fatal("expected", "zap", "got", res[3]) + if res[3] != "foo" { + t.Fatal("expected", "foo", "got", res[3]) } } @@ -1307,8 +1307,8 @@ func Test_Client_Single_Sorted_Search_Order(t *testing.T) { } } - // Ensure to get the latest value, that is, the value of the element with - // the highest score. + // Ensure to get the first value, that is, the value of the element with the + // lowest score. { res, err := cli.Sorted().Search().Order("ssk", 0, 0) if err != nil { @@ -1317,13 +1317,13 @@ func Test_Client_Single_Sorted_Search_Order(t *testing.T) { if len(res) != 1 { t.Fatal("expected", 1, "got", len(res)) } - if res[0] != "bar" { - t.Fatal("expected", "bar", "got", res[0]) + if res[0] != "foo" { + t.Fatal("expected", "foo", "got", res[0]) } } - // Ensure to get the penultimate value, that is, the value of the element - // with the second highest score. + // Ensure to get the second value, that is, the value of the element with the + // second highest score. { res, err := cli.Sorted().Search().Order("ssk", 1, 1) if err != nil { @@ -1332,8 +1332,8 @@ func Test_Client_Single_Sorted_Search_Order(t *testing.T) { if len(res) != 1 { t.Fatal("expected", 1, "got", len(res)) } - if res[0] != "foo" { - t.Fatal("expected", "foo", "got", res[0]) + if res[0] != "bar" { + t.Fatal("expected", "bar", "got", res[0]) } } @@ -1345,11 +1345,11 @@ func Test_Client_Single_Sorted_Search_Order(t *testing.T) { if len(res) != 2 { t.Fatal("expected", 2, "got", len(res)) } - if res[0] != "bar" { - t.Fatal("expected", "bar", "got", res[0]) + if res[0] != "foo" { + t.Fatal("expected", "foo", "got", res[0]) } - if res[1] != "foo" { - t.Fatal("expected", "foo", "got", res[1]) + if res[1] != "bar" { + t.Fatal("expected", "bar", "got", res[1]) } } @@ -1361,11 +1361,11 @@ func Test_Client_Single_Sorted_Search_Order(t *testing.T) { if len(res) != 2 { t.Fatal("expected", 2, "got", len(res)) } - if res[0] != "7" { - t.Fatal("expected", "7", "got", res[0]) + if res[0] != "6" { + t.Fatal("expected", "6", "got", res[0]) } - if res[1] != "6" { - t.Fatal("expected", "6", "got", res[1]) + if res[1] != "7" { + t.Fatal("expected", "7", "got", res[1]) } } @@ -1384,8 +1384,8 @@ func Test_Client_Single_Sorted_Search_Order(t *testing.T) { if len(res) != 1 { t.Fatal("expected", 1, "got", len(res)) } - if res[0] != "baz" { - t.Fatal("expected", "baz", "got", res[0]) + if res[0] != "foo" { + t.Fatal("expected", "foo", "got", res[0]) } } @@ -1397,8 +1397,8 @@ func Test_Client_Single_Sorted_Search_Order(t *testing.T) { if len(res) != 1 { t.Fatal("expected", 1, "got", len(res)) } - if res[0] != "8" { - t.Fatal("expected", "8", "got", res[0]) + if res[0] != "6" { + t.Fatal("expected", "6", "got", res[0]) } } @@ -1410,8 +1410,8 @@ func Test_Client_Single_Sorted_Search_Order(t *testing.T) { if len(res) != 1 { t.Fatal("expected", 1, "got", len(res)) } - if res[0] != "foo" { - t.Fatal("expected", "foo", "got", res[0]) + if res[0] != "baz" { + t.Fatal("expected", "baz", "got", res[0]) } } } @@ -1678,18 +1678,18 @@ func Test_Client_Single_Sorted_Search_Value(t *testing.T) { } { - res, err := cli.Sorted().Search().Score("ssk", 0.8, 0.7) + res, err := cli.Sorted().Search().Score("ssk", 0.7, 0.8) if err != nil { t.Fatal(err) } if len(res) != 2 { t.Fatal("expected", 2, "got", len(res)) } - if res[0] != "foo" { - t.Fatal("expected", "foo", "got", res[0]) + if res[0] != "bar" { + t.Fatal("expected", "bar", "got", res[0]) } - if res[1] != "bar" { - t.Fatal("expected", "bar", "got", res[1]) + if res[1] != "foo" { + t.Fatal("expected", "foo", "got", res[1]) } } } diff --git a/pkg/sorted/search.go b/pkg/sorted/search.go index ad859ce..57a1232 100644 --- a/pkg/sorted/search.go +++ b/pkg/sorted/search.go @@ -94,7 +94,6 @@ func (s *search) Order(key string, lef int, rig int, sco ...bool) ([]string, err arg = append(arg, prefix.WithKeys(s.prefix, key)) arg = append(arg, lef) arg = append(arg, rig) - arg = append(arg, "REV") if len(sco) == 1 { arg = append(arg, "WITHSCORES") } @@ -142,7 +141,7 @@ func (s *search) Score(key string, lef float64, rig float64) ([]string, error) { con := s.pool.Get() defer con.Close() - res, err := redis.Strings(con.Do("ZRANGE", prefix.WithKeys(s.prefix, key), lef, rig, "REV", "BYSCORE")) + res, err := redis.Strings(con.Do("ZRANGE", prefix.WithKeys(s.prefix, key), lef, rig, "BYSCORE")) if err != nil { return nil, tracer.Mask(err) } diff --git a/pkg/sorted/update.go b/pkg/sorted/update.go index 345ee09..51cb37a 100644 --- a/pkg/sorted/update.go +++ b/pkg/sorted/update.go @@ -135,7 +135,7 @@ type update struct { // the old element marks the end of the executed transaction, leaving a clean // state of an updated element behind. // -// redis> ZREVRANGE k:foo 25 25 +// redis> ZRANGE k:foo 25 25 BYSCORE // 1) "old" // // redis> ZADD k:foo 25 "new"