Skip to content

Spalmalo/forever-alone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Check message for uniqueness in period of time

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages