-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
63 lines (56 loc) · 1.74 KB
/
client.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
54
55
56
57
58
59
60
61
62
63
package redis
import (
"github.com/farseer-go/fs/container"
"github.com/farseer-go/fs/core"
"github.com/go-redis/redis/v8"
"time"
)
type client struct {
redisKey
redisString
redisHash
redisList
redisSet
redisZSet
redisLock
redisPub
redisElection
original *redis.Client
}
// newClient 初始化
func newClient(redisConfig redisConfig) IClient {
rdb := redis.NewClient(&redis.Options{
Addr: redisConfig.Server, //localhost:6379
Password: redisConfig.Password, // no password Set
DB: redisConfig.DB, // use default DB
DialTimeout: time.Duration(redisConfig.ConnectTimeout) * time.Millisecond, //链接超时时间设置
WriteTimeout: time.Duration(redisConfig.SyncTimeout) * time.Millisecond, //同步超时时间设置
ReadTimeout: time.Duration(redisConfig.ResponseTimeout) * time.Millisecond, //响应超时时间设置
})
return &client{
original: rdb,
redisKey: redisKey{rdb: rdb},
redisString: redisString{rdb: rdb},
redisHash: redisHash{rdb: rdb},
redisList: redisList{rdb: rdb},
redisSet: redisSet{rdb: rdb},
redisZSet: redisZSet{rdb: rdb},
redisLock: redisLock{rdb: rdb},
redisPub: redisPub{rdb: rdb},
redisElection: redisElection{rdb: rdb},
}
}
func (receiver *client) RegisterEvent(eventName string, fns ...core.ConsumerFunc) {
// 注册仓储
container.Register(func() core.IEvent {
return ®isterEvent{
eventName: eventName,
client: receiver,
}
}, eventName)
go subscribe(receiver, eventName, fns)
}
// Original 获取原生的客户端
func (receiver *client) Original() *redis.Client {
return receiver.original
}