framework: Igbinary serializer in Redis cache driver not working properly

  • Laravel Version: 8.83.25
  • PHP Version: 8.1.1
  • Database Driver & Version: Redis 6.0.6 on Ubuntu 22.04 Redis 6.2.7 on Fedora 36 PhpRedis 5.3.7

Description:

When you enable igbinary serializer for redis in database.php, the actual value stored in redis is serialized with php serializer and some igbinary bytes are added at beginning.

Example: \Cache::put('test', ['a', 'b'])

Actual value saved in Redis: \x00\x00\x00\x02\x11\x1ea:2:{i:0;s:1:\"a\";i:1;s:1:\"b\";}

As for me, it looks like value is serialized with php serializer and afterwards is serialized with igbinary

Expected value in Redis (from igbinary_serialize()): \0\0\0\x02\x14\x02\x06\0\x11\x01a\x06\x01\x11\x01b

Value from Redis if default serializer is used: a:2:{i:0;s:1:"a";i:1;s:1:"b";}

As you see, default serializer value is even shorter than igbinary one, which should never be the case

Checked with more complex stuff, for example putting the model into cache, issue is the same - some bytes from igbinary in beginning and default serializer value aftrewards.

Steps To Reproduce:

  1. Enable Redis::SERIALIZER_IGBINARY serializer in config/database.php
  2. Save some array or object to cache
  3. Go to redis-cli and compare the value inside redis with igbinary_serialize() result

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (7 by maintainers)

Most upvoted comments

I think serialize method should be used by framework only when 'serializer' option in config is set as Redis::SERIALIZER_NONE. In other serializers, even Redis::SERIALIZER_PHP, the extension is reponsible for serializing data.