forked from QLeelulu/ohlala
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush-to-user.go
54 lines (52 loc) · 1.73 KB
/
push-to-user.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
package main
import (
"github.com/QLeelulu/goku"
"github.com/QLeelulu/ohlala/golink"
"github.com/QLeelulu/ohlala/golink/models"
"strconv"
"strings"
"time"
)
func main() {
redisClient := models.GetRedis()
defer redisClient.Quit()
// 从推送队列取出处理
for {
// 格式: pushtype,userid(topicid),linkid,timestamp
item, err := redisClient.Rpop(golink.KEY_LIST_PUSH_TO_USER)
if err != nil {
if strings.Index(err.Error(), "Nonexisting key") < 0 {
goku.Logger().Errorln(err.Error())
}
time.Sleep(30 * time.Second)
} else if item != nil {
items := strings.Split(item.String(), ",")
if len(items) > 1 {
kid, err := strconv.ParseInt(items[1], 10, 64)
if err != nil {
goku.Logger().Errorln(err.Error())
continue
}
linkId, err := strconv.ParseInt(items[2], 10, 64)
if err != nil {
goku.Logger().Errorln(err.Error())
continue
}
if items[0] == "1" {
// 推给粉丝
err = models.LinkForUser_ToUserFollowers(kid, linkId)
} else if items[0] == "2" {
// 推给话题关注者
err = models.LinkForUser_ToTopicidFollowers(kid, linkId)
} else {
goku.Logger().Errorln("值错误:", item.String())
}
if err != nil {
goku.Logger().Errorln(err.Error())
}
}
} else {
time.Sleep(30 * time.Second)
}
}
}