Redis::DistLock - Distributed lock manager using Redis
use Redis::DistLock; my $rd = Redis::DistLock->new( servers => [qw[ localhost:6379 ]] ); my $mutex = $rd->lock( "foo", 10 ); die( "failed to get a lock" ) if ! $mutex; # ... critical section ... $rd->release( $mutex );
This is an implementation of the Redlock algorithm using Redis for distributed lock management.
NOTE: This needs at least Redis version 2.6.12 which adds new options to the SET command making this implementation possible.
SET
Array reference with servers to connect to or Redis objects to use.
Maximum number of times to try to acquire the lock. Defaults to 3.
3
Maximum delay between retries in seconds. Defaults to 0.2.
0.2
Flag to check redis server version(s) in the constructor to ensure compatibility. Defaults to 1.
1
Acquire the lock for the resource with the given time to live (in seconds) until the lock expires. Without a value will generate a unique identifier.
Release the previously acquired lock.
http://redis.io/topics/distlock
This code implements an algorithm which is currently a proposal, it was not formally analyzed. Make sure to understand how it works before using it in production environments.
This module was originally developed at Booking.com. With approval from Booking.com, this module was released as open source, for which the author would like to express his gratitude.
Simon Bertrang, <janus@cpan.org>
Copyright (C) 2014 by Simon Bertrang
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Redis::DistLock, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Redis::DistLock
CPAN shell
perl -MCPAN -e shell install Redis::DistLock
For more information on module installation, please visit the detailed CPAN module installation guide.