forked from izumin5210/nrredigo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconn.go
67 lines (58 loc) · 1.48 KB
/
conn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package nrredigo
import (
"strings"
"github.com/gomodule/redigo/redis"
"github.com/newrelic/go-agent/v3/newrelic"
)
func wrapConn(c redis.Conn, txn *newrelic.Transaction, cfg *Config) redis.Conn {
return &wrappedConn{
Conn: c,
txn: txn,
cfg: cfg,
}
}
type wrappedConn struct {
redis.Conn
txn *newrelic.Transaction
cfg *Config
}
func (c *wrappedConn) Do(commandName string, args ...interface{}) (interface{}, error) {
if c.txn != nil {
seg := c.createSegment(commandName)
seg.ParameterizedQuery = formatCommand(commandName, args)
defer seg.End()
}
return c.Conn.Do(commandName, args...)
}
func (c *wrappedConn) Send(commandName string, args ...interface{}) error {
if c.txn != nil {
seg := c.createSegment(commandName)
seg.ParameterizedQuery = formatCommand(commandName, args)
defer seg.End()
}
return c.Conn.Send(commandName, args...)
}
func (c *wrappedConn) Flush() error {
if c.txn != nil {
seg := c.createSegment("flush")
defer seg.End()
}
return c.Conn.Flush()
}
func (c *wrappedConn) Receive() (interface{}, error) {
if c.txn != nil {
seg := c.createSegment("receive")
defer seg.End()
}
return c.Conn.Receive()
}
func (c *wrappedConn) createSegment(cmdName string) newrelic.DatastoreSegment {
return newrelic.DatastoreSegment{
StartTime: c.txn.StartSegmentNow(),
Product: newrelic.DatastoreRedis,
Operation: strings.ToLower(cmdName),
Host: c.cfg.Host,
PortPathOrID: c.cfg.PortPathOrID,
DatabaseName: c.cfg.DBName,
}
}