![](/img/trans.png)
[英]Do we need thread safety when Cache is accessed from multiple processes (Redis)
[英]Do we need to reload the cache when the redis server is reconnection
我是 Redis 緩存的新手,我們在我的節點 API 應用程序中使用這個緩存。 在此應用程序啟動時,我們正在緩存中設置值。 當 Redis 服務器重新啟動時,我們是否需要重新加載這些值? 請幫助解決這個問題。
提前致謝
Redis有一個配置選項,將數據庫的內容寫入磁盤,重啟時將數據從磁盤加載到數據庫中。 此選項的詳細信息在此處的文檔中: https://redis.io/topics/persistence
如果您需要一些數據始終存在於 Redis 中,那么您需要在上面實現持久性,或者在您的應用程序中執行以下操作:
# when retrieving something from Redis cache
if (item_is_in_cache('my_key') { #inexpensive operation
retrieve_item_from_cache('my_key'); #inexpensive operation
} else {
store_important_data_in_cache(); #expensive operation
}
這個偽代碼所做的是首先檢查所需的數據是否在緩存中,如果是則檢索它。 從 Redis 緩存檢查和檢索數據是一項成本低廉的操作,這意味着所需的資源很少。 如果數據不在緩存中(即最近啟動的Redis服務器),我們必須將重要數據放入緩存中。 根據所需的數據量,這可能是一項昂貴的操作(使用的資源比檢查/檢索數據更多)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.