Example #1
0
func (url Url) IncCounter() {
	redis_client, e := helpers.GetRedisClient()
	if e != nil {
		return nil, e
	}
	redis_client.Inc(fmt.Sprintf("visits:%s", url.Digest))
}
Example #2
0
func (u Url) Save() error {
	redis_client, e := helpers.GetRedisClient()
	if e != nil {
		return e
	}
	redis_client.Set(u.Digest[0:5], []byte(u.Href))
	redis_client.Set(fmt.Sprintf("%s_cnt", u.Digest[0:5]), 0)
	redis_client.Rpush("digests", []byte(u.Digest[0:5]))

	return nil
}
Example #3
0
func FindUrl(digest string) (*Url, error) {
	redis_client, e := helpers.GetRedisClient()
	if e != nil {
		return nil, e
	}

	href, e := redis_client.Get(digest)
	if e != nil {
		return nil, e
	}
	url := Url{string(href), digest}

	return &url, nil
}
Example #4
0
func FindUrls() ([]Url, error) {
	redis_client, e := helpers.GetRedisClient()
	if e != nil {
		return nil, e
	}

	nb_urls, e := redis_client.Llen("digests")
	if e != nil {
		return nil, e
	}

	urls := make([]Url, nb_urls)
	for i := int64(0); i < nb_urls; i++ {
		digest, e := redis_client.Lindex("digests", i)
		if e != nil {
			return nil, e
		}

		url_bytes, e := redis_client.Get(fmt.Sprintf("%x", digest))
		url := fmt.Sprintf("%s", url_bytes)
		urls[i] = Url{url, fmt.Sprintf("%x", digest)}
	}
	return urls[:], nil
}