Beispiel #1
0
func (s *RedisStore) Scan(partition string) <-chan *bucket.Bucket {
	retBuckets := make(chan *bucket.Bucket)
	go func(out chan *bucket.Bucket) {
		rc := s.redisPool.Get()
		defer rc.Close()
		defer close(out)
		rc.Send("MULTI")
		rc.Send("SMEMBERS", partition)
		rc.Send("DEL", partition)
		reply, err := redis.Values(rc.Do("EXEC"))
		if err != nil {
			fmt.Printf("at=%q error=%s\n", "bucket-store-scan", err)
			return
		}
		var delCount int64
		var members []string
		redis.Scan(reply, &members, &delCount)
		for _, member := range members {
			id, err := bucket.ParseId(member)
			if err != nil {
				fmt.Printf("at=%q error=%s\n", "bucket-store-parse-key", err)
				continue
			}
			out <- &bucket.Bucket{Id: id}
		}
	}(retBuckets)
	return retBuckets
}
Beispiel #2
0
func (s *RedisStore) Scan(schedule time.Time) (<-chan *bucket.Bucket, error) {
	retBuckets := make(chan *bucket.Bucket)
	p, err := s.lockPartition()
	if err != nil {
		return retBuckets, err
	}
	partition := partitionPrefix + "." + strconv.Itoa(int(p))
	go func(out chan *bucket.Bucket) {
		rc := s.redisPool.Get()
		defer rc.Close()
		defer close(out)
		defer s.unlockPartition(p)
		rc.Send("MULTI")
		rc.Send("SMEMBERS", partition)
		rc.Send("DEL", partition)
		reply, err := redis.Values(rc.Do("EXEC"))
		if err != nil {
			fmt.Printf("at=%q error=%s\n", "bucket-store-scan", err)
			return
		}
		var delCount int64
		var members []string
		redis.Scan(reply, &members, &delCount)
		for _, member := range members {
			id, err := bucket.ParseId(member)
			if err != nil {
				fmt.Printf("at=%q error=%s\n", "bucket-store-parse-key", err)
				continue
			}
			bucketReady := id.Time.Add(id.Resolution)
			if !bucketReady.After(schedule) {
				out <- &bucket.Bucket{Id: id}
			} else {
				if err := s.putback(id); err != nil {
					fmt.Printf("putback-error=%s\n", err)
				}
			}
		}
	}(retBuckets)
	return retBuckets, nil
}