-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RedisStore improvement - don't open transaction unless all values are…
… serialaizable (#47193) * Create failing test case * copy files from martinssipenko:psr6-redis-failure * before inserting records serialize them * change test case * php style change * fix expectation * bump * Update RedisStore.php --------- Co-authored-by: Martins Sipenko <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
5dd3717
commit 9698de4
Showing
3 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Cache\Fixtures; | ||
|
||
use Exception; | ||
|
||
class Unserializable | ||
{ | ||
public function __sleep() | ||
{ | ||
throw new Exception('Not serializable'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Cache; | ||
|
||
use Illuminate\Foundation\Testing\Concerns\InteractsWithRedis; | ||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Tests\Integration\Cache\Fixtures\Unserializable; | ||
use Orchestra\Testbench\TestCase; | ||
|
||
class Psr6RedisTest extends TestCase | ||
{ | ||
use InteractsWithRedis; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->setUpRedis(); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
|
||
$this->tearDownRedis(); | ||
} | ||
|
||
/** | ||
* @dataProvider redisClientDataProvider | ||
*/ | ||
public function testTransactionIsNotOpenedWhenSerializationFails($redisClient): void | ||
{ | ||
$this->app['config']['cache.default'] = 'redis'; | ||
$this->app['config']['database.redis.client'] = $redisClient; | ||
|
||
$cache = $this->app->make('cache.psr6'); | ||
|
||
$item = $cache->getItem('foo'); | ||
|
||
$item->set(new Unserializable()); | ||
$item->expiresAfter(60); | ||
|
||
$cache->save($item); | ||
|
||
Cache::store('redis')->get('foo'); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public static function redisClientDataProvider(): array | ||
{ | ||
return [ | ||
['predis'], | ||
['phpredis'], | ||
]; | ||
} | ||
} |