Home » Php » php – Memcached get may return "not found" even though the key is set

php – Memcached get may return "not found" even though the key is set

Posted by: admin February 25, 2020 Leave a comment

Questions:

I’m using the Memcached extension in PHP, and I observe a strange behavior.

Sometimes, Memcached::get returns false with a result of RES_NOTFOUND, even though the key has been set with Memcached::set. This happens a few times an hour on a server with about 300 Memcached requests per second.

First I thought, somehow the set requests may fail and delete the key instead of updating it. Now I made a statistic about the different results, and I only receive RES_SUCCESS or RES_NOTFOUND. This makes me think that any error that happens while getting a key reports as not found, even though there are many result codes documented.

Is there a way to get more precise result codes? Or is it just impossible to rely on finding an existing key?

By the way, we are using PHP 7.2.

How to&Answers: