title: How get all keys when using POJO as key for Spring Redis cache?
body: <p>I am using Spring Data Redis to do my caching and I'm caching with the keys as objects, not strings. How do I find all the keys in a cache this way?</p>
  
  <p>When I try to use the <code>StringRedisSerializer()</code> I get a class cast exception saying the object cannot be cast to a string.</p>
  
  <p>When I try the <code>Jackson2JsonRedisSerializer</code>, it throws the exception:</p>
  
  <blockquote>
    <p>Could not read JSON: Unexpected character ('¬' (code 172)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')</p>
  </blockquote>
  
  <p>How can I get all the keys?</p>
  
  <p>I'm caching via the <code>@Cacheable</code> annotation.</p>
  
  <pre><code>@EnableCaching
  public class RedisCacheConfig
  {
      public static final String REDIS_CACHE_MGR = "RedisCacheManager";
  
      @Value( "${spring.redis.cluster}" )
      private List&lt;String&gt; cluster;
  
      @Bean
      public JedisConnectionFactory redisConnectionFactory()
      {
          JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory(
              new RedisClusterConfiguration( cluster )
          );
  
          return redisConnectionFactory;
      }
  
      @Bean
      public RedisTemplate&lt;String, String&gt; redisTemplate(RedisConnectionFactory cf)
      {
  
          RedisTemplate&lt;String, String&gt; redisTemplate = new RedisTemplate&lt;&gt;();
          redisTemplate.setConnectionFactory( cf );
          return redisTemplate;
      }
  
      @Bean
      public CacheManager redisCacheManager(RedisTemplate redisTemplate) throws EagleCacheException
      {
          RedisCacheManager cacheManager = new RedisCacheManager( redisTemplate );
  
          cacheManager.setDefaultExpiration( 3600 );
  
          return cacheManager;
      }
  }
  </code></pre>