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