Memcached CAS

706 views
Skip to first unread message

jainy

unread,
Nov 6, 2008, 12:39:36 PM11/6/08
to memcached

What issues can I have while using CAS ?

Is it atomic ?

I believe its

get and check + set

Does memcached ensures that value of the object will not be changed
after get and before set ?

Regards,
Gaurav Jain

Dustin

unread,
Nov 6, 2008, 2:22:34 PM11/6/08
to memcached
Yes, this is the entire point of a CAS operation (otherwise, you'd
just use get and set).

Clint Webb

unread,
Nov 6, 2008, 9:38:25 PM11/6/08
to memc...@googlegroups.com
Actually, just to clarify.   My understanding of CAS may be wrong though...

Memcache doesnt "ensure that the value of the object will bot be changed after get and before set" 
It is not a lock.   What it does is ensure that the SET does not happen if something has changed the value after the GET.

eg.

GET+CAS
<do some things>
<no other clients change that value>
SET+CAS
! success

or

GET+CAS
<do some things>
<another client changes the value>
SET+CAS
! fails.

CAS does not stop the value from changing.  It stops you from setting a value if it has changed since you did a GET.  In which case you would need to handle it in whatever way suits your situation.
--
"Be excellent to each other"

Dustin

unread,
Nov 6, 2008, 11:35:12 PM11/6/08
to memcached

On Nov 6, 6:38 pm, "Clint Webb" <webb.cl...@gmail.com> wrote:

> CAS does not stop the value from changing.  It stops you from setting a
> value if it has changed since you did a GET.  In which case you would need
> to handle it in whatever way suits your situation.

Yes, this is correct. It's not a lock, but it makes sure you
changed what you expected to change and does so atomically.
Reply all
Reply to author
Forward
0 new messages