nrredis

package module
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: Apache-2.0 Imports: 6 Imported by: 1

README

v3/integrations/nrredis-v8 GoDoc

Package nrredis instruments "github.com/go-redis/redis/v8".

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

For more information, see godocs.

Documentation

Overview

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

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

Example (Client)
package main

import (
	"context"
	"fmt"

	redis "github.com/go-redis/redis/v8"
	nrredis "github.com/newrelic/go-agent/v3/integrations/nrredis-v8"
	"github.com/newrelic/go-agent/v3/newrelic"
)

func getTransaction() *newrelic.Transaction { return nil }

func main() {
	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(ctx).Result()
	fmt.Println(pong, err)
}
Output:

Example (ClusterClient)
package main

import (
	"context"
	"fmt"

	redis "github.com/go-redis/redis/v8"
	nrredis "github.com/newrelic/go-agent/v3/integrations/nrredis-v8"
	"github.com/newrelic/go-agent/v3/newrelic"
)

func getTransaction() *newrelic.Transaction { return nil }

func main() {
	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(ctx).Result()
	fmt.Println(pong, err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHook

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.

Types

This section is empty.

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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