/*
This command is equal to SUNION, but instead of returning the resulting set, it
is stored in destination.

http://redis.io/commands/sunionstore
*/
767068
func (c *Client) SUnionStore(destination string, key ...string) (int64, error) {
	var ret int64

	args := make([][]byte, len(key)+2)
	args[0] = []byte("SUNIONSTORE")
	args[1] = []byte(destination)

	for i := range key {
		args[2+i] = []byte(key[i])
	}

	err := c.command(&ret, args...)

	return ret, err
}
317726
func NewRedisStore(client *redis.Client, prefix string) *RedisStore {
	if !strings.HasSuffix(prefix, ":") {
		prefix += ":"
	}
	return &RedisStore{
		client: client,
		prefix: prefix,
	}
}
895950
func NewStoreIndexCommandBuilder() *StoreIndexCommandBuilder {
	protobuf := &rpbRiakYZ.RpbYokozunaIndexPutReq{
		Index: &rpbRiakYZ.RpbYokozunaIndex{},
	}
	builder := &StoreIndexCommandBuilder{protobuf: protobuf}
	return builder
}
1097996
func (c *ContainerServer) ContainerStateToDisk(ctr *oci.Container) error {
	// ignore errors, this is a best effort to have up-to-date info about
	// a given container before its state gets stored
	c.Runtime().UpdateContainerStatus(ctr)

	jsonSource, err := ioutils.NewAtomicFileWriter(ctr.StatePath(), 0644)
	if err != nil {
		return err
	}
	defer jsonSource.Close()
	enc := json.NewEncoder(jsonSource)
	return enc.Encode(ctr.State())
}
140279
func (c *asyncClient) Sunionstore(arg0 string, arg1 []string) (stat FutureBool, err Error) {
	//	arg0bytes := []byte(arg0)
	//	arg1bytes := concatAndGetBytes(arg1, " ")
	args := appendAndConvert(arg0, arg1...)

	//	resp, err := c.conn.QueueRequest(&SUNIONSTORE, [][]byte{arg0bytes, arg1bytes})
	resp, err := c.conn.QueueRequest(&SUNIONSTORE, args)
	if err == nil {
		stat = resp.future.(FutureBool)
	}

	return
}
1263829
func (s *MatcherSession) AllocateRetrieval() (uint, bool) {
	fetcher := make(chan uint)

	select {
	case <-s.quit:
		return 0, false
	case s.matcher.retrievers <- fetcher:
		bit, ok := <-fetcher
		return bit, ok
	}
}
707545
func NewRedisKVStore(client *redis.Client, prefix string) *RedisKVStore {
	if !strings.HasSuffix(prefix, ":") {
		prefix += ":"
	}
	return &RedisKVStore{
		RedisStore: NewRedisStore(client, prefix),
	}
}
219232
func (cmd *CancelAllocationCommand) Source() (interface{}, error) {
	source := make(map[string]interface{})
	source["index"] = cmd.index
	source["shard"] = cmd.shardId
	source["node"] = cmd.node
	source["allow_primary"] = cmd.allowPrimary
	return source, nil
}
1339952
func (left *Resource) Equivalent(right Resource) bool {
	if left == nil {
		return right.IsEmpty()
	}
	if left.GetName() != right.GetName() ||
		left.GetType() != right.GetType() ||
		left.GetRole() != right.GetRole() {
		return false
	}
	if a, b := left.GetAllocationInfo(), right.GetAllocationInfo(); !a.Equivalent(b) {
		return false
	}
	if a, b := left.GetReservations(), right.GetReservations(); len(a) != len(b) {
		return false
	} else {
		for i := range a {
			ri := &a[i]
			if !ri.Equivalent(&b[i]) {
				return false
			}
		}
	}
	if !left.GetReservation().Equivalent(right.GetReservation()) {
		return false
	}
	if !left.GetDisk().Equivalent(right.GetDisk()) {
		return false
	}
	if (left.Revocable == nil) != (right.Revocable == nil) {
		return false
	}
	if a, b := left.ProviderID, right.ProviderID; (a == nil) != (b == nil) {
		return false
	} else if a != nil && a.Value != b.Value {
		return false
	}
	if a, b := left.Shared, right.Shared; (a == nil) != (b == nil) {
		return false
	}

	switch left.GetType() {
	case SCALAR:
		return left.GetScalar().Compare(right.GetScalar()) == 0
	case RANGES:
		return Ranges(left.GetRanges().GetRange()).Equivalent(right.GetRanges().GetRange())
	case SET:
		return left.GetSet().Compare(right.GetSet()) == 0
	default:
		return false
	}
}
241218
func (rc *Redis) Put(key string, value interface{}) error {
	val, err := Encode(value)
	if err != nil {
		if rc.Debug {
			log.Println("[Redis]EncodeErr: ", err, "Key:", key)
		}
		return err
	}
	if _, err = rc.do("SETEX", key, rc.LifeTime, val); err != nil {
		return err
	}
	_, err = rc.do("HSET", rc.key, key, true)
	if err != nil {
		if rc.Debug {
			log.Println("[Redis]PutErr: ", err, "Key:", key)
		}
		return err
	}
	if rc.Debug {
		log.Println("[Redis]Put: ", key)
	}
	return err
}
612115
func (r *RedisStore) MGet(keys []string) (map[string]interface{}, error) {
	values, err := r.client.MGet(keys...).Result()

	newValues := make(map[string]interface{}, len(keys))

	for k, v := range keys {
		value := values[k]
		if err != nil {
			return nil, err
		}

		newValues[v] = value
	}
	return newValues, nil
}
87723
func (env *maasEnviron) Storage() storage.Storage {
	env.ecfgMutex.Lock()
	defer env.ecfgMutex.Unlock()
	return env.storageUnlocked
}
585975
func (archiver *Archiver) CopyWithTar(src, dst string) error {
	srcSt, err := os.Stat(src)
	if err != nil {
		return err
	}
	if !srcSt.IsDir() {
		return archiver.CopyFileWithTar(src, dst)
	}

	// if this Archiver is set up with ID mapping we need to create
	// the new destination directory with the remapped root UID/GID pair
	// as owner
	rootIDs := archiver.IDMappingsVar.RootPair()
	// Create dst, copy src's content into it
	logrus.Debugf("Creating dest directory: %s", dst)
	if err := idtools.MkdirAllAndChownNew(dst, 0755, rootIDs); err != nil {
		return err
	}
	logrus.Debugf("Calling TarUntar(%s, %s)", src, dst)
	return archiver.TarUntar(src, dst)
}
385264
func (cli *Client) CopyToContainer(ctx context.Context, containerID, dstPath string, content io.Reader, options types.CopyToContainerOptions) error {
	query := url.Values{}
	query.Set("path", filepath.ToSlash(dstPath)) // Normalize the paths used in the API.
	// Do not allow for an existing directory to be overwritten by a non-directory and vice versa.
	if !options.AllowOverwriteDirWithFile {
		query.Set("noOverwriteDirNonDir", "true")
	}

	if options.CopyUIDGID {
		query.Set("copyUIDGID", "true")
	}

	apiPath := "/containers/" + containerID + "/archive"

	response, err := cli.putRaw(ctx, apiPath, query, content, nil)
	defer ensureReaderClosed(response)
	if err != nil {
		return wrapResponseError(err, response, "container:path", containerID+":"+dstPath)
	}

	// TODO this code converts non-error status-codes (e.g., "204 No Content") into an error; verify if this is the desired behavior
	if response.statusCode != http.StatusOK {
		return fmt.Errorf("unexpected status code from daemon: %d", response.statusCode)
	}

	return nil
}
685762
func NewRedisStore(c *redis.Client, prefix, sid string, dur time.Duration, kv map[interface{}]interface{}) *RedisStore {
	return &RedisStore{
		c:        c,
		prefix:   prefix,
		sid:      sid,
		duration: dur,
		data:     kv,
	}
}
547511
func NewRedisStore(pool *redis.Pool, keyPrefix string, db int) *redigostore.RedigoStore {
	st, err := redigostore.New(pool, keyPrefix, db)
	if err != nil {
		// As of this writing, creating a Redis store never returns an error
		// so this should be safe while providing some ability to return errors
		// in the future.
		panic(err)
	}
	return st
}
1324993
func (s *CreateBuildOutput) SetStorageLocation(v *S3Location) *CreateBuildOutput {
	s.StorageLocation = v
	return s
}