ppgoredis

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

ppgoredis

This package instruments the go-redis/redis package.

Installation

$ go get github.com/pinpoint-apm/pinpoint-go-agent/plugin/goredis
import "github.com/pinpoint-apm/pinpoint-go-agent/plugin/goredis"

Usage

PkgGoDev

This package instruments the go-redis calls. Use the NewClient as the redis.NewClient and the NewClusterClient as redis.NewClusterClient, respectively. It supports go-redis v6.10.0 and later.

rc = ppgoredis.NewClient(redisOpts)

It is necessary to pass the context containing the pinpoint.Tracer to Client using Client.WithContext.

rc = rc.WithContext(pinpoint.NewContext(context.Background(), tracer))
rc.Pipeline()
package main

import (
    "github.com/go-redis/redis"
    "github.com/pinpoint-apm/pinpoint-go-agent"
    "github.com/pinpoint-apm/pinpoint-go-agent/plugin/goredis"
)

var redisClient *ppgoredis.Client
var redisClusterClient *ppgoredis.ClusterClient

func redisv6(w http.ResponseWriter, r *http.Request) {
    c := redisClient.WithContext(r.Context())
    redisPipeIncr(c.Pipeline())
}

func redisv6Cluster(w http.ResponseWriter, r *http.Request) {
    c := redisClusterClient.WithContext(r.Context())
    redisPipeIncr(c.Pipeline())
}

func redisPipeIncr(pipe redis.Pipeliner) {
    incr := pipe.Incr("foo")
    pipe.Expire("foo", time.Hour)
    _, er := pipe.Exec()
    fmt.Println(incr.Val(), er)
}

func main() {
    ... //setup agent

    addrs := []string {"localhost:6379", "localhost:6380"}

    //redis client
    redisOpts := &redis.Options{
        Addr: addrs[0],
    }
    redisClient = ppgoredis.NewClient(redisOpts)

    //redis cluster client
    redisClusterOpts := &redis.ClusterOptions{
        Addrs: addrs,
    }
    redisClusterClient = ppgoredis.NewClusterClient(redisClusterOpts)

    http.HandleFunc("/redis", phttp.WrapHandlerFunc(redisv6))
    http.HandleFunc("/rediscluster", phttp.WrapHandlerFunc(redisv6Cluster))

    ...
}

Full Example Source

Documentation

Overview

Package ppgoredis instruments the go-redis/redis package (https://github.com/go-redis/redis).

This package instruments the go-redis calls. Use the NewClient as the redis.NewClient.

rc = ppgoredis.NewClient(redisOpts)

It is necessary to pass the context containing the pinpoint.Tracer to Client using Client.WithContext.

rc = rc.WithContext(pinpoint.NewContext(context.Background(), tracer))
rc.Pipeline()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*redis.Client
	// contains filtered or unexported fields
}

Client wraps redis.Client.

func NewClient

func NewClient(opt *redis.Options) *Client

NewClient returns a new Client ready to instrument.

func (*Client) WithContext

func (c *Client) WithContext(ctx context.Context) *Client

WithContext sets the context. It is possible to trace only when the given context contains a pinpoint.Tracer.

type ClusterClient

type ClusterClient struct {
	*redis.ClusterClient
	// contains filtered or unexported fields
}

ClusterClient wraps redis.ClusterClient.

func NewClusterClient

func NewClusterClient(opt *redis.ClusterOptions) *ClusterClient

NewClusterClient returns a new ClusterClient ready to instrument.

func (*ClusterClient) WithContext

func (c *ClusterClient) WithContext(ctx context.Context) *ClusterClient

WithContext sets the context. It is possible to trace only when the given context contains a pinpoint.Tracer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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