Skip to content

Commit 43a49b4

Browse files
msoderstrbradfitz
authored andcommitted
Export Compare-And-Swap (CAS) id in Item
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.
1 parent 6f412de commit 43a49b4

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

memcache/memcache.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,11 @@ type Item struct {
171171
// Zero means the Item has no expiration time.
172172
Expiration int32
173173

174-
// Compare and swap ID.
175-
casid uint64
174+
// CasID is the compare and swap ID.
175+
//
176+
// It's populated by get requests and then the same value is
177+
// required for a CompareAndSwap request to succeed.
178+
CasID uint64
176179
}
177180

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

0 commit comments

Comments
 (0)