简体   繁体   中英

Do we need to reload the cache when the redis server is reconnection

I am new to Redis cache and this cache we are using in my node API application. On the start-up of this application, we are setting the values in the cache. Do we need to reload the values when the Redis server is restarting? Please help on this.

Thanks in advance

Redis has a configuration option that writes the content of the database to disk, and when it restarts, load the data from disk into the database. The details on this option are in the docs here: https://redis.io/topics/persistence

If you need some data to always be present in Redis, then you'll either need to implement persistence above, or do something like this in your app:

# 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
}

What this pseudo-code does is first check that the required data is in the cache, and retrieve it if it is. Checking and retrieving data from a Redis cache is an inexpensive operation, meaning the resources required are low. If the data isn't in the cache (ie, the Redis server recently started), we have to put the important data in the cache. This can be an expensive operation (more resources used than checking/retrieving data) depending on the amount of data required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM