forked from mirror/redis
DBSize,ScriptLoad,ScriptFlush and ScriptExists should use hook (#1811)
Signed-off-by: monkey <golang@88.com>
This commit is contained in:
parent
dd4b7eb3b4
commit
c1b63a6703
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
func (c *ClusterClient) DBSize(ctx context.Context) *IntCmd {
|
func (c *ClusterClient) DBSize(ctx context.Context) *IntCmd {
|
||||||
cmd := NewIntCmd(ctx, "dbsize")
|
cmd := NewIntCmd(ctx, "dbsize")
|
||||||
|
_ = c.hooks.process(ctx, cmd, func(ctx context.Context, _ Cmder) error {
|
||||||
var size int64
|
var size int64
|
||||||
err := c.ForEachMaster(ctx, func(ctx context.Context, master *Client) error {
|
err := c.ForEachMaster(ctx, func(ctx context.Context, master *Client) error {
|
||||||
n, err := master.DBSize(ctx).Result()
|
n, err := master.DBSize(ctx).Result()
|
||||||
|
@ -19,14 +20,17 @@ func (c *ClusterClient) DBSize(ctx context.Context) *IntCmd {
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.SetErr(err)
|
cmd.SetErr(err)
|
||||||
return cmd
|
} else {
|
||||||
}
|
|
||||||
cmd.val = size
|
cmd.val = size
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClusterClient) ScriptLoad(ctx context.Context, script string) *StringCmd {
|
func (c *ClusterClient) ScriptLoad(ctx context.Context, script string) *StringCmd {
|
||||||
cmd := NewStringCmd(ctx, "script", "load", script)
|
cmd := NewStringCmd(ctx, "script", "load", script)
|
||||||
|
_ = c.hooks.process(ctx, cmd, func(ctx context.Context, _ Cmder) error {
|
||||||
mu := &sync.Mutex{}
|
mu := &sync.Mutex{}
|
||||||
err := c.ForEachShard(ctx, func(ctx context.Context, shard *Client) error {
|
err := c.ForEachShard(ctx, func(ctx context.Context, shard *Client) error {
|
||||||
val, err := shard.ScriptLoad(ctx, script).Result()
|
val, err := shard.ScriptLoad(ctx, script).Result()
|
||||||
|
@ -45,18 +49,22 @@ func (c *ClusterClient) ScriptLoad(ctx context.Context, script string) *StringCm
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.SetErr(err)
|
cmd.SetErr(err)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClusterClient) ScriptFlush(ctx context.Context) *StatusCmd {
|
func (c *ClusterClient) ScriptFlush(ctx context.Context) *StatusCmd {
|
||||||
cmd := NewStatusCmd(ctx, "script", "flush")
|
cmd := NewStatusCmd(ctx, "script", "flush")
|
||||||
_ = c.ForEachShard(ctx, func(ctx context.Context, shard *Client) error {
|
_ = c.hooks.process(ctx, cmd, func(ctx context.Context, _ Cmder) error {
|
||||||
shard.ScriptFlush(ctx)
|
err := c.ForEachShard(ctx, func(ctx context.Context, shard *Client) error {
|
||||||
|
return shard.ScriptFlush(ctx).Err()
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
cmd.SetErr(err)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +82,7 @@ func (c *ClusterClient) ScriptExists(ctx context.Context, hashes ...string) *Boo
|
||||||
result[i] = true
|
result[i] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ = c.hooks.process(ctx, cmd, func(ctx context.Context, _ Cmder) error {
|
||||||
mu := &sync.Mutex{}
|
mu := &sync.Mutex{}
|
||||||
err := c.ForEachShard(ctx, func(ctx context.Context, shard *Client) error {
|
err := c.ForEachShard(ctx, func(ctx context.Context, shard *Client) error {
|
||||||
val, err := shard.ScriptExists(ctx, hashes...).Result()
|
val, err := shard.ScriptExists(ctx, hashes...).Result()
|
||||||
|
@ -91,9 +100,10 @@ func (c *ClusterClient) ScriptExists(ctx context.Context, hashes ...string) *Boo
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.SetErr(err)
|
cmd.SetErr(err)
|
||||||
}
|
} else {
|
||||||
|
|
||||||
cmd.val = result
|
cmd.val = result
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue