instaredigo

package module
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 10 Imported by: 0

README

Instana instrumentation for Redigo

This module contains instrumentation code for Redis clients written with Redigo

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/instaredigo

Usage

instaredigo offers function wrappers for redis.DialContext(), redis.Dial(), redis.DialURL(), redis.DialURLContext(), redis.NewConn() and for redis.Conn that instrument an instance of redis.Conn using the provided instana.Sensor to trace Redis calls made with this instance.

conn, err := instaredigo.Dial(sensor, "tcp", ":6379")
if err != nil {
    //handle error
}
reply, err := conn.Do("SET", "greetings", "helloworld")

See the instaredigo package documentation for detailed examples.

Documentation

Overview

Example (BasicCommand)
package main

import (
	"context"
	"fmt"
	"os"

	instana "github.com/instana/go-sensor"
	"github.com/instana/go-sensor/instrumentation/instaredigo"
)

func main() {
	// Create a sensor for instana instrumentation
	sensor := instana.NewSensor("mysensor")

	// Create an InstaRedigo connection
	conn, err := instaredigo.Dial(sensor, "tcp", ":7001")
	if err != nil {
		os.Exit(1)
	}
	defer conn.Close()

	// Send a command using the new connection
	ctx := context.Background()
	reply, err := conn.Do("SET", "greetings", "helloworld", ctx)
	if err != nil {
		fmt.Println("Error while sending command. Details: ", err.Error())
	}
	fmt.Println("Response received: ", fmt.Sprintf("%s", reply))
}
Output:

Example (BatchCommands)
package main

import (
	"fmt"
	"os"

	instana "github.com/instana/go-sensor"
	"github.com/instana/go-sensor/instrumentation/instaredigo"
)

func main() {
	// Create a sensor for instana instrumentation
	sensor := instana.NewSensor("mysensor")

	//Create an InstaRedigo connection
	conn, err := instaredigo.Dial(sensor, "tcp", ":7001")
	if err != nil {
		os.Exit(1)
	}
	defer conn.Close()

	// Send a batch of commands  using the new connection
	err = conn.Send("MULTI")
	err = conn.Send("INCR", "foo")
	err = conn.Send("INCR", "bar")
	reply, err := conn.Do("EXEC")
	if err != nil {
		fmt.Println("Error while sending command. Details: ", err.Error())
	}
	fmt.Println("Response received: ", reply)
}
Output:

Index

Examples

Constants

View Source
const Version = "0.20.0"

Version is the instrumentation module semantic version

Variables

This section is empty.

Functions

func Dial

func Dial(sensor instana.TracerLogger, network, address string, options ...redis.DialOption) (redis.Conn, error)

Dial connects to the Redis server at the given network and address using the specified options along with instrumentation code.

func DialContext

func DialContext(sensor instana.TracerLogger, ctx context.Context, network, address string, options ...redis.DialOption) (redis.Conn, error)

DialContext connects to the Redis server at the given network and address using the specified options and context along with instrumentation code.

func DialURL

func DialURL(sensor instana.TracerLogger, rawurl string, options ...redis.DialOption) (redis.Conn, error)

DialURL wraps DialURLContext using context.Background along with the instrumentation code.

func DialURLContext

func DialURLContext(sensor instana.TracerLogger, ctx context.Context, rawurl string, options ...redis.DialOption) (redis.Conn, error)

DialURLContext connects to a Redis server at the given URL using the Redis URI scheme along with the instrumentation code.

func NewConn

func NewConn(sensor instana.TracerLogger, netConn net.Conn, readTimeout, writeTimeout time.Duration) redis.Conn

NewConn returns a new Redigo connection for the given net connection along with the instrumentation code.

Types

This section is empty.

Jump to

Keyboard shortcuts

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