Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Fix infinite value for RedisStore #31348

Merged
merged 2 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
51 changes: 51 additions & 0 deletions tests/Integration/Cache/RedisStoreTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Illuminate\Tests\Integration\Cache;

use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis;
use Illuminate\Support\Facades\Cache;
use Illuminate\Tests\Integration\IntegrationTest;

/**
* @group integration
*/
class RedisStoreTest extends IntegrationTest
{
use InteractsWithRedis;

protected function setUp(): void
{
parent::setUp();

$this->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'));
}
}