mirror of https://github.com/go-redis/redis.git
Merge pull request #108 from go-redis/fix/reduce-zadd-mem-alloc
commands: reduce memory allocations in ZAdd.
This commit is contained in:
commit
44a58ef067
|
@ -858,9 +858,12 @@ type ZStore struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *commandable) ZAdd(key string, members ...Z) *IntCmd {
|
func (c *commandable) ZAdd(key string, members ...Z) *IntCmd {
|
||||||
args := []string{"ZADD", key}
|
args := make([]string, 2+2*len(members))
|
||||||
for _, m := range members {
|
args[0] = "ZADD"
|
||||||
args = append(args, formatFloat(m.Score), m.Member)
|
args[1] = key
|
||||||
|
for i, m := range members {
|
||||||
|
args[2+2*i] = formatFloat(m.Score)
|
||||||
|
args[2+2*i+1] = m.Member
|
||||||
}
|
}
|
||||||
cmd := NewIntCmd(args...)
|
cmd := NewIntCmd(args...)
|
||||||
c.Process(cmd)
|
c.Process(cmd)
|
||||||
|
|
|
@ -267,3 +267,20 @@ func BenchmarkPipeline(b *testing.B) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkZAdd(b *testing.B) {
|
||||||
|
client := redis.NewClient(&redis.Options{
|
||||||
|
Addr: redisAddr,
|
||||||
|
})
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
|
||||||
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
|
for pb.Next() {
|
||||||
|
if err := client.ZAdd("key", redis.Z{float64(1), "hello"}).Err(); err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue