Which operating systems have you tested for this bug?
Linux
Which server did you use?
cli-server (PHP built-in webserver)
Database
No response
What happened?
When a prefix is provided for the Redis cache handler, the getMetaData() method always returns null.
Steps to Reproduce
Set up Redis handler in the file App\Config\Cache.php.
Set the handler redis.
Set a key prefix.
Provide the appropriate Redis configuration.
Ensure that Redis is valid handler.
Now try to store any value in the Redis caching using the service.
Try to access the metadata using the method getMetaData().
It will be received null.
Expected Output
Proper Metadata array about the existing cache key.
Anything else?
In the file system\Cache\Handlers\RedisHandler.phpLine #236,
the key is validated and the prefix is prepended.
In the next line the get() method is called which again prepend the prefix.
Hence, prepending the prefix twice turns the key into an always non-existing key.
The resolution is exchanging the order of execution for both lines.
PHP Version
8.2
CodeIgniter4 Version
4.3.2
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Linux
Which server did you use?
cli-server (PHP built-in webserver)
Database
No response
What happened?
When a prefix is provided for the Redis cache handler, the
getMetaData()
method always returns null.Steps to Reproduce
App\Config\Cache.php
.redis
.Now try to store any value in the Redis caching using the service. Try to access the metadata using the method
getMetaData()
. It will be received null.Expected Output
Proper Metadata array about the existing cache key.
Anything else?
In the file
system\Cache\Handlers\RedisHandler.php
Line #236, thekey
is validated and theprefix
is prepended. In the next line theget()
method is called which again prepend theprefix
.Hence, prepending the
prefix
twice turns thekey
into an always non-existing key. The resolution is exchanging the order of execution for both lines.