go-agent: github.com/newrelic/go-agent/v3/integrations/nrredis-v7 Index | Examples | Files | Directories

package nrredis

import "github.com/newrelic/go-agent/v3/integrations/nrredis-v7"

Package nrredis instruments github.com/go-redis/redis/v7.

Use this package to instrument your go-redis/redis/v7 calls without having to manually create DatastoreSegments.

Code:

opts := &redis.Options{Addr: "localhost:6379"}
client := redis.NewClient(opts)

//
// Step 1:  Add a nrredis.NewHook() to your redis client.
//
client.AddHook(nrredis.NewHook(opts))

//
// Step 2: Ensure that all client calls contain a context with includes
// the transaction.
//
txn := getTransaction()
ctx := newrelic.NewContext(context.Background(), txn)
pong, err := client.WithContext(ctx).Ping().Result()
fmt.Println(pong, err)

Code:

client := redis.NewClusterClient(&redis.ClusterOptions{
    Addrs: []string{":7000", ":7001", ":7002", ":7003", ":7004", ":7005"},
})

//
// Step 1:  Add a nrredis.NewHook() to your redis cluster client.
//
client.AddHook(nrredis.NewHook(nil))

//
// Step 2: Ensure that all client calls contain a context with includes
// the transaction.
//
txn := getTransaction()
ctx := newrelic.NewContext(context.Background(), txn)
pong, err := client.WithContext(ctx).Ping().Result()
fmt.Println(pong, err)

Index

Examples

Package Files

nrredis.go

func NewHook Uses

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

NewHook creates a redis.Hook to instrument Redis calls. Add it to your client, then ensure that all calls contain a context which includes the transaction. The options are optional. Provide them to get instance metrics broken out by host and port. The hook returned can be used with redis.Client, redis.ClusterClient, and redis.Ring.

Directories

PathSynopsis
example

Package nrredis imports 6 packages (graph) and is imported by 2 packages. Updated 2020-07-02. Refresh now. Tools for package owners.