ppgoredisv9

package module
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

README

ppgoredisv9

This package instruments the go-redis/redis/v9 package.

Installation

$ go get github.com/pinpoint-apm/pinpoint-go-agent/plugin/goredisv9
import "github.com/pinpoint-apm/pinpoint-go-agent/plugin/goredisv9"

Usage

PkgGoDev

This package instruments the go-redis/v9 calls. Use the NewHook or NewClusterHook as the redis.Hook. Only available in versions of go-redis with an AddHook() function.

rc = redis.NewClient(redisOpts)
client.AddHook(ppgoredisv9.NewHook(opts))

It is necessary to pass the context containing the pinpoint.Tracer to redis.Client.

rc = rc.WithContext(pinpoint.NewContext(context.Background(), tracer))
rc.Pipeline()
package main

import (
    "github.com/go-redis/redis/v9"
    "github.com/pinpoint-apm/pinpoint-go-agent"
    "github.com/pinpoint-apm/pinpoint-go-agent/plugin/goredisv9"
)

var redisClient *redis.Client

func redisv9(w http.ResponseWriter, r *http.Request) {
    ctx := r.Context()
    client := redisClient

    err := client.Set(ctx, "key", "value", 0).Err()
    val, err := client.Get(ctx, "key").Result()
    fmt.Println("key", val)
}

func main() {
    ... //setup agent

    addrs := []string{"localhost:6379", "localhost:6380"}

    redisOpts := &redis.Options{
        Addr: addrs[0],
    }
    redisClient = redis.NewClient(redisOpts)
    redisClient.AddHook(ppgoredisv9.NewHook(redisOpts))

    http.HandleFunc("/redis", pphttp.WrapHandlerFunc(redisv9))

    ...
}

Full Example Source

Documentation

Overview

Package ppgoredisv9 instruments the redis/go-redis/v9 package (https://github.com/redis/go-redis).

This package instruments the go-redis/v9 calls. Use the NewHook as the redis.Hook.

rc = redis.NewClient(redisOpts)
rc.AddHook(ppgoredisv9.NewHook(redisOpts))

It is necessary to pass the context containing the pinpoint.Tracer to redis.Client.

rc = rc.WithContext(pinpoint.NewContext(context.Background(), tracer))
rc.Pipeline()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClusterHook

func NewClusterHook(opts *redis.ClusterOptions) redis.Hook

NewClusterHook creates a redis.Hook to instrument redis cluster calls.

func NewHook

func NewHook(opts *redis.Options) redis.Hook

NewHook creates a redis.Hook to instrument redis calls.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL