PickServer returns the server address that a given item should be shared onto.
(key string)
| 103 | // PickServer returns the server address that a given item |
| 104 | // should be shared onto. |
| 105 | func (s *MemcachedJumpHashSelector) PickServer(key string) (net.Addr, error) { |
| 106 | s.mu.RLock() |
| 107 | defer s.mu.RUnlock() |
| 108 | if len(s.addrs) == 0 { |
| 109 | return nil, memcache.ErrNoServers |
| 110 | } else if len(s.addrs) == 1 { |
| 111 | return s.addrs[0], nil |
| 112 | } |
| 113 | cs := xxhash.Sum64String(key) |
| 114 | idx := jumpHash(cs, len(s.addrs)) |
| 115 | return s.addrs[idx], nil |
| 116 | } |
| 117 | |
| 118 | // Each iterates over each server and calls the given function. |
| 119 | // If f returns a non-nil error, iteration will stop and that |