Skip to content

Commit

Permalink
[6.x] Fix infinite value for RedisStore (#31348)
Browse files Browse the repository at this point in the history
* Fix infinite value for RedisStore

* Let Redis store NAN values
  • Loading branch information
driesvints authored Feb 4, 2020
1 parent 8a02955 commit fbf6f6c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
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'));
}
}

0 comments on commit fbf6f6c

Please sign in to comment.