func postArticle(client redis.Client, user, title, link string) string {
	id, err := client.Incr("article:")
	if err != nil {
		log.Fatal("Incrエラーだよ", err.Error())
	}

	articleID := strconv.FormatInt(id, 20)
	voted := "voted:" + articleID

	if _, err := client.Sadd(voted, []byte(user)); err != nil {
		log.Fatal("Saddエラーだよ", err.Error())
	}

	if _, err := client.Expire(voted, int64(ONE_WEEK_DAY*time.Second)); err != nil {
		log.Fatal("Expireエラーだよ", err.Error())
	}
	now := time.Now()
	article := "article:" + articleID
	fmt.Println("articleID", articleID)

	if err := client.Hmset(article, map[string]string{
		"title":  title,
		"link":   link,
		"poster": user,
		"time":   now.String(),
		"votes":  "1",
	}); err != nil {
		log.Fatal("Hmsetエラーだよ", err.Error())
	}

	if _, err := client.Zadd("score:", []byte(article), float64(now.Unix()+VOTE_SCORE)); err != nil {
		log.Fatal("Zaddエラーだよ", err.Error())
	}
	if _, err := client.Zadd("time:", []byte(article), float64(now.Unix())); err != nil {
		log.Fatal("Zaddエラーだよ", err.Error())
	}

	return articleID
}
Esempio n. 2
0
func setToBeHandled(input string) {

	c := redis.Client{Addr: addr, Password: pass}
	c.Auth(pass)

	c.Set(input, "1")
	c.Expire(input, EXPIRETIME)

}
Esempio n. 3
0
func GetTempTicket(expire_seconds int, scene_id int, scene_str string) string {
	url := `https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=` + GetAccessToken()
	data := `{"expire_seconds": ` + strconv.Itoa(expire_seconds) +
		`, "action_name": "QR_SCENE", ` +
		`"action_info": {"scene": {"scene_id": ` + strconv.Itoa(scene_id) +
		`,"scene_str":"` + scene_str + `"}}}`
	if ticket := getTicket(url, data); len(ticket) < 1 {
		return ""
	} else {
		var redcli redis.Client
		redcli.Addr = beego.AppConfig.String("redis_addr")
		redcli.Hset(ticket, "scene_id", []byte(strconv.Itoa(scene_id)))
		redcli.Expire(ticket, 120)
		return ticket
	}
}
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)
}