diff --git a/ledis/t_zset.go b/ledis/t_zset.go index 5d6bfb3..964361e 100644 --- a/ledis/t_zset.go +++ b/ledis/t_zset.go @@ -899,7 +899,7 @@ func (db *DB) ZUnionStore(destKey []byte, srcKeys [][]byte, weights []int64, agg } for _, pair := range scorePairs { if score, ok := destMap[String(pair.Member)]; !ok { - destMap[String(pair.Member)] = pair.Score + destMap[String(pair.Member)] = pair.Score * weights[i] } else { destMap[String(pair.Member)] = aggregateFunc(score, pair.Score*weights[i]) } @@ -966,7 +966,7 @@ func (db *DB) ZInterStore(destKey []byte, srcKeys [][]byte, weights []int64, agg } for _, pair := range scorePairs { if score, ok := destMap[String(pair.Member)]; !ok { - destMap[String(pair.Member)] = pair.Score + destMap[String(pair.Member)] = pair.Score * weights[i] } else { keptMembers = append(keptMembers, pair.Member) destMap[String(pair.Member)] = aggregateFunc(score, pair.Score*weights[i]) diff --git a/ledis/t_zset_test.go b/ledis/t_zset_test.go index a772360..a2232d3 100644 --- a/ledis/t_zset_test.go +++ b/ledis/t_zset_test.go @@ -338,7 +338,7 @@ func TestZInterStore(t *testing.T) { db.ZAdd(key2, ScorePair{2, []byte("three")}) keys := [][]byte{key1, key2} - weights := []int64{1, 2} + weights := []int64{2, 3} out := []byte("out") n, err := db.ZInterStore(out, keys, weights, AggregateSum) @@ -352,7 +352,7 @@ func TestZInterStore(t *testing.T) { if err != nil { t.Fatal(err.Error()) } - if v != 5 { + if v != 8 { t.Fatal("invalid value ", v) } @@ -370,7 +370,7 @@ func TestZInterStore(t *testing.T) { if err != nil { t.Fatal(err.Error()) } - if v != 1 { + if v != 2 { t.Fatal("invalid value ", v) }