这是indexloc提供的服务,不要输入任何密码
Skip to content

ClusterClient won't call hooks during Watch #3599

@markuspeloquin

Description

@markuspeloquin

Calling AddHook() on a ClusterClient will not call hooks when using Watch(), or anything inside the Watch block.

Expected Behavior

I see watch ... unwatch in my logger.

Current Behavior

It prints nothing.

Possible Solution

Not a solution, but a workaround:

client := redis.NewClusterClient(&redis.ClusterOptions{
    NewClient: func(opt *redis.Options) *redis.Client {
        c := redis.NewClient(opt)
        c.AddHook(myHooks{})
        return c
    },
})

Steps to Reproduce

type myHooks struct{}
func (myHooks) DialHook(redis.DialHook) redis.DialHook { return nil }
func (myHooks) ProcessPipelineHook(redis.ProcessPipelineHook) redis.ProcessPipelineHook { return nil }
func (myHooks) ProcessHook(next redis.ProcessHook) redis.ProcessHook {
    return func(ctx context.Context, cmd redis.Cmder) error {
        defer fmt.Printf("%v\n", cmd)
        return next(ctx, cmd)
    }
}

client := redis.NewClusterClient(&redis.ClusterOptions{})
client.AddHook(myHooks{})
client.Watch(ctx, func(*redis.Tx) error { return nil }, "key") // should print 'watch key... unwatch'

Context (Environment)

I'm trying to log my commands and everything inside Watch() is missing.

Detailed Description

Pass hooks to child clients.

Possible Implementation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions