-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG]: Redis Cache/Storage Adapter race condition #16269
Comments
Other cache adapters can be optimized replacing
libmemcached (in current implementation actually doing 2 requests in $cache->get($key))
|
What do we do if the actual stored value is $key = 'somekey';
$value = $this->doGet($key); // value is `false`
if (false === $value) {
return $defaultValue; // null
}
return $value; The reason we did it that way was just for the above scenario. Thoughts? |
Redis is not supporting storing boolean or int types, it stores everything as string. If the actual value will be Answering your question @niden, it will work properly with actual $key = 'somekey';
$serialized_value = $this->doGet($key); // if stored value is `false` will return string "b:0;"
if (false === $value) {
return $defaultValue; // null
}
$value = $this->getUnserializedData($serialized_value, $defaultValue); // "b:0;" will be unserialized to false
return $value; |
That I did not know :) Thank you for reporting this. I will get on it shortly. |
Describe the bug
\Phalcon\Cache\Adapter\Redis
has race condition that returnsfalse
in cases when value was deleted on redis server afterthis->has(key)
check and beforethis->doGet(key)
. Alsothis->has(key)
making excessive request to redis server.cphalcon/phalcon/Storage/Adapter/AbstractAdapter.zep
Line 148 in ce1392e
To Reproduce
Will eventualy return false :
Expected behavior
Must return
"value"
if value exists in cache and"default_value"
in case cache miss..Solution
\Redis->get() returns bool
false
in case key not exists in Redis. We must removethis->has(key)
request from\Phalcon\Cache\Adapter\Redis::get()
, and add check forfalse
. This will return$defaultValue
for non existing keys, and will not create excessive request viathis->has(key)
Details
The text was updated successfully, but these errors were encountered: