redlock | Distributed locks with Redis and Python

 by   glasslion Python Version: Current License: MIT

kandi X-RAY | redlock Summary

kandi X-RAY | redlock Summary

null

Distributed locks with Redis and Python
Support
    Quality
      Security
        License
          Reuse

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of redlock
            Get all kandi verified functions for this library.

            redlock Key Features

            No Key Features are available at this moment for redlock.

            redlock Examples and Code Snippets

            Features
            mavendot img1Lines of Code : 34dot img1no licencesLicense : No License
            copy iconCopy
            // 1. Create config object
            Config config = new Config();
            config.useClusterServers()
                   // use "rediss://" for SSL connection
                  .addNodeAddress("redis://127.0.0.1:7181");
            
            // or read config from file
            config = Config.fromYAML(new File("config-f  

            Community Discussions

            QUESTION

            Super basic questions about using RedLockFactory.CreateLockAsync()
            Asked 2021-Oct-14 at 11:06

            The following pseudocode may be a little too boiled down, but this is more of a general question

            ...

            ANSWER

            Answered 2021-Oct-10 at 22:10

            I need to stop posting questions when burned out and frustrated late on Friday afternoon.

            I dug into the source and test code for RedlockFactory and all of the things I originally thought were not working at all appear to be working just fine, both to read the code and to use the debugger.

            My real panic came from the TransactionScope problem I mentioned in my edited original question and the problems there don't seem to have anything to do with how RedlockFactory or any other items implementing DisposeAsync work.

            Source https://stackoverflow.com/questions/69503134

            QUESTION

            How to choose the right value for the expiryTime parameter for RedLockFactory.CreateLockAsync() method?
            Asked 2021-Aug-20 at 22:34

            I am using RedLock.net library for resource locking. To lock a resoruce I am using RedLockFactory.CreateLockAsync.

            ...

            ANSWER

            Answered 2021-Aug-20 at 22:34

            ExpiryTime determines the maximum time that a lock will be held in the case of a failure (say, the process holding the lock crashing). It also indirectly determines how often the lock is renewed while it is being held.

            e.g.

            If you set an expiry time of 10 minutes:

            • the automatic lock renewal timer will call out to redis every 5 minutes (expiry time / 2) to extend the lock
            • if your process crashes without releasing the lock, you will have to wait up to a maximum of 10 minutes until the key expires in redis and another process can take out a lock on the same resource

            If you set an expiry time of 10 milliseconds:

            • the automatic lock renewal timer will call out to redis every 5 milliseconds (expiry time / 2) to extend the lock (which might be a little excessive)
            • if your process crashes without releasing the lock, you will have to wait up to a maximum of 10 milliseconds until the key expires in redis and another process can take out a lock on the same resource

            It's a balance between how much time you're willing to wait for a lock to expire in the failure case vs how much load you put on your redis servers.

            Source https://stackoverflow.com/questions/68855859

            QUESTION

            Mocking Redlock.CreateAsync does not return mocked object
            Asked 2021-Jun-07 at 21:55

            I am trying to Mock Redlock

            I have the test below

            ...

            ANSWER

            Answered 2021-Jun-07 at 21:55

            The definition of CreateLockAsync

            Source https://stackoverflow.com/questions/67870370

            QUESTION

            How to check if the function has executed completely and store completed flag in global variable in JavaScript
            Asked 2021-Mar-25 at 06:19

            When a user clicks on the Break button, it executes the Break() function inside the JS. It then calls getData() and also 2 lines of code after getData with CSS. But if you see that 2 CSS btnLock which use to hide lock.png and btnUnlock which displays unlock.png. it is not waiting for getData() to complete and these 2 CSS is getting overridden with what we have in buildTable(). So the option I am looking for is to build the datatable medTable.draw() first and then check if the Break() has completed. If so, then use these 2 CSS to hide and display.

            So for that, I want to use the global boolean variable to store the status of the Break function. I mean whether it completed or not so that I can use it after medTable.draw(); to check the Break function completed.

            Index

            ...

            ANSWER

            Answered 2021-Mar-25 at 06:19

            If you want to make sure

            Source https://stackoverflow.com/questions/66791642

            QUESTION

            redis terminate called after throwing an instance of 'sw::redis::MovedError'
            Asked 2020-Nov-24 at 09:17

            I try to build a redis cluster follow this cluster-tutorial

            I try to use this tutorial(RedLock) to write codeRed Lock

            Got the following error : terminate called after throwing an instance of 'sw::redis::MovedError'

            ...

            ANSWER

            Answered 2020-Nov-24 at 09:17

            Redlock does not work with Redis Cluster. Instead, it works with Single Redis instances. You should run your code with N dependent Redis instances, NOT a Redis Cluster.

            terminate called after throwing an instance of 'sw::redis::MovedError'

            Seems that you're using redis-plus-plus. You got this error, because you're trying to send commands to Redis Cluster with a Redis object.

            Source https://stackoverflow.com/questions/64982136

            QUESTION

            Distributed readers-writer lock in python
            Asked 2020-Apr-05 at 16:31

            I am looking for a readers-writer lock that can be used in python in a distributed system.

            So far I've found:

            1. redlock, which is based on redis. Does not provide a readers-writer lock.
            2. The distributed package of dask offers a lock, but again, no readers-writer lock.
            3. kazoo, which works with Zookeeper, offers a readers-writer lock. However Zookeeper is an extremely heavy dependency, as it written in Java and therefore requires the JDK.

            Is there a more lightweight alternative to kazoo / Zookeeper? Ideally a pure python solution that is nevertheless battle tested?

            ...

            ANSWER

            Answered 2020-Apr-05 at 16:31

            Redis is single-threaded and read/write operations are atomic; which means multiple simultaneous read/write operations will not succeed and readers and writer(s) will be obtaining access to the resource sequentially in atomic fashion. I believe this would solve your problem if the resource is kept in as one of the redis data structures. You do not need a separate reader-writer lock mechanism when using redis and python as combination where the resource is kept within redis.

            Hope it helps

            Source https://stackoverflow.com/questions/60821649

            QUESTION

            Is Redisson getLock() Safe for Distributed Lock Usage?
            Asked 2020-Apr-03 at 10:36

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

            Redisson (3.11.x) has several methods to instantiate locks:

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

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

            I am looking to compare getLock() to getRedLock(), which appears to use Redlock and is documented at the top-level of Redis' distlock page: 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.

            ...

            ANSWER

            Answered 2020-Apr-03 at 10:36

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

            All Redisson locks fit for distributed use case. RedLock algorithm assumes that you have lock per master node in cluster. RedLock algorithm is proposition and unfortunately there are no feedbacks of its practice usage. Except of its 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 object stored as single object in Redis. Other threads are notified through pubsub listeners if lock released. There is also lockWatchdogTimeout setting allows to define time after which lock will be forced to release if current thread is not alive.

            UPDATE Since 3.12.5 version getLock() method returns Lock with improved reliability during failover. getRedLock() has been deprecated.

            Source https://stackoverflow.com/questions/60573175

            QUESTION

            Lock on redis cluster
            Asked 2020-Mar-23 at 10:24

            I have a Redis cluster of 3 master nodes and each master has corresponding slave nodes. I would like to acquire a lock on the cluster to perform some write operations and then release the lock.

            From what I've read is - To connect to a cluster we generally connect to one node in the cluster and perform all operations on that node which in-turn handles re-directing to other nodes in the cluster.

            Is it possible to acquire lock on a Redis cluster? [P.S I am using Redisson client] From the examples in Redisson client under Multilock and redlock (https://github.com/redisson/redisson/wiki/8.-Distributed-locks-and-synchronizers), they are acquiring a lock on individual nodes.

            • How does Multi lock or Red lock work on a cluster?
            • How and what kind of lock do I use if I have a Redis cluster?
            • Which library (Jedis/Redisson) do I use?

            Jedis also seems to have support for locking on the cluster (https://github.com/kaidul/jedis-lock).

            P.S: I've read extensively on this, but I've not been able to find clear answers on locking on a cluster. Would really appreciate some help.

            ...

            ANSWER

            Answered 2020-Mar-23 at 10:24

            I found a solution to my question above.

            As far as we are using the same key to acquire a lock across all client nodes, all the attempts to acquire the lock will go to the same node on the Redis cluster. So you can just use simple Rlock from Redisson.

            See comments to this question: https://github.com/leandromoreira/redlock-rb/issues/63

            Source https://stackoverflow.com/questions/60771436

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install redlock

            No Installation instructions are available at this moment for redlock.Refer to component home page for details.

            Support

            For feature suggestions, bugs create an issue on GitHub
            If you have any questions vist the community on GitHub, Stack Overflow.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries