Skip to content

Commands wrapped in a Watch callback are not hooked if client is a cluster #1547

Closed as not planned
@yansal

Description

@yansal

Expected Behavior

Commands wrapped in a Watch callback should enter the client hook.

Current Behavior

Commands wrapped in a Watch callback do enter the client hook if the client has been created with the NewClient function, but not if the client is a cluster created with the NewClusterClient function

Steps to Reproduce

This program works:

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/go-redis/redis/v8"
)

func main() {
	if err := main1(); err != nil {
		log.Fatal(err)
	}
}

func main1() error {
	client := redis.NewClient(&redis.Options{Addr: "localhost:6379"})
	client.AddHook(hook{})
	ctx := context.Background()
	const key = "foo"
	if err := client.Watch(ctx, func(tx *redis.Tx) error {
		return tx.Set(ctx, key, "bar", 0).Err()
	}, key); err != nil {
		return err
	}
	return nil
}

type hook struct{}

func (h hook) BeforeProcess(ctx context.Context, cmder redis.Cmder) (context.Context, error) {
	return ctx, nil
}

func (h hook) AfterProcess(ctx context.Context, cmder redis.Cmder) error {
	fmt.Println(cmder)
	return nil
}

func (h hook) BeforeProcessPipeline(ctx context.Context, cmders []redis.Cmder) (context.Context, error) {
	return ctx, nil
}

func (h hook) AfterProcessPipeline(ctx context.Context, cmders []redis.Cmder) error { return nil }

It prints

watch foo: OK
set foo bar: OK
unwatch: OK

If we replace the client with a cluster client, then the program prints nothing.

This bug is present with the git sha 38caa12.

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