8000 feat: added support for `gats` command by ghrushneshr25 · Pull Request #188 · bradfitz/gomemcache · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: added support for gats command #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions memcache/memcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,18 +754,35 @@ func (c *Client) DeleteAll() error {
// returned if the item didn't already exist in the cache.
func (c *Client) GetAndTouch(key string, expiration int32) (item *Item, err error) {< 8000 /td>
err = c.withKeyAddr(key, func(addr net.Addr) error {
return c.getAndTouchFromAddr(addr, key, expiration, func(it *Item) { item = it })
return c.getAndTouchFromAddr(addr, key, expiration, func(it *Item) { item = it }, "gat")
})
if err == nil && item == nil {
err = ErrCacheMiss
}
return
}

func (c *Client) getAndTouchFromAddr(addr net.Addr, key string, expiration int32, cb func(*Item)) error {
// GetAndTouchWithCAS retrieves an item from the cache and updates its expiration time.
// This function is similar to GetAndTouch but uses the "gats" command to perform
// a CAS operation. The CAS operation ensures that the item
// has not been modified or evicted between the retrieval and the update of the
// expiration time. If the item is not found, ErrCacheMiss is returned.
func (c *Client) GetAndTouchWithCAS(key string, expiration int32) (item *Item, err error) {
err = c.withKeyAddr(key, func(addr net.Addr) error {
return c.getAndTouchFromAddr(addr, key, expiration, func(it *Item) { item = it }, "gats")
})
if err == nil && item == nil {
err = ErrCacheMiss
}
return
}

// getAndTouchFromAddr sends a "gat" or "gats" command to the specified address.
// The `command` parameter determines whether to use "gat" (Get And Touch) or "gats" (Get And Touch with CAS).
func (c *Client) getAndTouchFromAddr(addr net.Addr, key string, expiration int32, cb func(*Item), command string) error {
return c.withAddrRw(addr, func(conn *conn) error {
rw := conn.rw
if _, err := fmt.Fprintf(rw, "gat %d %s\r\n", expiration, key); err != nil {
if _, err := fmt.Fprintf(rw, "%s %d %s\r\n", command, expiration, key); err != nil {
return err
}
if err := rw.Flush(); err != nil {
Expand Down
Loading
0