FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #4245 from lucasmichot/redis-setex · JavaDevl/framework@dbad947 · GitHub

Commit dbad947

Browse files
committed
Merge pull request laravel#4245 from lucasmichot/redis-setex
Redis : use setex instead of set and expires
2 parents ff579f4 + 76008e3 commit dbad947

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

‎src/Illuminate/Cache/RedisStore.php‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ public function put($key, $value, $minutes)
6666
{
6767
$value = is_numeric($value) ? $value : serialize($value);
6868

69-
$this->connection()->set($this->prefix.$key, $value);
70-
71-
$this->connection()->expire($this->prefix.$key, $minutes * 60);
69+
$this->connection()->setex($this->prefix.$key, $minutes * 60, $value);
7270
}
7371

7472
/**

‎tests/Cache/CacheRedisStoreTest.php‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,17 @@ public function testRedisValueIsReturnedForNumerics()
4040
public function testSetMethodProperlyCallsRedis()
4141
{
4242
$redis = $this->getRedis();
43-
$redis->getRedis()->shouldReceive('connection')->twice()->with('default')->andReturn($redis->getRedis());
44-
$redis->getRedis()->shouldReceive('set')->once()->with('prefix:foo', serialize('foo'));
45-
$redis->getRedis()->shouldReceive('expire')->once()->with('prefix:foo', 60 * 60);
43+
$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
44+
$redis->getRedis()->shouldReceive('setex')->once()->with('prefix:foo', 60 * 60, serialize('foo'));
4645
$redis->put('foo', 'foo', 60);
4746
}
4847

4948

5049
public function testSetMethodProperlyCallsRedisForNumerics()
5150
{
5251
$redis = $this->getRedis();
53-
$redis->getRedis()->shouldReceive('connection')->twice()->with('default')->andReturn($redis->getRedis());
54-
$redis->getRedis()->shouldReceive('set')->once()->with('prefix:foo', 1);
55-
$redis->getRedis()->shouldReceive('expire')->once()->with('prefix:foo', 60 * 60);
52+
$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
53+
$redis->getRedis()->shouldReceive('setex')->once()->with('prefix:foo', 60 * 60, 1);
5654
$redis->put('foo', 1, 60);
5755
}
5856

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL