Example #1
0
func (s *RedisStore) Put(b *bucket.Bucket) error {
	defer s.Mchan.Time("bucket.put", time.Now())

	rc := s.redisPool.Get()
	defer rc.Close()

	b.Lock()
	key, err := b.Id.Encode()
	value := b.Vals
	b.Unlock()
	if err != nil {
		return err
	}
	args := make([]interface{}, len(value)+1)
	args[0] = key
	for i := range value {
		x := strconv.FormatFloat(value[i], 'f', 10, 64)
		args[i+1] = []byte(x)
	}
	partition := s.bucketPartition(key)
	rc.Send("MULTI")
	rc.Send("RPUSH", args...)
	rc.Send("EXPIRE", key, 300)
	rc.Send("SADD", partition, key)
	rc.Send("EXPIRE", partition, 300)
	_, err = rc.Do("EXEC")
	if err != nil {
		return err
	}
	return nil
}
Example #2
0
func (s *RedisStore) Put(b *bucket.Bucket) error {
	defer utils.MeasureT("bucket.put", time.Now())

	rc := s.redisPool.Get()
	defer rc.Close()

	b.Lock()
	key, err := b.Id.Encode()
	value := b.Vals
	b.Unlock()
	if err != nil {
		return err
	}

	//TODO(ryandotsmith): Ensure consistent keys are being written.
	partition := s.bucketPartition([]byte(key))
	rc.Send("MULTI")
	rc.Send("RPUSH", key, value)
	rc.Send("EXPIRE", key, 300)
	rc.Send("SADD", partition, key)
	rc.Send("EXPIRE", partition, 300)
	_, err = rc.Do("EXEC")
	if err != nil {
		return err
	}
	return nil
}
Example #3
0
func bucketsEqual(actual, expected *bucket.Bucket) bool {
	if actual.Id.Name != expected.Id.Name {
		return false
	}
	if actual.Id.Source != expected.Id.Source {
		return false
	}
	if actual.Sum() != expected.Sum() {
		return false
	}
	return true
}
Example #4
0
func (s *RedisStore) Get(b *bucket.Bucket) error {
	defer s.Mchan.Time("bucket.get", time.Now())
	rc := s.redisPool.Get()
	defer rc.Close()

	key, err := b.Id.Encode()
	if err != nil {
		return err
	}
	reply, err := redis.Values(rc.Do("LRANGE", key, 0, -1))
	if err != nil {
		return err
	}
	if len(reply) == 0 {
		return errors.New("redis_store: Empty bucket.")
	}
	b.Vals = make([]float64, len(reply))
	for i := range reply {
		numstr := reply[i].([]byte)
		numf, err := strconv.ParseFloat(string(numstr), 64)
		if err == nil {
			b.Vals[i] = numf
		}

	}
	return nil
}