Search code examples
memcachedspymemcached

What should cas id for initial set call?


I am implementing CAS based memcached retrieval and have a possibly dumb question. If there is no entry for particular key, i.e. first time its stored, What should I set the cas id too?


Solution

  • Whenever you set a new key that doesn't exist in memcached then the cas value should be 0. If you set it to something other then 0 you will get a NOT_FOUND error. The reason for this error is that memcached will try to check the cas value you gave against the key you are trying to set in memcached. Since that key doesn't exist yet you get NOT_FOUND.