Snc\RedisBundle\Session\Storage\Handler\RedisSessionHandler::setTtl PHP Method

setTtl() public method

Change the default TTL.
public setTtl ( integer $ttl )
$ttl integer
    public function setTtl($ttl)
    {
        $this->ttl = $ttl;
    }

Usage Example

 public function testWritingSessionDataWithExpiration()
 {
     $this->redis->expects($this->exactly(3))->method('setex')->with($this->equalTo('session:_symfony'), $this->equalTo(10), $this->equalTo('some data'));
     // Expiration is set by cookie_lifetime option
     $handler = new RedisSessionHandler($this->redis, array('cookie_lifetime' => 10), 'session', false);
     $handler->write('_symfony', 'some data');
     // Expiration is set with the TTL attribute
     $handler = new RedisSessionHandler($this->redis, array(), 'session', false);
     $handler->setTtl(10);
     $handler->write('_symfony', 'some data');
     // TTL attribute overrides cookie_lifetime option
     $handler = new RedisSessionHandler($this->redis, array('cookie_lifetime' => 20), 'session', false);
     $handler->setTtl(10);
     $handler->write('_symfony', 'some data');
 }