title: Jedis key expiry
body: <p>I am trying to understand redis/jedis with spring. I am stuck somewhere where I can't able to expiry my key after certain period of time. </p>
  
  <p>Can anyone please help ? </p>
  
  <pre><code>public class SessionCacheRepositoryImpl implements SessionCacheRepository {
  
      private static final String KEY = "Session";
  
      private RedisTemplate&lt;String, Object&gt; redisTemplate;
      private HashOperations hashOperations;
  
      @Autowired
      public SessionCacheRepositoryImpl(RedisTemplate&lt;String, Object&gt; redisTemplate) {
          this.redisTemplate = redisTemplate;
      }
  
      @PostConstruct
      private void init() {
          hashOperations = redisTemplate.opsForHash();
          redisTemplate.expire(KEY, 30, TimeUnit.SECONDS);
      }
  
      public void saveSession(final Session session) {
          hashOperations.put(KEY, session.getSessionID(), session);
      }
  }
  </code></pre>
  
  <p>And this is my config class</p>
  
  <pre><code>private RedisTemplate&lt;String, Object&gt; template;
  
  @Bean
  JedisConnectionFactory jedisConnectionFactory() {
      JedisConnectionFactory jedisConFactory = new JedisConnectionFactory();
      jedisConFactory.setHostName("localhost");
      jedisConFactory.setPort(36919);
      return jedisConFactory;
  }
  
  @Bean
  public RedisTemplate&lt;String, Object&gt; redisTemplate() {
      template = new RedisTemplate&lt;String, Object&gt;();
      template.setConnectionFactory(jedisConnectionFactory());
      template.setValueSerializer(new GenericToStringSerializer&lt;Object&gt;(Object.class));
      return template;
  }
  </code></pre>