-
Notifications
You must be signed in to change notification settings - Fork 0
/
resque.go
53 lines (42 loc) · 1.03 KB
/
resque.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
package resque
import redis "gopkg.in/redis.v5"
// Client holds an active resque connection
type Client struct {
redisClient *redis.Client
namespace string
}
// RedisOptions is a wrapper of https://godoc.org/gopkg.in/redis.v5#Options
type RedisOptions redis.Options
// Configuration stores the required configuration to create a resque client
type Configuration struct {
// Redis URI connection string
RedisURI string
Redis RedisOptions
// Resque namespace (default: "resque")
Namespace string
}
// New returns a new resque client.
// Goroutine safe
func New(cfg Configuration) (*Client, error) {
var opts redis.Options
if cfg.RedisURI == "" {
opts = redis.Options(cfg.Redis)
} else {
optsNew, err := redis.ParseURL(cfg.RedisURI)
if err != nil {
return nil, err
}
opts = *optsNew
}
client := redis.NewClient(&opts)
if err := client.Ping().Err(); err != nil {
return nil, err
}
if cfg.Namespace == "" {
cfg.Namespace = "resque"
}
return &Client{
redisClient: client,
namespace: cfg.Namespace,
}, nil
}