diff --git a/src/Illuminate/Cache/RedisStore.php b/src/Illuminate/Cache/RedisStore.php index 7782f3db120e..f3aa8a3dce34 100755 --- a/src/Illuminate/Cache/RedisStore.php +++ b/src/Illuminate/Cache/RedisStore.php @@ -292,7 +292,7 @@ public function setPrefix($prefix) */ protected function serialize($value) { - return is_numeric($value) ? $value : serialize($value); + return is_numeric($value) && ! in_array($value, [INF, -INF]) && ! is_nan($value) ? $value : serialize($value); } /** diff --git a/tests/Integration/Cache/RedisStoreTest.php b/tests/Integration/Cache/RedisStoreTest.php new file mode 100644 index 000000000000..fd2995b7e737 --- /dev/null +++ b/tests/Integration/Cache/RedisStoreTest.php @@ -0,0 +1,51 @@ +setUpRedis(); + } + + protected function tearDown(): void + { + parent::tearDown(); + + $this->tearDownRedis(); + } + + public function testItCanStoreInfinite() + { + Cache::store('redis')->clear(); + + $result = Cache::store('redis')->put('foo', INF); + $this->assertTrue($result); + $this->assertSame(INF, Cache::store('redis')->get('foo')); + + $result = Cache::store('redis')->put('bar', -INF); + $this->assertTrue($result); + $this->assertSame(-INF, Cache::store('redis')->get('bar')); + } + + public function testItCanStoreNan() + { + Cache::store('redis')->clear(); + + $result = Cache::store('redis')->put('foo', NAN); + $this->assertTrue($result); + $this->assertNan(Cache::store('redis')->get('foo')); + } +}