spring中redistemplate不能用通配符keys查出相应Key的问题


有个业务中需要删除某个前缀的所有Redis缓存,于是用RedisTemplate的keys方法先查出所有合适的key,再遍历删除。但是在keys(patten+"*")时每次取出的都为空。

解决问题:

spring中redis配置中,引入StringRedisTemplate而不是RedisTemplate,StringRedisTemplate本身继承自RedisTemplate,

<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="connectionFactory" />
</bean>

改为

<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
<property name="connectionFactory" ref="connectionFactory" />
</bean>

 

from : https://blog.csdn.net/bigtree_3721/article/details/55211934


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM