Ejemplo n.º 1
0
func (self *clientWithPrefix) ListKeys(p *trib.Pattern, list *trib.List) error {
	// escape colon
	binName := colon.Escape(self.bin)
	p.Prefix = binName + "::" + colon.Escape(p.Prefix)
	p.Suffix = colon.Escape(p.Suffix)

	// RPC call
	err := self.originalClient.ListKeys(p, list)
	if err != nil {
		return err
	}

	// unescape and trim
	for i, str := range list.L {
		str = colon.Unescape(str)
		list.L[i] = strings.TrimPrefix(str, self.bin+"::")
	}
	return nil
}
Ejemplo n.º 2
0
func (self *ReplicaClient) ListKeys(p *trib.Pattern, list *trib.List) error {
	// escape colon
	binName := colon.Escape(self.name)
	p.Prefix = binName + "::" + p.Prefix
	p.Suffix = p.Suffix + "list"

	// RPC call
	// get the list of logs of the key

	// a list used as temp storage
	tmpList := trib.List{make([]string, 0)}
	for index, ad := range self.addr {
		tempclient := &client{ad}
		err1 := tempclient.ListKeys(p, &tmpList)
		if err1 == nil {
			break
		} else if index < len(self.addr)-1 {
			continue
		} else {
			return err1
		}
	}

	blockCh := make(chan string, len(tmpList.L))
	for _, str := range tmpList.L {
		go func(str string) {
			tmpList2 := trib.List{make([]string, 0)}
			s1 := colon.Escape(self.name) + "::"
			s2 := "list"
			str = strings.TrimPrefix(str, s1)
			str = strings.TrimSuffix(str, s2)
			_ = self.ListGet(str, &tmpList2) // ignore this err?
			if len(tmpList2.L) != 0 {
				blockCh <- str
			} else {
				blockCh <- ""
			}
		}(str)
	}

	list.L = make([]string, 0, len(tmpList.L))
	for _ = range tmpList.L {
		result := <-blockCh
		if result != "" {
			list.L = append(list.L, result)
		}
	}

	// unescape and trim
	if len(list.L) > 0 {
		for i, str := range list.L {
			//str = colon.Unescape(str)
			s1 := colon.Escape(self.name) + "::"
			s2 := "valu"
			str = strings.TrimPrefix(str, s1)
			str = strings.TrimSuffix(str, s2)
			list.L[i] = str
		}
	}
	return nil
}