/// 获取用户列表并报错到redis数据库中 KEY=wx_UserList func GetUserList() { url := "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + GetAccessToken() key := "wx_UserList" var v WXUserList c, status := global.HttpGet(url) if status >= 0 { dec := json.NewDecoder(strings.NewReader(c)) for { if err := dec.Decode(&v); err == io.EOF { break } else if err != nil { log.Fatal(err) } } var redcli redis.Client redcli.Addr = beego.AppConfig.String("redis_addr") if ok, err := redcli.Exists(key); err != nil { log.Println(err.Error()) } else { if ok { redcli.Del(key) } } for _, value := range v.Data.Openid { redcli.Rpush(key, []byte(value)) } log.Println("Successful: Add Userlist ") } }
func alreadyBeingHandled(input string) bool { c := redis.Client{Addr: addr, Password: pass} c.Auth(pass) check, _ := c.Exists(input) return check }
func checkLearningDB(msg string) bool { /*set up redis client*/ c := redis.Client{Addr: addr, Password: pass} c.Auth(pass) // hash the message hash := md5hash(msg) // check databse check, _ := c.Exists(hash) if check == true { return true } else { return false } }
func getGroupArticle(client redis.Client, group string, page int) []map[string]string { order := "score:" key := order + group if ok, err := client.Exists(key); err != nil { log.Fatal("Exists エラーだよ", err.Error()) } else if !ok { //if _, err := client.Zinterstore(key, "group:" + group, order); err != nil { // log.Fatal("Zinterstore エラーだよ", err.Error()) //} if _, err := client.Expire(key, 60); err != nil { log.Fatal("Expire エラーだよ", err.Error()) } } return getArticle(client, page, key) }
func articleVote(client redis.Client, user, article string) { cutoff := time.Now().Add(ONE_WEEK_DAY * time.Second) // 記事チェック if hit, err := client.Exists("time:"); err != nil { log.Fatal("Existsエラーだよ", err.Error()) } else if !hit { log.Fatal("記事がないよ ") } // 期限チェック if score, err := client.Zscore("time:", []byte(article)); err != nil { log.Fatal("Zscoreエラーだよ", err.Error()) } else { if cutoff.After(time.Unix(int64(score), 0)) { fmt.Println("Afterだった ", cutoff.Unix(), " ", int64(score)) return } } articleID := strings.TrimPrefix(article, "article:") fmt.Println("articleID", articleID) ok, err := client.Sadd("voted:"+articleID, []byte(user)) if err != nil { log.Fatal("Saddエラーだよ", err.Error()) } if ok { if _, err := client.Zincrby("score:", []byte(article), VOTE_SCORE); err != nil { log.Fatal("Zincrbyエラーだよ", err.Error()) } if _, err := client.Hincrby(article, "votes", 1); err != nil { log.Fatal("Hincrbyエラーだよ", err.Error()) } } }