title: (Redis, Springboot) Although TTL remains but expired event is generated
body: <p>I have been developing some program with Spring and Redis but I am in stuck :(</p>
  <h2>What I want</h2>
  <ul>
  <li>when http request comes to server, then <code>setex</code> myKey, value and ttl.</li>
  <li>when myKey is expired, then expired event comes to server and I will make a log.</li>
  </ul>
  <h2>Source code</h2>
  <pre><code>@Configuration
  public class RedisListenerContainerConfig {
    @Bean(&quot;redisMyListenerContainer&quot;)
    public RedisMessageListenerContainer redisLPRInOutCarExpiryListenerContainer(
        RedisConnectionFactory redisConnectionFactory,
        RedisLPRInOutCarExpiryListener redisLPRInOutCarExpiryListener) {
      redisConnectionFactory.getConnection().setConfig(&quot;notify-keyspace-events&quot;, &quot;Kx&quot;);
  
      RedisMessageListenerContainer container = new RedisMessageListenerContainer();
      container.setConnectionFactory(redisConnectionFactory);
      container.addMessageListener(myListener, new PatternTopic(&quot;__keyspace@0__:myKey*&quot;));
      container.setErrorHandler(e -&gt; log.error(&quot;error&quot;));
  
      return container;
    }
  }
  
  // here expired event will be got
  @Component
  public class MyListener implements MessageListener {
    @Override
    public void onMessage(Message message, byte[] pattern) {
      // to make log
    }
  }
  
  @Service 
  public class MyService {
    ...
    // here setex is generated
    private void setExMyKey(String myKey) {
      String value = &quot;value&quot;;
  
      redisTemplate.opsForValue().set(myKey, value, 60 * 10 ,TimeUnit.SECONDS);
      final String listKey = &quot;list_&quot; + myKey;
      if (redisTemplate.opsForList().size(listKey) &lt; 1) {
        redisTemplate.opsForList().leftPush(listKey, value);
      }
    }
  }
  
  </code></pre>
  <h2>info of Redis</h2>
  <ul>
  <li>standalone</li>
  <li>keys: 610000</li>
  <li>expires: 600000</li>
  </ul>
  <h2>Problem</h2>
  <p>Actually, the http requests keep coming to the server so it supposes to the ttl of mykey will never be zero.</p>
  <p>But after taking a while, although ttl still remains, expired event is generated so many times.</p>
  <pre><code>127.0.0.1:6379&gt; ttl myKey_3378
  (integer) 1783
  </code></pre>
  <h2>the suspicious part</h2>
  <ul>
  <li>According to <a href="https://redis.io/docs/manual/keyspace-notifications/#events-generated-by-different-commands" rel="nofollow noreferrer">Redis documents</a>, I think, my function for <code>setex</code> does not change the value but only ttl.
  And that could mean myKey is not really modified.</li>
  </ul>
  <pre><code>IMPORTANT all the commands generate events only if the target key is really modified. 
  For instance an SREM deleting a non-existing element from a Set will not actually change the value of the key, so no event will be generated.
  </code></pre>
  <ul>
  <li>Is it possible to be a issue of <a href="https://redis.com/ebook/part-2-core-concepts/chapter-6-application-components-in-redis/6-2-distributed-locking/6-2-5-locks-with-timeouts/" rel="nofollow noreferrer">Redis lock</a>?</li>
  </ul>
  <hr />
  <p>My language is not English so I am sorry in advance not to understand very well.
  Hopefully I solve this problem soon.
  Thank you so much.</p>