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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With