cache icon indicating copy to clipboard operation
cache copied to clipboard

Uncaught Apix\Cache\PsrCache\InvalidArgumentException: Item key ('test:string') is invalid

Open KarelWintersky opened this issue 3 years ago • 0 comments

Bug Report

Uncaught Apix\Cache\PsrCache\InvalidArgumentException: Item key ('test:string') is invalid

Code snippet

use Apix\Cache;

$backend = new \Redis();
$backend->connect('localhost');
$backend->select(1);
$cache = Cache\Factory::getPool($backend);

$item = $cache->getItem('test:string');

returns:

PHP Fatal error:  Uncaught Apix\Cache\PsrCache\InvalidArgumentException: Item key ('test:string') is invalid. in 
./vendor/apix/cache/src/PsrCache/Item.php:71
Stack trace:
#0 /vendor/apix/cache/src/PsrCache/Pool.php(53): Apix\Cache\PsrCache\Item::normalizedKey()
#1 /test_redis_apix.php(17): Apix\Cache\PsrCache\Pool->getItem()
#2 {main}
  thrown in /vendor/apix/cache/src/PsrCache/Item.php on line 71

But Redis allowed use this key:

root@quartz:/etc/redis# redis-cli --version
redis-cli 6.2.6

root@quartz:/etc/redis# redis-cli

127.0.0.1:6379> set test:string 'foobar'
OK
127.0.0.1:6379> get test:string
"foobar"
127.0.0.1:6379> 

Also, keys with : recommended by official documentation: https://redis.io/topics/data-types-intro#redis-keys

Very short keys are often not a good idea. There is little point in writing "u1000flw" as a key if you can instead write "user:1000:followers". The latter is more readable and the added space is minor compared to the space used by the key object itself and the value object. While short keys will obviously consume a bit less memory, your job is to find the right balance.

More details

  • Apix-cache version: 1.3
  • Operating System: LMDE (based debian 10)
  • PHP Version: 7.4
  • Redis 6.2.6

KarelWintersky avatar Oct 27 '21 00:10 KarelWintersky