diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:36:04 +0000 |
commit | b09c6d56832eb1718c07d74abf3bc6ae3fe4e030 (patch) | |
tree | d2caec2610d4ea887803ec9e9c3cd77136c448ba /dependencies/pkg/mod/github.com/go-redis/redis/v8@v8.11.5/example_instrumentation_test.go | |
parent | Initial commit. (diff) | |
download | icingadb-b09c6d56832eb1718c07d74abf3bc6ae3fe4e030.tar.xz icingadb-b09c6d56832eb1718c07d74abf3bc6ae3fe4e030.zip |
Adding upstream version 1.1.0.upstream/1.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | dependencies/pkg/mod/github.com/go-redis/redis/v8@v8.11.5/example_instrumentation_test.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/dependencies/pkg/mod/github.com/go-redis/redis/v8@v8.11.5/example_instrumentation_test.go b/dependencies/pkg/mod/github.com/go-redis/redis/v8@v8.11.5/example_instrumentation_test.go new file mode 100644 index 0000000..d66edce --- /dev/null +++ b/dependencies/pkg/mod/github.com/go-redis/redis/v8@v8.11.5/example_instrumentation_test.go @@ -0,0 +1,80 @@ +package redis_test + +import ( + "context" + "fmt" + + "github.com/go-redis/redis/v8" +) + +type redisHook struct{} + +var _ redis.Hook = redisHook{} + +func (redisHook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error) { + fmt.Printf("starting processing: <%s>\n", cmd) + return ctx, nil +} + +func (redisHook) AfterProcess(ctx context.Context, cmd redis.Cmder) error { + fmt.Printf("finished processing: <%s>\n", cmd) + return nil +} + +func (redisHook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error) { + fmt.Printf("pipeline starting processing: %v\n", cmds) + return ctx, nil +} + +func (redisHook) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) error { + fmt.Printf("pipeline finished processing: %v\n", cmds) + return nil +} + +func Example_instrumentation() { + rdb := redis.NewClient(&redis.Options{ + Addr: ":6379", + }) + rdb.AddHook(redisHook{}) + + rdb.Ping(ctx) + // Output: starting processing: <ping: > + // finished processing: <ping: PONG> +} + +func ExamplePipeline_instrumentation() { + rdb := redis.NewClient(&redis.Options{ + Addr: ":6379", + }) + rdb.AddHook(redisHook{}) + + rdb.Pipelined(ctx, func(pipe redis.Pipeliner) error { + pipe.Ping(ctx) + pipe.Ping(ctx) + return nil + }) + // Output: pipeline starting processing: [ping: ping: ] + // pipeline finished processing: [ping: PONG ping: PONG] +} + +func ExampleClient_Watch_instrumentation() { + rdb := redis.NewClient(&redis.Options{ + Addr: ":6379", + }) + rdb.AddHook(redisHook{}) + + rdb.Watch(ctx, func(tx *redis.Tx) error { + tx.Ping(ctx) + tx.Ping(ctx) + return nil + }, "foo") + // Output: + // starting processing: <watch foo: > + // finished processing: <watch foo: OK> + // starting processing: <ping: > + // finished processing: <ping: PONG> + // starting processing: <ping: > + // finished processing: <ping: PONG> + // starting processing: <unwatch: > + // finished processing: <unwatch: OK> +} |