Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure default search order of first in first out #11

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 46 additions & 46 deletions pkg/conformance/client_single_sorted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}

Expand All @@ -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])
}
}
}
Expand Down Expand Up @@ -656,19 +656,19 @@ 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)
}
err = cli.Sorted().Create().Score("ssk", "baz", 6.0)
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)
}
Expand All @@ -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])
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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])
}
}

Expand All @@ -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])
}
}

Expand All @@ -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])
}
}

Expand All @@ -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])
}
}

Expand All @@ -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])
}
}

Expand All @@ -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])
}
}
}
Expand Down Expand Up @@ -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])
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/sorted/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sorted/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down