Y
Y
yetanotherape2012-05-11 08:42:12
symfony
yetanotherape, 2012-05-11 08:42:12

Why do replace() before set() in Memcache?

Understanding the Memcache library for PHP, I came across an interesting comment : before doing set() of a value that could already exist, you need to do replace() , because ostensibly when working with a cluster of memcached servers, set() can set several values ​​​​with the same keys (on different nodes, I guess), and then get can return any of these values.
In order to avoid problems, the author suggests using the following code:

$result = $memcache->replace($key, $var); <br>
if( $result == false ) <br>
{ <br>
    $result = $memcache->set($key, $var); <br>
} <br>

This approach is widely used, for example, it can be found in the memcached wrapper in symfony .
I can imagine how values ​​\u200b\u200bwith the same keys can appear in different nodes, but why set () is to blame for this duplication of keys and how replace () can save from this - at least kill I don’t understand.
How do you think this can happen? What is the fundamental difference between set() and replace() in this context?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolai Vasilchuk, 2012-05-11
@Anonym

Are you talking about Memcache or Memcache d ? These are different libraries and Memcache really has some kind of glitch with setters. Try memcached.

D
deadkrolik, 2012-05-12
@deadkrolik

clack clack

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question