instaredis

package module
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 6 Imported by: 0

README

Instana instrumentation for go-redis

This module contains instrumentation code for Redis clients written with go-redis.

GoDoc

Installation

To add the module to your go.mod file run the following command in your project directory:

$ go get github.com/instana/go-sensor/instrumentation/instaredis

Usage

instaredis offers function wrappers for redis.NewClient(), redis.NewFailoverClient(), redis.NewClusterClient() and redis.NewFailoverClusterClient() that instrument an instance of redis.Client or redis.ClusterClient by adding hooks to the redis client. These hooks then use the provided instana.Sensor to trace Redis calls made with this client instance:

rdb := redis.NewClient(&redis.Options{
	Addr: "localhost:6382",
})

instaredis.WrapClient(rdb, sensor)

See the instaredis package documentation for detailed examples.

Documentation

Overview

Example
// Initialize Instana sensor
sensor := instana.NewSensor("redis-client")

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

rdb := redis.NewClient(&redis.Options{
	Addr: "localhost:6382",
})

// Use instaredis.WrapClient() after the Redis client instance is created in order to instrument the client.
// The same instaredis.WrapClient() can be used when creating a Redis client with redis.NewFailoverClient.
// When creating an instance of Redis to communicate with a cluster, instaredis.WrapClusterClient() should be used
// instead. These cases apply when a client is being created via redis.NewClusterClient() or
// redis.NewFailoverClusterClient()
instaredis.WrapClient(rdb, sensor)

// Use the API normally.
rdb.Do(ctx, "incr", "counter")
rdb.Get(ctx, "counter").Bytes()

pipe := rdb.Pipeline()
pipe.Set(ctx, "name", "Instana", time.Minute)
pipe.Incr(ctx, "some_counter")
pipe.Exec(ctx)

txPipe := rdb.TxPipeline()
txPipe.Set(ctx, "email", "info@instana.com", time.Minute)
txPipe.Incr(ctx, "some_counter")
txPipe.Exec(ctx)
Output:

Index

Examples

Constants

View Source
const Version = "1.16.0"

Version is the instrumentation module semantic version

Variables

This section is empty.

Functions

This section is empty.

Types

type InstanaRedisClient added in v1.1.0

type InstanaRedisClient interface {
	AddHook(hook redis.Hook)
	Options() *redis.Options
}

func WrapClient

func WrapClient(client InstanaRedisClient, sensor instana.TracerLogger) InstanaRedisClient

WrapClient wraps the Redis client instance in order to add the instrumentation

type InstanaRedisClusterClient added in v1.1.0

type InstanaRedisClusterClient interface {
	AddHook(hook redis.Hook)
	Options() *redis.ClusterOptions
}

func WrapClusterClient

func WrapClusterClient(clusterClient InstanaRedisClusterClient, sensor instana.TracerLogger) InstanaRedisClusterClient

WrapClusterClient wraps the Redis client instance in order to add the instrumentation

Jump to

Keyboard shortcuts

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