5

Using org.springframework.data.redis.core.RedisTemplate for storing data in redis server. I have the keys in pattern similar to "abc@xyz@pqr". Wanted to get all the keys which have the starting letters as "abc", and was using RedisTemplate.keys(String pattern) method for the same as Below:

Set<String> redisKeys = redisTemplate.keys("(abc).*");

for (String key : redisKeys) {
    System.out.println(key);
}

But its always giving me empty set.

// tried this pattern also 
Set<String> redisKeys = redisTemplate.keys("abc*");

Please help me out.

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
Virat Mishra
  • 155
  • 1
  • 2
  • 9

1 Answers1

9

Make sure to use StringRedisSerializer to serialize keys. Spring Data Redis defaults to JdkSerializationRedisSerializer which does not allow glob-style search because of the way it works.

Check out the reference documentation for more details.

mp911de
  • 17,546
  • 2
  • 55
  • 95