|
if (true !== this->has(key)) { |
Description
After upgrading Phalcon from 4.0.6 to 5.8.0 and PHP from 7.2 to 8.3, we noticed a performance issue related to the get method when using Redis as a cache backend. The method first calls has (which internally executes an EXISTS command) before calling get, effectively doubling the number of Redis operations. Under high traffic, this redundancy negatively impacts Redis performance.
Expected Behavior
The get method should retrieve the value directly without first checking for existence, unless absolutely necessary. The default value handling should be done in a more optimized manner.
Current Behavior
- The
get method first calls has -> Redis executes EXISTS key.
- Then,
get is called -> Redis executes GET key.
- This results in two commands for every single retrieval operation, reducing efficiency under load.
Steps to Reproduce
- Upgrade Phalcon from
4.0.6 to 5.8.0.
- Use Redis as a cache backend.
- Call
$cache->get('some_key', 'default_value') in a high-traffic scenario.
- Monitor Redis and observe the
EXISTS call happening before GET.
Proposed Solution
Modify the get method to avoid calling has. Instead, rely on the GET result directly:
- If
GET returns null (or false), use the default value.
- This would eliminate the extra
EXISTS call and improve Redis performance.
Environment
- Phalcon Version:
5.8.0
- PHP Version:
8.3
- Redis Version:
7.0.15
- Operating System:
Ubuntu 22.04


Would it be possible to optimize the get method to avoid this redundancy? Looking forward to your feedback.
cphalcon/phalcon/Storage/Adapter/AbstractAdapter.zep
Line 166 in 83677f1
Description
After upgrading Phalcon from
4.0.6to5.8.0and PHP from7.2to8.3, we noticed a performance issue related to thegetmethod when using Redis as a cache backend. The method first callshas(which internally executes anEXISTScommand) before callingget, effectively doubling the number of Redis operations. Under high traffic, this redundancy negatively impacts Redis performance.Expected Behavior
The
getmethod should retrieve the value directly without first checking for existence, unless absolutely necessary. The default value handling should be done in a more optimized manner.Current Behavior
getmethod first callshas-> Redis executesEXISTS key.getis called -> Redis executesGET key.Steps to Reproduce
4.0.6to5.8.0.$cache->get('some_key', 'default_value')in a high-traffic scenario.EXISTScall happening beforeGET.Proposed Solution
Modify the
getmethod to avoid callinghas. Instead, rely on theGETresult directly:GETreturnsnull(or false), use the default value.EXISTScall and improve Redis performance.Environment
5.8.08.37.0.15Ubuntu 22.04Would it be possible to optimize the
getmethod to avoid this redundancy? Looking forward to your feedback.