Project

barrage

0.01
Low commit activity in last 3 years
No release in over a year
Distributed id generator
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Barrage

Gem Version Dependency Status Coverage Status Build Status Code Climate

Distributed ID generator(like twitter/snowflake)

Installation

Add this line to your application's Gemfile:

gem 'barrage'

And then execute:

$ bundle

Or install it yourself as:

$ gem install barrage

Usage

Example

# 39bit: msec (17.4 years from start_at)
# 16bit: worker_id
# 9bit:  sequence
require 'barrage'

barrage = Barrage.new(
  "generators" => [
    {"name" => "msec", "length" => 39, "start_at" => 1396278000000},
    {"name" => "redis_worker_id", "length" => 16, "ttl" => 300},
    {"name" => "sequence", "length" => 9}
  ]
)
barrage.next
# => Generated 64bit ID

Generators

msec

redis_worker_id

requirement: redis 2.6+

sequence

Creating your own generator

module Barrage::Generators
  class YourOwnGenerator < Base
    self.required_options += %w(your_option_value)
    def generate
      # generated code
    end

    def your_option_value
      options["your_option_value"]
    end
  end
end

barrage = Barrage.new("generators" => [{"name"=>"your_own", "length" => 8, "your_option_value"=>"xxx"}])

Contributing

  1. Fork it ( https://github.com/drecom/barrage/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