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 ¶
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.
Click to show internal directories.
Click to hide internal directories.