Skip to content

Commit

Permalink
Export Compare-And-Swap (CAS) id in Item
Browse files Browse the repository at this point in the history
Even though the CAS id is a transparent token there are use cases where the
client of the module could be interested in storing the token from a retrieved
Item out-of-process for later use with a CAS operation. This is impossible if
the field is unexported.
  • Loading branch information
martins authored and bradfitz committed Sep 4, 2023
1 parent 6f412de commit 43a49b4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions memcache/memcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,11 @@ type Item struct {
// Zero means the Item has no expiration time.
Expiration int32

// Compare and swap ID.
casid uint64
// CasID is the compare and swap ID.
//
// It's populated by get requests and then the same value is
// required for a CompareAndSwap request to succeed.
CasID uint64
}

// conn is a connection to a server.
Expand Down Expand Up @@ -535,7 +538,7 @@ func parseGetResponse(r *bufio.Reader, cb func(*Item)) error {
// It does not read the bytes of the item.
func scanGetResponseLine(line []byte, it *Item) (size int, err error) {
pattern := "VALUE %s %d %d %d\r\n"
dest := []interface{}{&it.Key, &it.Flags, &size, &it.casid}
dest := []interface{}{&it.Key, &it.Flags, &size, &it.CasID}
if bytes.Count(line, space) == 3 {
pattern = "VALUE %s %d %d\r\n"
dest = dest[:3]
Expand Down Expand Up @@ -618,7 +621,7 @@ func (c *Client) populateOne(rw *bufio.ReadWriter, verb string, item *Item) erro
var err error
if verb == "cas" {
_, err = fmt.Fprintf(rw, "%s %s %d %d %d %d\r\n",
verb, item.Key, item.Flags, item.Expiration, len(item.Value), item.casid)
verb, item.Key, item.Flags, item.Expiration, len(item.Value), item.CasID)
} else {
_, err = fmt.Fprintf(rw, "%s %s %d %d %d\r\n",
verb, item.Key, item.Flags, item.Expiration, len(item.Value))
Expand Down

0 comments on commit 43a49b4

Please sign in to comment.