Memcached concurrency problem

$m = new Memcached();
$res = $m->get("key");

if(empty($res)) {
    $ret = $m->set("key");
    $ret && $this->insert($data);
}

Why does the insert data repeat in the above code? What is the correct way to write it?

Mar.28,2021

does anyone know how to solve it? Wait on the line! Currently, there are the following abnormal data

clipboard.png

clipboard.png


solve this problem with mem locks


there is obviously something wrong with the logic of your code
$ret & & $this- > insert ($data);

) Insert

only when

ret is empty.


MC is not persistent either. It can only be intercepted at the first level. To prevent repetition, it still depends on the unique index of the database


if there is too much concurrency, you can consider using locks, and $ret & $this- > insert ($data);) in your logic. Without a rigorous judgment, that is, when concurrency is realized, as long as $ret is implemented, it will result in repeated insertion of $this- > insert, and at the same time limit duplicate values in combination with the unique index of the database

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b717-2bae8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b717-2bae8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?