Skip to content

Igbinary serializer in Redis cache driver not working properly #44652

@andreyzp87

Description

@andreyzp87
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions