Skip to content

Commit

Permalink
let Sorted.Search.Order return values and scores together (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
xh3b4sd authored Oct 10, 2023
1 parent 2f90402 commit 340d865
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
29 changes: 19 additions & 10 deletions pkg/conformance/client_single_sorted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1358,14 +1358,20 @@ func Test_Client_Single_Sorted_Search_Order(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if len(res) != 2 {
t.Fatal("expected", 2, "got", len(res))
if len(res) != 4 {
t.Fatal("expected", 4, "got", len(res))
}
if res[0] != "6" {
t.Fatal("expected", "6", "got", res[0])
if res[0] != "foo" {
t.Fatal("expected", "foo", "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])
if res[2] != "bar" {
t.Fatal("expected", "bar", "got", res[2])
}
if res[3] != "7" {
t.Fatal("expected", "7", "got", res[3])
}
}

Expand Down Expand Up @@ -1394,11 +1400,14 @@ func Test_Client_Single_Sorted_Search_Order(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if len(res) != 1 {
t.Fatal("expected", 1, "got", len(res))
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] != "6" {
t.Fatal("expected", "6", "got", res[0])
if res[1] != "6" {
t.Fatal("expected", "6", "got", res[1])
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/sorted/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ type Search interface {
// Order returns the values of the sorted set elements stored under key. The
// provided pointers are ranks of the elements' scores within the sorted set.
// All values udner key can be returned using lef=0 and rig=-1. Optionally a
// single bool is allowed to be passed for returning the element scores
// instead of their values as described by WITHSCORES.
// single bool is allowed to be passed for additionally returning the element
// scores together with their values as described by WITHSCORES.
//
// https://redis.io/commands/zrange
//
Expand Down
11 changes: 1 addition & 10 deletions pkg/sorted/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,7 @@ func (s *search) Order(key string, lef int, rig int, sco ...bool) ([]string, err
return nil, tracer.Mask(err)
}

if len(sco) == 0 {
return res, nil
}

var lis []string
for i := 1; i < len(res); i += 2 {
lis = append(lis, res[i])
}

return lis, nil
return res, nil
}

func (s *search) Rando(key string, cou ...uint) ([]string, error) {
Expand Down

0 comments on commit 340d865

Please sign in to comment.