예제 #1
0
func getArticle(client redis.Client, page int, order string) []map[string]string {
	if order == "" {
		order = "score:"
	}

	start := (page - 1) * ARTICLES_PER_PAGE
	end := start + ARTICLES_PER_PAGE - 1

	ids, err := client.Zrevrange(order, start, end)
	if err != nil {
		log.Fatal("Zrevrange エラーだよ", err.Error())
	}

	articles := make([]map[string]string, 0)
	for _, id := range ids {

		articleData := make(map[string]string, 0)
		if err := client.Hgetall(string(id), articleData); err != nil {
			log.Fatal("Hgetall エラーだよ", err.Error())
		}
		articleData["id"] = string(id)

		articles = append(articles, articleData)
	}

	return articles
}
예제 #2
0
파일: redis2.go 프로젝트: aimeiyan/gocode
func main() {
	client := redis.Client{Addr: "192.168.1.101:6379"}
	// client.Addr = "127.0.0.1:6379"

	client.Hmset("h1", map[string]string{"Key3": "abc", "Key4": "sdfs",
		"key1": "abc", "key2": "sdfs"})

	m := make(map[string]string)
	client.Hgetall("h1", m)
	log.Println(m)

	a := AA{}
	client.Hgetall("h1", &a)
	log.Println(a)
}