Skip to content

Commit

Permalink
rename to Sorted.Create.Score due to the score interface
Browse files Browse the repository at this point in the history
  • Loading branch information
xh3b4sd committed Sep 27, 2023
1 parent 6c522f7 commit e8053a9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
20 changes: 10 additions & 10 deletions pkg/conformance/client_single_sorted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,30 +157,30 @@ func Test_Client_Single_Sorted_Create_Value(t *testing.T) {
}

{
err := cli.Sorted().Create().Value("ssk", "foo", 0.8)
err := cli.Sorted().Create().Score("ssk", "foo", 0.8)
if err != nil {
t.Fatal(err)
}
}

{
err := cli.Sorted().Create().Value("ssk", "bar", 0.7)
err := cli.Sorted().Create().Score("ssk", "bar", 0.7)
if err != nil {
t.Fatal(err)
}
}

// Verify we can create elements with duplicated scores.
{
err := cli.Sorted().Create().Value("ssk", "zap", 0.8)
err := cli.Sorted().Create().Score("ssk", "zap", 0.8)
if err != nil {
t.Fatal(err)
}
}

// Verify values must be unique after all.
{
err := cli.Sorted().Create().Value("ssk", "foo", 0.8)
err := cli.Sorted().Create().Score("ssk", "foo", 0.8)
if !sorted.IsAlreadyExistsError(err) {
t.Fatal("expected", "alreadyExistsError", "got", err)
}
Expand Down Expand Up @@ -656,19 +656,19 @@ func Test_Client_Single_Sorted_Delete_Value(t *testing.T) {
}

{
err = cli.Sorted().Create().Value("ssk", "foo", 8.0)
err = cli.Sorted().Create().Score("ssk", "foo", 8.0)
if err != nil {
t.Fatal(err)
}
err = cli.Sorted().Create().Value("ssk", "bar", 7.0)
err = cli.Sorted().Create().Score("ssk", "bar", 7.0)
if err != nil {
t.Fatal(err)
}
err = cli.Sorted().Create().Value("ssk", "baz", 6.0)
err = cli.Sorted().Create().Score("ssk", "baz", 6.0)
if err != nil {
t.Fatal(err)
}
err = cli.Sorted().Create().Value("ssk", "zap", 5.0)
err = cli.Sorted().Create().Score("ssk", "zap", 5.0)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1803,7 +1803,7 @@ func Test_Client_Single_Sorted_Update_Score(t *testing.T) {
}

{
err := cli.Sorted().Create().Value("ssk", "foo", 0.8)
err := cli.Sorted().Create().Score("ssk", "foo", 0.8)
if err != nil {
t.Fatal(err)
}
Expand All @@ -1823,7 +1823,7 @@ func Test_Client_Single_Sorted_Update_Score(t *testing.T) {
}

{
err := cli.Sorted().Create().Value("ssk", "foo", 0.7)
err := cli.Sorted().Create().Score("ssk", "foo", 0.7)
if !sorted.IsAlreadyExistsError(err) {
t.Fatal("expected", "alreadyExistsError", "got", err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/fake/sorted_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package fake

type SortedCreate struct {
FakeIndex func() error
FakeValue func() error
FakeScore func() error
}

func (e *SortedCreate) Index(key string, val string, sco float64, ind ...string) error {
Expand All @@ -13,9 +13,9 @@ func (e *SortedCreate) Index(key string, val string, sco float64, ind ...string)
return nil
}

func (e *SortedCreate) Value(key string, val string, sco float64) error {
if e.FakeValue != nil {
return e.FakeValue()
func (e *SortedCreate) Score(key string, val string, sco float64) error {
if e.FakeScore != nil {
return e.FakeScore()
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/sorted/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (c *create) Index(key string, val string, sco float64, ind ...string) error
return tracer.Mask(executionFailedError)
}

func (c *create) Value(key string, val string, sco float64) error {
func (c *create) Score(key string, val string, sco float64) error {
con := c.pool.Get()
defer con.Close()

Expand Down
5 changes: 2 additions & 3 deletions pkg/sorted/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ type Create interface {
// Scores are enforced to be unique.
Index(key string, val string, sco float64, ind ...string) error

// Value creates an element within the sorted set under key transparently
// Score creates an element within the sorted set under key transparently
// using ZADD and the NX option. Scores are not enforced to be unique, values
// are.
//
// https://redis.io/commands/zadd
//
// TODO rename to Score due to its score interface
Value(key string, val string, sco float64) error
Score(key string, val string, sco float64) error
}

type Delete interface {
Expand Down

0 comments on commit e8053a9

Please sign in to comment.