Esempio n. 1
0
func (r *Redis) KeysByTags(matchTags ...string) ([]string, Error) {
	conn := r.pool.Get()
	defer conn.Close()

	keys, err := r.getRawKeys(conn)
	if err != nil {
		return nil, err
	}

	tagKeys := make([]interface{}, 0)
	for _, key := range keys {
		tagKeys = append(tagKeys, interface{}(r.tagKey(key)))
	}

	tags, err2 := redis.Strings(conn.Do("MGET", tagKeys...))
	if err2 != nil {
		return nil, redisErr(err2)
	}

	matchedKeys := make([]string, 0)
	for index, tags := range tags {
		tagList := strings.Split(tags, ";")

		for _, matchTag := range matchTags {
			if utils.StrIn(tagList, matchTag) {
				matchedKeys = append(matchedKeys, keys[index])
			}
		}
	}

	return r.cleanKeys(matchedKeys), nil
}
Esempio n. 2
0
func (fs *Fs) KeysByTags(tags ...string) ([]string, apperror.Error) {
	allKeys, err := fs.Keys()
	if err != nil {
		return nil, err
	}

	matchedKeys := make([]string, 0)
	for _, key := range allKeys {
		item, err := fs.Get(key)
		if err != nil {
			return nil, err
		}

		for _, tag := range tags {
			if utils.StrIn(item.GetTags(), tag) {
				matchedKeys = append(matchedKeys, key)
			}
		}
	}

	return matchedKeys, nil
}