Distributed ID generator(like twitter/snowflake)
Add this line to your application's Gemfile:
gem 'barrage'
And then execute:
$ bundle
Or install it yourself as:
$ gem install barrage
# 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
requirement: redis 2.6+
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"}])
- Fork it ( https://github.com/drecom/barrage/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