This gem uses Redis to keep a list of recent text messages. ForeverAlone calculates hex digests of message and stores them into the Redis with a given expiration period.
Add this line to your application's Gemfile:
gem 'forever-alone'
And then execute:
$ bundle
Or install it yourself as:
$ gem install forever-alone
# init ForeverAlone with default timeout(30 minutes)
forever_alone = ForeverAlone.new("some message")
# or with custom timeout
forever_alone = ForeverAlone.new("some message", 5.minutes)
# check if given message is unique
forever_alone.unique?
# remember this message
forever_alone.remember
# OR just ensure that message is unique and raise ForeverAlone::MessageIsNotUnique error otherwise
forever_alone.ensure
# if you want to flush all locks
forever_alone.flush_locks
Here is ForeverAlone default configuration:
ForeverAlone.configure do |config|
config.digest = Digest::MD5 # you can switch to Digest::SHA1
config.timeout = 1_800 # default expiration period
config.namespace = :locks # prefix to Redis keys "locks:df49b60423903e095b80d9b4a92eb065"
end
You can configure redis connection with REDIS_URL
environment variable.
You can add fakeredis to your Gemfile to prevent ForeverAlone from making requests to your Redis server.
gem "fakeredis", require: "fakeredis/rspec", group: :test
- Fork it ( https://github.com/[my-github-username]/forever-alone/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request