-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomm.go
77 lines (68 loc) · 1.53 KB
/
comm.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package comms
import (
nats "github.com/nats-io/nats.go"
)
func NewComm(addressRedis string, addressNATS string) Comm {
return Comm {NewRedis(addressRedis), NewNATS(addressNATS)}
}
/*
Holds the Redis/NATS cluster and provides a basic way to interact with it.
*/
type Comm struct {
Memory RedisItem
Web* nats.EncodedConn
}
func (c Comm) GetID() string {
return c.Memory.GetID()
}
func (c Comm) Key(key string) Comm {
return Comm {c.Memory.Key(key), c.Web}
}
func (c Comm) Get() string {
return c.Memory.Get()
}
func (c Comm) Integer() int {
return c.Memory.Integer()
}
func (c Comm) Set(val string) {
c.Memory.Set(val)
}
func (c Comm) Incr() int {
return c.Memory.Incr()
}
func (c Comm) Map() map[string]string {
return c.Memory.Map()
}
func (c Comm) KeyVal(key string, val string) int {
return c.Memory.KeyVal(key, val)
}
func (c Comm) KeyValNX(key string, val string) int {
return c.Memory.KeyVal(key, val)
}
func (c Comm) Has(val string) bool {
return c.Memory.Has(val)
}
func (c Comm) Members() []string {
return c.Memory.Members()
}
func (c Comm) Add(val string) {
c.Memory.Add(val)
}
func (c Comm) Rem(val string) {
c.Memory.Rem(val)
}
func (c Comm) Establish(val string) RedisItem {
return c.Memory.Establish(val)
}
func (c Comm) SendString(val string) {
c.Web.Publish(c.Memory.GetID(), val)
}
func (c Comm) SendInt(val int) {
c.Web.Publish(c.Memory.GetID(), val)
}
func (c Comm) SendFloat(val float64) {
c.Web.Publish(c.Memory.GetID(), val)
}
func (c Comm) Recv(handler nats.Handler) {
c.Web.Subscribe(c.Memory.GetID(), handler)
}