简体   繁体   English

redis服务器重连时是否需要重新加载缓存

[英]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.我是 Redis 缓存的新手,我们在我的节点 API 应用程序中使用这个缓存。 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?当 Redis 服务器重新启动时,我们是否需要重新加载这些值? 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. Redis有一个配置选项,将数据库的内容写入磁盘,重启时将数据从磁盘加载到数据库中。 The details on this option are in the docs here: https://redis.io/topics/persistence此选项的详细信息在此处的文档中: 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:如果您需要一些数据始终存在于 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
}

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.从 Redis 缓存检查和检索数据是一项成本低廉的操作,这意味着所需的资源很少。 If the data isn't in the cache (ie, the Redis server recently started), we have to put the important data in the cache.如果数据不在缓存中(即最近启动的Redis服务器),我们必须将重要数据放入缓存中。 This can be an expensive operation (more resources used than checking/retrieving data) depending on the amount of data required.根据所需的数据量,这可能是一项昂贵的操作(使用的资源比检查/检索数据更多)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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