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

问题描述

所以我只读了有关redlock的内容。据我了解,它需要3台独立的机器才能工作。独立表示它们是指所有机器都是主机,并且它们之间没有复制,这意味着它们正在提供不同类型的数据。那么,为什么我需要锁定在充当主服务器的三个独立Redis实例中存在的密钥?我需要使用redlock的用例是什么?

So I just read about redlock. What I understood is that it needs 3 independent machines to work. By independent they mean that all the machines are masters and there is no replication amongst them, which means they are serving different types of data. So why would I need to lock a key present in three independent redis instances acting as masters ? What are the use cases where I would need to use redlock ?

推荐答案

这并不是说您要在Redis中锁定密钥。相反,键锁,用于控制对其他资源的访问。其他资源可能是任何东西,并且通常是Redis之外的东西,因为Redis具有允许原子访问其数据结构的自身机制。

It's not that you're locking a key within Redis. Rather, the key is the lock, and used to control access to some other resource. That other resource could be anything, and generally is something outside of Redis since Redis has its own mechanisms for allowing atomic access to its data structures.

当只需要一个成员时,您将使用分布式锁。

You would use a distributed lock when you want only one member at a time of a distributed system to do something.

要从互联网上随机抽取一个例子,请在谈论他们使用分布式锁来确保多个进程不会同时生成并向网络广播单独的事务

To take a random example from the internet, here's Coinbase talking about their use of a distributed lock to "ensure that multiple processes do not concurrently generate and broadcast separate transactions to the network".

这篇关于Redis分布式锁解决什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 03:33