Skip to content

Commit

Permalink
Support Go 1.23 iterators for the ZADD command (#652)
Browse files Browse the repository at this point in the history
* Support Go 1.23 iterators for the ZADD

* refactor: change to [string, float64]
  • Loading branch information
mingdaoy authored Oct 25, 2024
1 parent 1928749 commit 25821d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/cmds/iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

package cmds

import "iter"
import (
"iter"
"strconv"
)

func (c HmsetFieldValue) FieldValueIter(seq iter.Seq2[string, string]) HmsetFieldValue {
for field, value := range seq {
Expand All @@ -24,3 +27,10 @@ func (c XaddFieldValue) FieldValueIter(seq iter.Seq2[string, string]) XaddFieldV
}
return c
}

func (c ZaddScoreMember) ScoreMemberIter(seq iter.Seq2[string, float64]) ZaddScoreMember {
for member, score := range seq {
c.cs.s = append(c.cs.s, strconv.FormatFloat(score, 'f', -1, 64), member)
}
return c
}
1 change: 1 addition & 0 deletions internal/cmds/iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func iter0(s Builder) {
s.Hmset().Key("1").FieldValue().FieldValueIter(maps.All(map[string]string{"1": "1"})).Build()
s.Hset().Key("1").FieldValue().FieldValueIter(maps.All(map[string]string{"1": "1"})).Build()
s.Xadd().Key("1").Id("*").FieldValue().FieldValueIter(maps.All(map[string]string{"1": "1"})).Build()
s.Zadd().Key("1").ScoreMember().ScoreMemberIter(maps.All(map[string]float64{"1": float64(1)})).Build()
}

func TestIter(t *testing.T) {
Expand Down

0 comments on commit 25821d0

Please sign in to comment.