-
Notifications
You must be signed in to change notification settings - Fork 141
/
redis.go
30 lines (26 loc) · 625 Bytes
/
redis.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
package redisClient
import (
"context"
"fmt"
"github.com/go-redis/redis/v8"
apmgoredis "go.elastic.co/apm/module/apmgoredisv8"
)
type Redis struct {
Config *redis.Options
Client *redis.Client
}
func RedisAdapter(config *redis.Options) *Redis {
conn := NewClient()
return &Redis{Config: config, Client: conn}
}
func NewClient() *redis.Client {
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "", // no password set
DB: 0, // use default DB
})
rdb.AddHook(apmgoredis.NewHook())
pong, err := rdb.Ping(context.Background()).Result()
fmt.Println(pong, err)
return rdb
}