简体   繁体   English

重新启动后在Redis(或其他缓存服务)中重新加载数据的最佳方法?

[英]Best way to reload data in Redis (or other cache service) upon restart?

When the Redis server fails and restarts, what's the best way to reload data into Redis? 当Redis服务器发生故障并重新启动时,将数据重新加载到Redis的最佳方法是什么? (I'm a bit new to Redis and in-memory databases) (我对Redis和内存数据库有点陌生)

I have three parts, I'll describe them as follows: 我分为三个部分,分别描述如下:

  • Producer app - Updates a SQL database and also writes a subset of the SQL data into a Redis server 生产者应用-更新SQL数据库,并将SQL数据的子集写入Redis服务器
  • Redis server - Has an important subset of the SQL data Redis服务器-具有重要的SQL数据子集
  • Consumer app - Needs to look up data in Redis at a fast rate (currently doesn't write to Redis or the SQL database) 消费者应用程序-需要快速在Redis中查找数据(当前不写入Redis或SQL数据库)

Some options I'm considering: 我正在考虑的一些选择:

  • Put reload script in Redis server so it'll query the SQL database and reload itself upon startup 将重装脚本放入Redis服务器中,以便它查询SQL数据库并在启动时重装自身
  • Build an endpoint in the Producer app that the Consumer app can call to tell the Producer app to reload Redis when the Consumer app notices that the Redis server is empty and has restarted 当消费者应用程序注意到Redis服务器为空并已重新启动时,在生产者应用程序中构建一个端点,供消费者应用程序调用以告诉生产者应用程序重新加载Redis。
  • Get rid of the Producer app completely and have the Consumer app directly query the SQL database and write the results in Redis (but then how will it know when the SQL data has been updated?) 完全摆脱Producer应用程序,并让Consumer应用程序直接查询SQL数据库并将结果写入Redis(但是如何知道何时更新SQL数据?)
  • Keep the Producer app, but also have the Consumer app directly query the SQL database and write the results in Redis when the Consumer app senses Redis to be empty 保留Producer应用程序,但也让Consumer应用程序直接查询SQL数据库,并在Consumer应用程序感觉到Redis为空时将结果写入Redis。

Reloading data into Redis or any other cache is called cache-warming. 将数据重新加载到Redis或任何其他缓存中被称为缓存预热。 The problem you seem to have is that you're not trying to use Redis as a cache but as a means to communicate between the apps. 您似乎遇到的问题是,您不是要使用Redis作为缓存,而是要在应用之间进行通信。

Normally you would want your application to query Redis to see if there's data in there and if not query the endpoint or database so you should always have some kind of means to go without Redis. 通常,您希望您的应用程序查询Redis,以查看其中是否有数据,如果不查询端点或数据库,则应该始终采用某种方式来避免Redis。

Whether you have the producer purge the consumer's cache or have consumer mind it's own cache and deal with stale data or introduce another application just for serving the data would depends on your exact needs. 是让生产者清除消费者的缓存,还是让消费者注意它自己的缓存并处理陈旧数据,或者引入另一个仅用于服务数据的应用程序,这取决于您的确切需求。

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

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