-
Notifications
You must be signed in to change notification settings - Fork 1
/
redis_output.go
42 lines (33 loc) · 863 Bytes
/
redis_output.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
package zipkin
import (
"encoding/json"
"gopkg.in/redis.v3"
)
type redisOutput struct {
*redis.Client
config *Config
key string
}
// NewRedisOutput() returns an Output that converts ZipKin spans to JSON and RPUSH
// (http://redis.io/commands/RPUSH) it to the specified Redis (http://redis.io) server.
func NewRedisOutput(config *Config, addr, password string, db int64, key string) (Output, error) {
client := redis.NewClient(&redis.Options{
Addr: addr,
Password: password,
DB: db,
})
if e := client.Ping().Err(); e != nil {
return nil, e
}
return &redisOutput{client, config, key}, nil
}
func (ro *redisOutput) Write(result OutputMap) (e error) {
var buffer []byte
if buffer, e = json.Marshal(result); e != nil {
return e
}
if _, e = ro.RPush(ro.key, string(buffer)).Result(); e != nil {
return e
}
return nil
}