migrate from govendor to dep
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
_*
|
||||
*.out
|
||||
*~
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
## About
|
||||
|
||||
This is a memcache client library for the Go programming language
|
||||
(http://golang.org/).
|
||||
|
||||
## Installing
|
||||
|
||||
### Using *go get*
|
||||
|
||||
$ go get github.com/bradfitz/gomemcache/memcache
|
||||
|
||||
After this command *gomemcache* is ready to use. Its source will be in:
|
||||
|
||||
$GOPATH/src/github.com/bradfitz/gomemcache/memcache
|
||||
|
||||
## Example
|
||||
|
||||
import (
|
||||
"github.com/bradfitz/gomemcache/memcache"
|
||||
)
|
||||
|
||||
func main() {
|
||||
mc := memcache.New("10.0.0.1:11211", "10.0.0.2:11211", "10.0.0.3:11212")
|
||||
mc.Set(&memcache.Item{Key: "foo", Value: []byte("my value")})
|
||||
|
||||
it, err := mc.Get("foo")
|
||||
...
|
||||
}
|
||||
|
||||
## Full docs, see:
|
||||
|
||||
See https://godoc.org/github.com/bradfitz/gomemcache/memcache
|
||||
|
||||
Or run:
|
||||
|
||||
$ godoc github.com/bradfitz/gomemcache/memcache
|
||||
|
||||
+26
-11
@@ -56,7 +56,7 @@ var (
|
||||
ErrNoStats = errors.New("memcache: no statistics available")
|
||||
|
||||
// ErrMalformedKey is returned when an invalid key is used.
|
||||
// Keys must be at maximum 250 bytes long, ASCII, and not
|
||||
// Keys must be at maximum 250 bytes long and not
|
||||
// contain whitespace or control characters.
|
||||
ErrMalformedKey = errors.New("malformed: key is too long or contains invalid characters")
|
||||
|
||||
@@ -64,14 +64,17 @@ var (
|
||||
ErrNoServers = errors.New("memcache: no servers configured or available")
|
||||
)
|
||||
|
||||
// DefaultTimeout is the default socket read/write timeout.
|
||||
const DefaultTimeout = 100 * time.Millisecond
|
||||
|
||||
const (
|
||||
buffered = 8 // arbitrary buffered channel size, for readability
|
||||
maxIdleConnsPerAddr = 2 // TODO(bradfitz): make this configurable?
|
||||
// DefaultTimeout is the default socket read/write timeout.
|
||||
DefaultTimeout = 100 * time.Millisecond
|
||||
|
||||
// DefaultMaxIdleConns is the default maximum number of idle connections
|
||||
// kept for any single address.
|
||||
DefaultMaxIdleConns = 2
|
||||
)
|
||||
|
||||
const buffered = 8 // arbitrary buffered channel size, for readability
|
||||
|
||||
// resumableError returns true if err is only a protocol-level cache error.
|
||||
// This is used to determine whether or not a server connection should
|
||||
// be re-used or not. If an error occurs, by default we don't reuse the
|
||||
@@ -89,7 +92,7 @@ func legalKey(key string) bool {
|
||||
return false
|
||||
}
|
||||
for i := 0; i < len(key); i++ {
|
||||
if key[i] <= ' ' || key[i] > 0x7e {
|
||||
if key[i] <= ' ' || key[i] == 0x7f {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -133,6 +136,14 @@ type Client struct {
|
||||
// If zero, DefaultTimeout is used.
|
||||
Timeout time.Duration
|
||||
|
||||
// MaxIdleConns specifies the maximum number of idle connections that will
|
||||
// be maintained per address. If less than one, DefaultMaxIdleConns will be
|
||||
// used.
|
||||
//
|
||||
// Consider your expected traffic rates and latency carefully. This should
|
||||
// be set to a number higher than your peak parallel requests.
|
||||
MaxIdleConns int
|
||||
|
||||
selector ServerSelector
|
||||
|
||||
lk sync.Mutex
|
||||
@@ -147,9 +158,6 @@ type Item struct {
|
||||
// Value is the Item's value.
|
||||
Value []byte
|
||||
|
||||
// Object is the Item's value for use with a Codec.
|
||||
Object interface{}
|
||||
|
||||
// Flags are server-opaque flags whose semantics are entirely
|
||||
// up to the app.
|
||||
Flags uint32
|
||||
@@ -199,7 +207,7 @@ func (c *Client) putFreeConn(addr net.Addr, cn *conn) {
|
||||
c.freeconn = make(map[string][]*conn)
|
||||
}
|
||||
freelist := c.freeconn[addr.String()]
|
||||
if len(freelist) >= maxIdleConnsPerAddr {
|
||||
if len(freelist) >= c.maxIdleConns() {
|
||||
cn.nc.Close()
|
||||
return
|
||||
}
|
||||
@@ -228,6 +236,13 @@ func (c *Client) netTimeout() time.Duration {
|
||||
return DefaultTimeout
|
||||
}
|
||||
|
||||
func (c *Client) maxIdleConns() int {
|
||||
if c.MaxIdleConns > 0 {
|
||||
return c.MaxIdleConns
|
||||
}
|
||||
return DefaultMaxIdleConns
|
||||
}
|
||||
|
||||
// ConnectTimeoutError is the error type used when it takes
|
||||
// too long to connect to the desired host. This level of
|
||||
// detail can generally be ignored.
|
||||
|
||||
+17
-2
@@ -41,6 +41,21 @@ type ServerList struct {
|
||||
addrs []net.Addr
|
||||
}
|
||||
|
||||
// staticAddr caches the Network() and String() values from any net.Addr.
|
||||
type staticAddr struct {
|
||||
ntw, str string
|
||||
}
|
||||
|
||||
func newStaticAddr(a net.Addr) net.Addr {
|
||||
return &staticAddr{
|
||||
ntw: a.Network(),
|
||||
str: a.String(),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *staticAddr) Network() string { return s.ntw }
|
||||
func (s *staticAddr) String() string { return s.str }
|
||||
|
||||
// SetServers changes a ServerList's set of servers at runtime and is
|
||||
// safe for concurrent use by multiple goroutines.
|
||||
//
|
||||
@@ -58,13 +73,13 @@ func (ss *ServerList) SetServers(servers ...string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
naddr[i] = addr
|
||||
naddr[i] = newStaticAddr(addr)
|
||||
} else {
|
||||
tcpaddr, err := net.ResolveTCPAddr("tcp", server)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
naddr[i] = tcpaddr
|
||||
naddr[i] = newStaticAddr(tcpaddr)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user