MCPcopy
hub / github.com/bradfitz/gomemcache / PickServer

Method PickServer

memcache/selector.go:114–129  ·  view source on GitHub ↗
(key string)

Source from the content-addressed store, hash-verified

112}
113
114func (ss *ServerList) PickServer(key string) (net.Addr, error) {
115 ss.mu.RLock()
116 defer ss.mu.RUnlock()
117 if len(ss.addrs) == 0 {
118 return nil, ErrNoServers
119 }
120 if len(ss.addrs) == 1 {
121 return ss.addrs[0], nil
122 }
123 bufp := keyBufPool.Get().(*[]byte)
124 n := copy(*bufp, key)
125 cs := crc32.ChecksumIEEE((*bufp)[:n])
126 keyBufPool.Put(bufp)
127
128 return ss.addrs[cs%uint32(len(ss.addrs))], nil
129}

Callers 1

benchPickServerFunction · 0.95

Calls 1

GetMethod · 0.80

Tested by 1

benchPickServerFunction · 0.76