Skip to content

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
Development

Successfully merging this pull request may close these issues.

2 participants