Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get_multi / set_multi atomic?

In the official FAQ of Memcached i read:

"All individual commands sent to memcached are absolutely atomic."

However this is still unclear to me when it comes to get_multi and set_multi. I'd like to know whether get_multi and set_multi are atomic in the following sense:

  • All writes performed by set_multi will be performed together atomically.
  • All reads performed by get_multi will be performed together atomically.

For example these situations should be impossible:

1)

  • Initially contents of the cache is {'a': 0, 'b': 0}
  • machine A calls set_multi({'a': 1, 'b': 1})
  • machine B calls get_multi(['a', 'b']) and receives {'a': 1, 'b': 0}

2)

  • Initially contents of the cache is {'a': 0, 'b': 0}
  • machine A calls `set({'a': 1})
  • machine A calls `set({'b': 2})
  • machine B calls get_multi(['a', 'b']) and receives {'a': 0, 'b': 2}

This question is just so important for my design, that I thought I'd better ask for confirmation.

like image 537
julx Avatar asked Aug 12 '26 21:08

julx


1 Answers

As I read this section, get_multi issues multiple requests that run in parallel, the idea being that for large requests, get_multi allows the total amount of time to get all results to be reduced. I don't see any guarantee or mention that the independent requests, done together, are collectively atomic. The same rule likely applies to set_multi (i.e. the individual requests are atomic, but the collection of them is not).

There also appears to be no mention of transactions.

like image 125
jefflunt Avatar answered Aug 16 '26 08:08

jefflunt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!