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

Conversation

ghrushneshr25
Copy link
Contributor
@ghrushneshr25 ghrushneshr25 commented Apr 4, 2025

Add support for gats command via GetAndTouchWithCAS

Summary

This PR introduces support for the gats (Get and Touch with CAS) command in the gomemcached client library by adding a new method: GetAndTouchWithCAS.

Motivation

The gats command allows clients to retrieve an item while updating its expiration time, with CAS (Check-And-Set) semantics. This is particularly useful when implementing optimistic concurrency control, ensuring that items haven't been modified or evicted between the time they are read and their expiration is updated.

Changes

  • Added a new method:
    func (c *Client) GetAndTouchWithCAS(key string, expiration int32) (*Item, error)
  • Internally uses the "gats" command in the request to retrieve the item and update its TTL while fetching the CAS value.
  • Returns ErrCacheMiss if the key is not found.

Example Usage

item, err := client.GetAndTouchWithCAS("my-key", 60)

Notes

  • Maintains backward compatibility.
  • Mirrors existing GetAndTouch behaviour but with CAS support.

@ghrushneshr25 ghrushneshr25 changed the title feat: add GetAndTouchWithCAS function feat: added support for gats command Apr 4, 2025
@dormando
Copy link
Collaborator
dormando commented Apr 4, 2025

(sorry, I'm still booting up on the project and mostly doing triage); the normal get command always does gets under the hood, so there's only one top level Get command. We should probably adjust the GAT that was merged to just be GATS?

There's a separate issue/pr about servers that don't support gets/gats though, so that PR could cover/fix both commands.

@dormando dormando added this to the Small protocol issues milestone Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Develo 3737 pment

Successfully merging this pull request may close these issues.

2 participants
0