cluster_commands.go 376 字节
Newer Older
Y
Your Name 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
package redis

import "sync/atomic"

func (c *ClusterClient) DBSize() *IntCmd {
	cmd := NewIntCmd("dbsize")
	var size int64
	err := c.ForEachMaster(func(master *Client) error {
		n, err := master.DBSize().Result()
		if err != nil {
			return err
		}
		atomic.AddInt64(&size, n)
		return nil
	})
	if err != nil {
		cmd.setErr(err)
		return cmd
	}
	cmd.val = size
	return cmd
}