github.com/epsagon/epsagon-go@v1.39.0/example/redis_wrapper/main.go (about) 1 package main 2 3 import ( 4 "context" 5 "io" 6 "net/http" 7 8 "github.com/epsagon/epsagon-go/epsagon" 9 epsagonhttp "github.com/epsagon/epsagon-go/wrappers/net/http" 10 epsagonredis "github.com/epsagon/epsagon-go/wrappers/redis" 11 "github.com/go-redis/redis/v8" 12 ) 13 14 func main() { 15 config := epsagon.NewTracerConfig("redis-wrapper-test", "") 16 config.MetadataOnly = false 17 18 mux := http.NewServeMux() 19 mux.HandleFunc("/ping", epsagonhttp.WrapHandleFunc( 20 config, 21 func(w http.ResponseWriter, req *http.Request) { 22 // initialize the redis client as usual 23 // make sure to pass in the epsagon tracer context 24 rdb := epsagonredis.NewClient(&redis.Options{ 25 Addr: "localhost:6379", 26 Password: "", 27 DB: 0, 28 }, req.Context()) 29 30 ctx := context.Background() 31 32 // pipeline operations 33 pipe := rdb.Pipeline() 34 pipe.Set(ctx, "somekey", "somevalue", 0) 35 pipe.Get(ctx, "somekey") 36 pipe.Exec(ctx) 37 38 // single operation 39 value, _ := rdb.Get(ctx, "somekey").Result() 40 41 io.WriteString(w, value) 42 }), 43 ) 44 45 http.ListenAndServe(":8080", mux) 46 }