-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathredis.go
37 lines (31 loc) · 854 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
package goscriptor
import (
"strconv"
"github.com/go-redis/redis/v8"
)
// Option - Redis Option
type Option struct {
Host string
Port int
Password string
DB int
PoolSize int
}
// Create - create a new redis descriptor
func (opt *Option) Create() redis.UniversalClient {
return redis.NewUniversalClient(&redis.UniversalOptions{
Addrs: []string{opt.Host + ":" + strconv.Itoa(opt.Port)},
Password: opt.Password,
DB: opt.DB,
PoolSize: opt.PoolSize,
RouteRandomly: false,
})
}
// UniversalOprions - Redis Option
type UniversalOprions redis.UniversalOptions
// CreateAddrs - create a new redis descriptor
//
// https://redis.uptrace.dev/guide/universal.html
func (opt *UniversalOprions) CreateAddrs() redis.UniversalClient {
return redis.NewUniversalClient((*redis.UniversalOptions)(opt))
}