Skip to content

Commit d7e81fc

Browse files
ghrushneshr25bradfitz
authored andcommitted
added support to execute "gat"
1 parent 36d5281 commit d7e81fc

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

memcache/memcache.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,34 @@ func (c *Client) DeleteAll() error {
750750
})
751751
}
752752

753+
// Get and Touch the item with the provided key. The error ErrCacheMiss is
754+
// returned if the item didn't already exist in the cache.
755+
func (c *Client) GetAndTouch(key string, expiration int32) (item *Item, err error) {
756+
err = c.withKeyAddr(key, func(addr net.Addr) error {
757+
return c.getAndTouchFromAddr(addr, key, expiration, func(it *Item) { item = it })
758+
})
759+
if err == nil && item == nil {
760+
err = ErrCacheMiss
761+
}
762+
return
763+
}
764+
765+
func (c *Client) getAndTouchFromAddr(addr net.Addr, key string, expiration int32, cb func(*Item)) error {
766+
return c.withAddrRw(addr, func(conn *conn) error {
767+
rw := conn.rw
768+
if _, err := fmt.Fprintf(rw, "gat %d %s\r\n", expiration, key); err != nil {
769+
return err
770+
}
771+
if err := rw.Flush(); err != nil {
772+
return err
773+
}
774+
if err := parseGetResponse(rw.Reader, conn, cb); err != nil {
775+
return err
776+
}
777+
return nil
778+
})
779+
}
780+
753781
// Ping checks all instances if they are alive. Returns error if any
754782
// of them is down.
755783
func (c *Client) Ping() error {

0 commit comments

Comments
 (0)