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 }
func (self *Storage) ListKeys(p *trib.Pattern, r *trib.List) error { self.listLock.Lock() defer self.listLock.Unlock() ret := make([]string, 0, len(self.lists)) for k := range self.lists { if p.Match(k) { ret = append(ret, k) } } r.L = ret if Logging { log.Printf("ListKeys(%q, %q) => %d", p.Prefix, p.Suffix, len(r.L)) for i, s := range r.L { log.Printf(" %d: %q", i, s) } } return nil }
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 }