Skip to content

Commit

Permalink
rename to Sorted.Search.Score due to score interface
Browse files Browse the repository at this point in the history
  • Loading branch information
xh3b4sd committed Sep 27, 2023
1 parent 8903da4 commit d6f07b6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
12 changes: 6 additions & 6 deletions pkg/conformance/client_single_sorted_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,7 @@ func Test_Client_Single_Sorted_Search_Value(t *testing.T) {
}

{
res, err := cli.Sorted().Search().Value("ssk", 0.8, 0.8)
res, err := cli.Sorted().Search().Score("ssk", 0.8, 0.8)
if err != nil {
t.Fatal(err)
}
Expand All @@ -1600,7 +1600,7 @@ func Test_Client_Single_Sorted_Search_Value(t *testing.T) {
}

{
res, err := cli.Sorted().Search().Value("ssk", 0.8, 0.8)
res, err := cli.Sorted().Search().Score("ssk", 0.8, 0.8)
if err != nil {
t.Fatal(err)
}
Expand All @@ -1620,7 +1620,7 @@ func Test_Client_Single_Sorted_Search_Value(t *testing.T) {
}

{
res, err := cli.Sorted().Search().Value("ssk", 0.7, 0.7)
res, err := cli.Sorted().Search().Score("ssk", 0.7, 0.7)
if err != nil {
t.Fatal(err)
}
Expand All @@ -1633,7 +1633,7 @@ func Test_Client_Single_Sorted_Search_Value(t *testing.T) {
}

{
res, err := cli.Sorted().Search().Value("ssk", 0.8, 0.7)
res, err := cli.Sorted().Search().Score("ssk", 0.8, 0.7)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1677,7 +1677,7 @@ func Test_Client_Single_Sorted_Update(t *testing.T) {
}

{
res, err := cli.Sorted().Search().Value("ssk", 0.8, 0.8)
res, err := cli.Sorted().Search().Score("ssk", 0.8, 0.8)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1717,7 +1717,7 @@ func Test_Client_Single_Sorted_Update(t *testing.T) {
}

{
res, err := cli.Sorted().Search().Value("ssk", 0.8, 0.8)
res, err := cli.Sorted().Search().Score("ssk", 0.8, 0.8)
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/fake/sorted_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type SortedSearch struct {
FakeInter func() ([]string, error)
FakeOrder func() ([]string, error)
FakeRando func() ([]string, error)
FakeValue func() ([]string, error)
FakeScore func() ([]string, error)
}

func (s *SortedSearch) Index(key string, ind string) (string, error) {
Expand Down Expand Up @@ -40,9 +40,9 @@ func (s *SortedSearch) Rando(key string, cou ...uint) ([]string, error) {
return nil, nil
}

func (s *SortedSearch) Value(key string, lef float64, rig float64) ([]string, error) {
if s.FakeValue != nil {
return s.FakeValue()
func (s *SortedSearch) Score(key string, lef float64, rig float64) ([]string, error) {
if s.FakeScore != nil {
return s.FakeScore()
}

return nil, nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/locker/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package locker
type Interface interface {
// Acquire creates a distributed lock.
Acquire() error

// Refresh prevents a distributed lock from expiring.
Refresh() error

// Release deletes a distributed lock so that it can be acquired by another
// process.
Release() error
Expand Down
27 changes: 17 additions & 10 deletions pkg/sorted/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Create interface {
//
// TODO should be renamed to Index because of the index feature.
Score(key string, val string, sco float64, ind ...string) error

// Value creates an element within the sorted set under key transparently
// using ZADD. Scores are not enforced to be unique.
//
Expand All @@ -29,10 +30,12 @@ type Create interface {
type Delete interface {
// Clean removes the sorted set under key including the derived indeizes.
Clean(key string) error

// Index deletes the element identified by value within the specified sorted
// set. Note that indices associated with the underlying element are purged
// automatically as well.
Index(key string, val string) error

// Limit cuts off all older elements from the sorted set under key resulting
// in a sorted set that contains the latest lim amount of elements. Consider
// the following elements.
Expand All @@ -44,10 +47,12 @@ type Delete interface {
// e f g
//
Limit(key string, lim int) error

// Score deletes the element identified by score within the specified sorted
// set. Note that indices associated with the underlying element are purged
// automatically as well.
Score(key string, sco float64) error

// Value deletes the elements identified by the given values within the
// specified sorted set. Non-existing elements are ignored.
//
Expand All @@ -60,9 +65,11 @@ type Exists interface {
// Index verifies if an element with the given index exists within the
// sorted set identified by key.
Index(key string, ind string) (bool, error)

// Score verifies if an element with the given score exists within the
// sorted set identified by key.
Score(key string, sco float64) (bool, error)

// Value verifies if an element with the given value exists within the
// sorted set identified by key.
Value(key string, val string) (bool, error)
Expand Down Expand Up @@ -95,6 +102,7 @@ type Search interface {
// during element creation. This enables multi key elements. Values can be
// retreived using different keys referencing the requested element's value.
Index(key string, ind string) (string, error)

// Inter returns the values that exist in all the given keys. Therefore the
// returned values represent the intersection of the given keys. Given k1 and
// k2 hold the following values, Inter(k1, k2) were to return v4 and v5.
Expand All @@ -103,29 +111,28 @@ type Search interface {
// k2 v2 v4 v5 v7
//
Inter(key ...string) ([]string, error)

// 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.
// Optionally a single bool is allowed to be passed for returning the element
// scores instead of their values as described by WITHSCORES.
//
// lef=-1 rig=-1 -> rightmost/first element
// lef=0 rig=0 -> leftmost/latest element
// 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.
//
// lef=0 rig=-1 -> all elements
// https://redis.io/commands/zrange
//
Order(key string, lef int, rig int, sco ...bool) ([]string, error)

// Rando returns a random value within the underlying sorted set. Optionally
// a single uint is allowed to be passed for requesting cou random values as
// described by ZRANDMEMBER.
//
// https://redis.io/commands/zrandmember
//
Rando(key string, cou ...uint) ([]string, error)
// Value returns the values associated to the range of scores defined by lef

// Score returns the values associated to the range of scores defined by lef
// and rig. Can be used to find a particular value if lef and rig are equal.
//
// TODO should be renamed to Score because of the score parameters.
Value(key string, lef float64, rig float64) ([]string, error)
Score(key string, lef float64, rig float64) ([]string, error)
}

type Update interface {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sorted/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (s *search) Rando(key string, cou ...uint) ([]string, error) {
return res, nil
}

func (s *search) Value(key string, lef float64, rig float64) ([]string, error) {
func (s *search) Score(key string, lef float64, rig float64) ([]string, error) {
con := s.pool.Get()
defer con.Close()

Expand Down

0 comments on commit d6f07b6

Please sign in to comment.