本文介绍了锁定和Redis的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有75台(并且正在不断增加)服务器需要通过Redis共享数据.理想情况下,所有75台服务器都希望通过INCRBYFLOAT操作写入Redis中的两个字段.我们预计最终在这两个字段上可能每天进行数百万次写入操作,每天进行数十亿次读取操作.此数据必须是持久性的.

We have 75 (and growing) servers that need to share data via Redis. All 75 servers would ideally want to write to two fields in Redis with INCRBYFLOAT operations. We anticipate eventually having potentially millions of daily write operations and billions of daily reads on these two fields. This data must be persistent.

我们担心,Redis锁定可能会导致多次重试写入操作,而同时尝试增加同一字段的次数.

We're concerned that Redis locking might cause write operations to be repeatedly retried with many simultaneous attempts to increment the same field.

问题:

  • 在一个很重的负载下,单个字段上同时出现多个INCRBYFLOAT是个坏主意吗?
  • 我们是否应该有一个外部过程来汇总"单独的字段并改为编写两个字段? (这引入了另一个故障点)
  • 写入时会在这两个字段上读取吗?
  • Is multiple, simultaneous INCRBYFLOAT on a single field a bad idea under a very heavy load?
  • Should we have an external process "summarize" separate fields and write the two fields instead? (this introduces another failure point)
  • Will reads on those two fields block while writing?

推荐答案

Redis不锁定.同样,它是单线程的;因此没有比赛条件.读或写不会阻塞.

Redis does not lock. Also, it is single threaded; so there are no race conditions. Reads or Writes do not block.

您可以在同一键上运行数百万个INCRBYFLOAT,而不会出现任何问题.无需外部流程.读取这些字段不会造成任何问题.

You can run millions of INCRBYFLOAT on the same key without any problems. No need for external processes. Reading those fields does not pose any problems.

说,对两个键进行数百万次更新"听起来很奇怪.如果您可以解释用例,也许在Redis中可能有更好的方法来处理它.

That said, "Millions of updates to two keys" sounds strange. If you can explain your use case, perhaps there might be a better way to handle it within Redis.

这篇关于锁定和Redis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 04:18