-
Notifications
You must be signed in to change notification settings - Fork 2
/
group.go
51 lines (47 loc) · 1.09 KB
/
group.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
package main
import (
"fmt"
"google.golang.org/protobuf/proto"
"github.com/gomodule/redigo/redis"
guaproto "github.com/syhlion/gua/proto"
)
type Group struct {
apiRedis *redis.Pool
groupRedis *redis.Pool
delayRedis *redis.Pool
}
func (g *Group) GetGroup(groupName string) (otpToken string, err error) {
c := g.groupRedis.Get()
defer c.Close()
groupKey := fmt.Sprintf("USER_%s", groupName)
return redis.String(c.Do("GET", groupKey))
}
func (g *Group) GetJobList(groupName string) (jobs []*guaproto.Job, err error) {
c := g.delayRedis.Get()
defer c.Close()
jobKey := fmt.Sprintf("JOB-%s-*", groupName)
keys, err := RedisScan(c, jobKey)
if err != nil {
return
}
jobs = make([]*guaproto.Job, 0)
for _, v := range keys {
b, err := redis.Bytes(c.Do("GET", v))
if err != nil {
continue
}
jb := &guaproto.Job{}
err = proto.Unmarshal(b, jb)
if err != nil {
continue
}
jobs = append(jobs, jb)
}
return
}
func (g *Group) GetFuncList(groupName string) (otpToken string, err error) {
return
}
func (g *Group) GetNodeList(groupName string) (otpToken string, err error) {
return
}