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>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章