0.0
No commit activity in last 3 years
No release in over 3 years
A locking mechanism. Builds queue of concurrent code blocks using Redis.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0

Runtime

>= 1.2.8
>= 3.0.3
 Project Readme

redis-locker

A super-FAST and super-ROBUST LOCKING mechanism. Resolves race conditions. Builds queue of concurrent code blocks using Redis. Minimizes the number of redis requests to the least possible amount.

If Redis fails at some point (cleared, filled with wrong data, stuck) it will be trying to stay alive anyway. This is supported by additional key-control.

Installing

$ gem install redis-locker

Or put in your gemfile for latest version:

gem 'redis-locker', git: 'git://github.com/einzige/redis-locker.git'

Setting up

# Specify redis instance
# (if you are using rails put this into: config/initializers/redis_locker.rb
RedisLocker.redis = Redis.new({host: '127.0.0.1', port: 6379})

# Optionally specify the logger level (default is WARN)
RedisLocker.logger.level = Logger::WARN

# Or disable logging
RedisLocker.logger = Logger.new(nil)

Using

# Throws an error if transaction will not be finished in 10 seconds
RedisLocker.new('payment_transaction').run!(10.seconds) do
  # Any concurrent code.
end

# Throws an error if transaction will not be finished in 10 seconds
# Clears all stale tasks which were not performed within 10 seconds
RedisLocker.new('payment_transaction', 10.seconds).run! do
  # Any concurrent code.
end

# Does not throw any error, but clears all stale tasks which were not performed within 10 seconds
RedisLocker.new('payment_transaction', 10.seconds).run do
  # Any concurrent code.
end

Running specs

  • Clone the repo
  • run bundle exec rake spec

Contributing to redis-locker

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright (c) 2013 Sergei Zinin. No LICENSE for details :)