gpt4 book ai didi

java - Redisson getLock()对于分布式锁使用是否安全?

转载 作者:行者123 更新时间:2023-12-03 06:42:39 25 4
gpt4 key购买 nike

Redisson的 getLock() 方法是否适合分布式用例,它与 getRedLock() 相比如何?

Redisson(3.11.x)有几种实例化锁的方法:

  • RedissonClient.getLock()
  • RedissonClient.getRedLock()
  • 其他像 getReadWriteLock() getFairLock() 等。

  • getLock()使用哪种算法,并且对分布式使用安全吗? documentation说:

    Implements a non-fair locking so doesn't guarantees an acquire order by threads.



    我想将 getLock()getRedLock()进行比较,后者似乎使用Redlock,并在Redis的 distlock页面的顶层进行了记录: https://redis.io/topics/distlock:

    This page is an attempt to provide a more canonical algorithm to implement distributed locks with Redis. We propose an algorithm, called Redlock, which implements a DLM which we believe to be safer than the vanilla single instance approach.

    最佳答案

    Is Redisson's getLock() method good for a distributed use case, and how does it compare to getRedLock()?



    所有Redisson锁都适合分布式用例。 RedLock算法假定您在群集中的每个主节点上都有锁。 RedLock算法只是一个命题,不幸的是,它的实践用法没有反馈。除了analisys https://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html

    What algorithm does getLock() use, and is it safe for distributed usage?


    RLock对象作为单个对象存储在Redis中。如果释放了锁,则通过pubsub侦听器通知其他线程。还有lockWatchdogTimeout设置,该设置允许定义时间,如果当前线程不 Activity ,将在该时间后强制释放锁。

    更新
    从3.12.5版本开始,getLock()方法在故障转移期间以提高的可靠性返回Lock。 getRedLock()已被弃用。

    关于java - Redisson getLock()对于分布式锁使用是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60573175/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com