0.0
No commit activity in last 3 years
No release in over 3 years
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.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 0.5.0
>= 3.2.0, ~> 3.2

Runtime

> 3.0, ~> 3.0
 Project Readme

ForeverAlone

forever alone

Build Status

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.

Installation

Add this line to your application's Gemfile:

gem 'forever-alone'

And then execute:

$ bundle

Or install it yourself as:

$ gem install forever-alone

Usage

  # 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

Configuration

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.

Testing

You can add fakeredis to your Gemfile to prevent ForeverAlone from making requests to your Redis server.

gem "fakeredis", require: "fakeredis/rspec", group: :test

Contributing

  1. Fork it ( https://github.com/[my-github-username]/forever-alone/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request