nrredis

package module
v1.0.1-0...-0a94385 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

README

v3/integrations/nrredis-v8 GoDoc

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

import nrredis "github.com/oldfritter/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/oldfritter/go-agent/v3/integrations/nrredis-v8"

	oldfritter "github.com/oldfritter/go-agent/v3/oldfritter"
)

func getTransaction() *oldfritter.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 := oldfritter.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/oldfritter/go-agent/v3/integrations/nrredis-v8"

	oldfritter "github.com/oldfritter/go-agent/v3/oldfritter"
)

func getTransaction() *oldfritter.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 := oldfritter.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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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