redis/cluster_commands.go

26 lines
445 B
Go
Raw Normal View History

2017-09-11 09:19:30 +03:00
package redis
2020-03-11 17:26:42 +03:00
import (
"context"
"sync/atomic"
)
2017-09-11 09:19:30 +03:00
2020-03-11 17:26:42 +03:00
func (c *ClusterClient) DBSize(ctx context.Context) *IntCmd {
cmd := NewIntCmd(ctx, "dbsize")
2017-09-11 09:19:30 +03:00
var size int64
2020-03-11 17:26:42 +03:00
err := c.ForEachMaster(ctx, func(ctx context.Context, master *Client) error {
n, err := master.DBSize(ctx).Result()
2017-09-11 09:19:30 +03:00
if err != nil {
return err
}
atomic.AddInt64(&size, n)
return nil
})
if err != nil {
2020-02-03 12:53:47 +03:00
cmd.SetErr(err)
2017-09-11 09:19:30 +03:00
return cmd
}
cmd.val = size
return cmd
}