diff --git a/tair/main_test.go b/tair/main_test.go index a18a0b0..fe67a0f 100644 --- a/tair/main_test.go +++ b/tair/main_test.go @@ -61,7 +61,6 @@ func redisOptions() *redis.Options { DialTimeout: 10 * time.Second, ReadTimeout: 30 * time.Second, WriteTimeout: 30 * time.Second, - Password: "xxx", MaxRetries: -1, PoolSize: 10, diff --git a/tair/tairzset.go b/tair/tairzset.go index d5dc1dd..9bebff0 100644 --- a/tair/tairzset.go +++ b/tair/tairzset.go @@ -3,7 +3,6 @@ package tair import ( "context" "github.com/go-redis/redis/v8" - "strconv" "strings" ) @@ -62,12 +61,14 @@ type ExZAddMember struct { Member string } -func joinScoresToString(scores ...float64) string { +func joinScoresToString(scores ...string) string { var builder strings.Builder for _, score := range scores { - builder.WriteString(strconv.FormatFloat(score, 'E', -1, 64)) + builder.WriteString(score) + builder.WriteString("#") } - return builder.String() + strs := builder.String() + return strs[:len(strs)-1] } type ExZRangeArgs struct { @@ -120,12 +121,12 @@ func (tc tairCmdable) exZAdd(ctx context.Context, key string, p *ExZAddArgs, mem return cmd } -func (tc tairCmdable) ExZAddManyScore(ctx context.Context, key string, member string, scores ...float64) *redis.IntCmd { +func (tc tairCmdable) ExZAddManyScore(ctx context.Context, key string, member string, scores ...string) *redis.IntCmd { args := make([]interface{}, 4) args[0] = "exzadd" args[1] = key - args[2] = member - args[3] = joinScoresToString(scores...) + args[2] = joinScoresToString(scores...) + args[3] = member cmd := redis.NewIntCmd(ctx, args...) _ = tc(ctx, cmd) return cmd @@ -162,7 +163,7 @@ func (tc tairCmdable) ExZIncrBy(ctx context.Context, key string, score string, m return cmd } -func (tc tairCmdable) ExZIncrByManyScore(ctx context.Context, key string, member string, score ...float64) *redis.StringSliceCmd { +func (tc tairCmdable) ExZIncrByManyScore(ctx context.Context, key string, member string, score ...string) *redis.StringSliceCmd { a := make([]interface{}, 4) a[0] = "exzincryby" a[1] = key diff --git a/tair/tairzset_test.go b/tair/tairzset_test.go index 8c369ef..6e9d42c 100644 --- a/tair/tairzset_test.go +++ b/tair/tairzset_test.go @@ -43,6 +43,24 @@ func (suite *TairZsetTestSuite) TestExZAdd() { assert.Equal(suite.T(), res, int64(0)) } +func (suite *TairZsetTestSuite) TestExZAddManyScore() { + res, err := suite.tairClient.ExZAddManyScore(ctx, "k1", "a", "32", "21", "16").Result() + assert.NoError(suite.T(), err) + assert.Equal(suite.T(), res, int64(1)) + + res, err = suite.tairClient.ExZAddManyScore(ctx, "k1", "d", "14", "4", "16").Result() + assert.NoError(suite.T(), err) + assert.Equal(suite.T(), res, int64(1)) + + res, err = suite.tairClient.ExZAddManyScore(ctx, "k1", "c", "20", "7", "12").Result() + assert.NoError(suite.T(), err) + assert.Equal(suite.T(), res, int64(1)) + + res2, err := suite.tairClient.ExZRange(ctx, "k1", 0, -1).Result() + assert.NoError(suite.T(), err) + assert.Equal(suite.T(), res2, []string{"d", "c", "a"}) +} + func (suite *TairZsetTestSuite) TestExZAddParams() { res, err := suite.tairClient.ExZAddArgs(ctx, "foo", "1", "a", tair.ExZAddArgs{}.New().Xx()).Result() assert.NoError(suite.T(), err)