Is Memcached get and put methods are thread safe

2019-04-13 04:12发布

问题:

Is there any chance of getting a garbled value for a key in memcached in multi thread environment?. If so how to avoid it with minimal time of synchronization?.

Using Java client to access memcached server

回答1:

No. Memcache will return a value that somebody wrote previously, and not a garbled value. If you get/modify/put you have no guarantee that the put applies to the same value as the get. Use the cas (compare and set) operation if you need to synchronize.