aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/bradfitz
diff options
context:
space:
mode:
authortechknowlogick <techknowlogick@gitea.io>2021-02-28 18:08:33 -0500
committerGitHub <noreply@github.com>2021-02-28 18:08:33 -0500
commit47f6a4ec3f058f69b65fb6501d6ac98994b8f8da (patch)
tree4d1421a4c836de9de4014117419c151035c17eec /vendor/github.com/bradfitz
parent030646eea41e17e58e11e73b19339630b6d6148e (diff)
downloadgitea-47f6a4ec3f058f69b65fb6501d6ac98994b8f8da.tar.gz
gitea-47f6a4ec3f058f69b65fb6501d6ac98994b8f8da.zip
go1.16 (#14783)
Diffstat (limited to 'vendor/github.com/bradfitz')
-rw-r--r--vendor/github.com/bradfitz/gomemcache/memcache/memcache.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/vendor/github.com/bradfitz/gomemcache/memcache/memcache.go b/vendor/github.com/bradfitz/gomemcache/memcache/memcache.go
index 25e88ca261..545a3e7958 100644
--- a/vendor/github.com/bradfitz/gomemcache/memcache/memcache.go
+++ b/vendor/github.com/bradfitz/gomemcache/memcache/memcache.go
@@ -112,6 +112,7 @@ var (
resultTouched = []byte("TOUCHED\r\n")
resultClientErrorPrefix = []byte("CLIENT_ERROR ")
+ versionPrefix = []byte("VERSION")
)
// New returns a memcache client using the provided server(s)
@@ -398,6 +399,30 @@ func (c *Client) flushAllFromAddr(addr net.Addr) error {
})
}
+// ping sends the version command to the given addr
+func (c *Client) ping(addr net.Addr) error {
+ return c.withAddrRw(addr, func(rw *bufio.ReadWriter) error {
+ if _, err := fmt.Fprintf(rw, "version\r\n"); err != nil {
+ return err
+ }
+ if err := rw.Flush(); err != nil {
+ return err
+ }
+ line, err := rw.ReadSlice('\n')
+ if err != nil {
+ return err
+ }
+
+ switch {
+ case bytes.HasPrefix(line, versionPrefix):
+ break
+ default:
+ return fmt.Errorf("memcache: unexpected response line from ping: %q", string(line))
+ }
+ return nil
+ })
+}
+
func (c *Client) touchFromAddr(addr net.Addr, keys []string, expiration int32) error {
return c.withAddrRw(addr, func(rw *bufio.ReadWriter) error {
for _, key := range keys {
@@ -644,6 +669,12 @@ func (c *Client) DeleteAll() error {
})
}
+// Ping checks all instances if they are alive. Returns error if any
+// of them is down.
+func (c *Client) Ping() error {
+ return c.selector.Each(c.ping)
+}
+
// Increment atomically increments key by delta. The return value is
// the new value after being incremented or an error. If the value
// didn't exist in memcached the error is ErrCacheMiss. The value in