Redis中key過期回調


redis中key的六大淘汰機制

noeviction:當內存使用達到閾值的時候,執行命令直接報錯

allkeys-lru:在所有的key中,優先移除最近未使用的key(推薦)

volatile-lru:在設置了過期時間的鍵空間中,優先移除最近未使用的key

allkeys-random:在所有的key中,隨機移除某個key

volatile-random:在設置了過期時間的鍵空間中,隨機移除某個key

 

volatile-ttl:在設置了過期時間的鍵空間中,具有更早過期時間的key優先移除。

redis.conf中配置maxmemory <bytes> 比如:maxmemory 300mb開始執行淘汰

redis.conf中配置maxmemory-policy  比如:maxmemory-policy volatile-lru

 

key失效后回調配置

redis.conf中配置notify-keyspace-events "Ex"

@Configuration
public class RedisListenerConfig {
    @Bean
    RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        return container;
    }
}

 

noeviction:當內存使用達到閾值的時候,執行命令直接報錯

allkeys-lru:在所有的key中,優先移除最近未使用的key(推薦)

volatile-lru:在設置了過期時間的鍵空間中,優先移除最近未使用的key

allkeys-random:在所有的key中,隨機移除某個key

volatile-random:在設置了過期時間的鍵空間中,隨機移除某個key

volatile-ttl:在設置了過期時間的鍵空間中,具有更早過期時間的key優先移除。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM