Class: ActiveRecord::Turntable::Sequencer::Katsubushi
- Inherits:
-
ActiveRecord::Turntable::Sequencer
- Object
- ActiveRecord::Turntable::Sequencer
- ActiveRecord::Turntable::Sequencer::Katsubushi
- Defined in:
- lib/active_record/turntable/sequencer/katsubushi.rb
Instance Method Summary collapse
- #current_sequence_value(sequence_name) ⇒ Object
-
#initialize(options = {}) ⇒ Katsubushi
constructor
A new instance of Katsubushi.
- #next_sequence_value ⇒ Object
Methods inherited from ActiveRecord::Turntable::Sequencer
class_for, #release!, #sequence_name, sequence_name
Constructor Details
#initialize(options = {}) ⇒ Katsubushi
Returns a new instance of Katsubushi.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/active_record/turntable/sequencer/katsubushi.rb', line 4 def initialize( = {}) @options = ["options"] opts = @options.dup servers = opts.delete("servers").map do |server| "#{server["host"]}:#{server["port"]}" end require "dalli" require "securerandom" dalli_opts = opts.with_indifferent_access @client = Dalli::Client.new(servers, dalli_opts) end |
Instance Method Details
#current_sequence_value(sequence_name) ⇒ Object
22 23 24 |
# File 'lib/active_record/turntable/sequencer/katsubushi.rb', line 22 def current_sequence_value(sequence_name) next_sequence_value(sequence_name) end |
#next_sequence_value ⇒ Object
18 19 20 |
# File 'lib/active_record/turntable/sequencer/katsubushi.rb', line 18 def next_sequence_value(*) @client.get(SecureRandom.hex(4)).to_i end |