title: ZF2 Redis: how to set expiration time for a key
body: <p>I have to set up a Redis on a server to store information from Zend Framework 2.
  For now, I can store information, but I can not to give them an expiration time for they naturally renew themselves after a while.</p>
  
  <p>I have not found some documentations about this step and it seems to me rather obscure.</p>
  
  <p>My code:</p>
  
  <p>page: config/autoload/cache.global.php
      
  
  <pre><code>return array(
      'caches' =&gt; array(
          'redis' =&gt; array (
              'adapter' =&gt; array (
                  'name' =&gt; 'redis',
                  'lifetime' =&gt; 60, //doesn't work
                  'options' =&gt; array (
                      'server' =&gt; array (
                          'host' =&gt; 'x.x.x.x',
                          'port' =&gt; x
                      ),
                      'ttl' =&gt; 10, // seems to have no effect
                      'namespace' =&gt; 'mycache',
                  ),
              ),
          )
      )
  );
  </code></pre>
  
  <p>in Controller :</p>
  
  <pre><code>..
  use Zend\Cache\StorageFactory;
  ..
          $redis = StorageFactory::factory ($this-&gt;getServiceLocator ()
               -&gt;get ('config')['caches']['redis']);
  
          if ($redis-&gt;hasItem ('test')) {
                  var_dump($redis-&gt;getItem ('test'));
                  $redis-&gt;removeItem('test');
          } else {
              $redis-&gt;addItem('test', 'testtest');
          }
  ..
  </code></pre>
  
  <p>I tried several methods, but everytime, the result is the same, no expiration information appears in Redis :</p>
  
  <pre><code>127.0.0.1:6379&gt; get mycache:test
  "testtest"
  127.0.0.1:6379&gt; ttl mycache:test
  (integer) -1
  </code></pre>
  
  <p>Thanks for your help!</p>