serkant.uluderya | e5afeff | 2021-02-23 18:00:23 +0300 | [diff] [blame] | 1 | package redis |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "sync/atomic" |
| 6 | ) |
| 7 | |
| 8 | func (c *ClusterClient) DBSize(ctx context.Context) *IntCmd { |
| 9 | cmd := NewIntCmd(ctx, "dbsize") |
| 10 | var size int64 |
| 11 | err := c.ForEachMaster(ctx, func(ctx context.Context, master *Client) error { |
| 12 | n, err := master.DBSize(ctx).Result() |
| 13 | if err != nil { |
| 14 | return err |
| 15 | } |
| 16 | atomic.AddInt64(&size, n) |
| 17 | return nil |
| 18 | }) |
| 19 | if err != nil { |
| 20 | cmd.SetErr(err) |
| 21 | return cmd |
| 22 | } |
| 23 | cmd.val = size |
| 24 | return cmd |
| 25 | } |