Exemplo n.º 1
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
}
Exemplo n.º 2
0
func (s *RedisStore) putback(id *bucket.Id) error {
	defer utils.MeasureT("bucket.putback", time.Now())
	rc := s.redisPool.Get()
	defer rc.Close()
	key := id.Encode()
	partition := s.bucketPartition([]byte(key))
	rc.Send("MULTI")
	rc.Send("SADD", partition, key)
	rc.Send("EXPIRE", partition, 300)
	_, err := rc.Do("EXEC")
	if err != nil {
		return err
	}
	return nil
}
Exemplo n.º 3
0
func (s *RedisStore) Get(b *bucket.Bucket) error {
	defer utils.MeasureT("bucket.get", time.Now())
	rc := s.redisPool.Get()
	defer rc.Close()

	reply, err := redis.Values(rc.Do("LRANGE", b.Id.Encode(), 0, -1))
	if err != nil {
		return err
	}
	if len(reply) == 0 {
		return errors.New("redis_store: Empty bucket.")
	}
	// The redis.Strings reply will always wrap our array in an outer
	// array. Above, we checked that we would always have at least 1 elm.
	if err := decodeList(reply[0].([]byte), &b.Vals); err != nil {
		return err
	}
	return nil
}