-
Notifications
You must be signed in to change notification settings - Fork 20
/
redis.go
39 lines (32 loc) · 867 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
31
32
33
34
35
36
37
38
39
package redis
import (
"github.com/go-redis/redis"
"github.com/micro-company/go-auth/utils"
"github.com/sirupsen/logrus"
)
var (
log = logrus.New()
Redis *redis.Client
)
func init() {
// Logging =================================================================
// Setup the logger backend using Sirupsen/logrus and configure
// it to use a custom JSONFormatter. See the logrus docs for how to
// configure the backend at github.com/Sirupsen/logrus
log.Formatter = new(logrus.JSONFormatter)
}
func ConnectToRedis() {
// Get configuration
REDIS_URL := utils.Getenv("REDIS_URL", "redis://localhost:6379/1")
opt, err := redis.ParseURL(REDIS_URL)
if err != nil {
panic(err)
}
Redis = redis.NewClient(opt)
_, err = Redis.Ping().Result()
if err != nil {
log.Panic("Fail connect to Redis")
panic(err)
}
log.Info("Success connect to Redis")
}