-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Open
Description
Laravel Version
11.x - 12.x
PHP Version
8.x
Database Driver & Version
Redis Support => enabled
Redis Version => 6.3.0
Redis Sentinel Version => 1.0
Available serializers => php, json, igbinary
Available compression => lzf, zstd, lz4
Description
When using phpredis with serializers (SERIALIZER_PHP, SERIALIZER_IGBINARY, SERIALIZER_JSON, etc) in Laravel's Cache layer, storing boolean false values results in null being returned when retrieved. This only affects phpredis with certain serializers, not Predis.
Root Cause (potential)
The bug is in Illuminate\Redis\Connections\PhpRedisConnection::get() method. The original code:
public function get($key)
{
$result = $this->command('get', [$key]);
return $result !== false ? $result : null; // ← BUG: Can't distinguish false value from missing key
}The problem: When phpredis with a serializer retrieves a stored false boolean value, it correctly deserializes and returns the boolean false. However, the code treats false (whether it means "key not found" or "value is false") the same way - both return null.
Steps To Reproduce
Prerequisites
// config/database.php
'redis' => [
'client' => 'phpredis',
'options' => [
'prefix' => 'igb:', // optional
'serializer' => Redis::SERIALIZER_IGBINARY, // any except Redis::SERIALIZER_NONE
'compression' => Redis::COMPRESSION_LZ4, // optional
],
],Reproduction Steps
- Store
falsevalue:Redis::connection()->setex('key_false', 300, false)orCache::put('key_false', false, 300) - Retrieve via Cache:
Cache::get('key_false') - Result:
null(incorrect - should befalse) - Direct Redis retrieval:
Redis::get('key_false')returnsfalse(correct)
Expected Behavior
Cache::get('key') should return the cached false value, not null.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels