codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.38k stars 1.9k forks source link

Bug: increment/decrement not working in Cache RedisHandler; method "remember" not listed in CacheInterface #6385

Closed tzalexander closed 2 years ago

tzalexander commented 2 years ago

PHP Version

8.0

CodeIgniter4 Version

4.2.4

CodeIgniter4 Installation Method

Composer (as dependency to an existing project)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

fpm-fcgi

Database

MySQL

What happened?

The methods increment and decrement use the wrong php redis hashKey. Currently "data" is used - it should be "__ci_value" if I am right.

The method "remember" is not listed CacheInterface (system/Cache/) and is not suggested. See docs https://www.codeigniter.com/user_guide/libraries/caching.html.

Thank you

Steps to Reproduce

cache()->save('test', 5);  // test = 5
cache()->decrement('test', 2);

cache()->get('test'); // test = 5; it should be 3

Expected Output

3 instead of 5

Anything else?

No response

paulbalandan commented 2 years ago

The methods increment and decrement use the wrong php redis hashKey. Currently "data" is used - it should be "__ci_value" if I am right.

Please open a PR with your changes so that we can discuss further. Also don't forget to add unit tests.

The method "remember" is not listed CacheInterface (system/Cache/) and is not suggested. See docs https://www.codeigniter.com/user_guide/libraries/caching.html.

This is intended. The "remember" method came after CacheInterface was finalized, so adding it would break custom implementations of the interface. It can be added to the interface though in a major version bump.

paulbalandan commented 2 years ago

It seems the increment and decrement functions are untested. https://github.com/codeigniter4/CodeIgniter4/blob/57385ea1bf64fb31c235f9c15eff4d39a69cbbc1/tests/system/Cache/Handlers/RedisHandlerTest.php#L169-L176