Memcached Check and Set Operation with Python Example – POFTUT

Memcached Check and Set Operation with Python Example

Check and Set Operation aka CAS is a update for existing key-value. For example we get a key-value counter-123 and we increased it to locally 124. Then we try to update the key-value like counter-124 Memcached checks if the value is changed by others. If it is changed we get an error. To track changes Memcached gives us a token.

  • cas the name of the operation
  • key the key we want to change
  • flags related flags
  • expiretime key-value hold interval
  • bytes  the size of the value
  • castoken  the token used by Memcache to track change

Now lets make an example

As always like we do we add new key-value

Now we get the variable but this get operation is a bit different from get because we use gets like below which provides a token too.

  • gets the verb used to get a variable with a token
  • VALUE is the value line
  • counter  is key
  • means zero flag
  • is the size of the value
  • 21  is our magic token
  • 123 is the value
  • END means is the operation is successfull

We have made some operations and incremented the counter value to 124 and want to set the new value

  • cas the verb
  • counter thekey we want to change
  • 0 flag
  • timeout
  • size of the new value
  • 21 token for this operation
  • 124 new value
  • STORED operation successfully complated
LEARN MORE  How To Install Pip on Windows?

Python Application

Leave a Reply

Your email address will not be published. Required fields are marked *