class Cassandra::Batch

Public Class Methods

new(cassandra, options) click to toggle source
   # File lib/cassandra/batch.rb
 5 def initialize(cassandra, options) 
 6   @queue_size = options.delete(:queue_size) || 0
 7   @cassandra = cassandra
 8   @options = options
 9   @batch_queue = []
10 end

Public Instance Methods

<<(mutation) click to toggle source

Append mutation to the batch queue Flush the batch queue if full

   # File lib/cassandra/batch.rb
16 def <<(mutation)
17   @batch_queue << mutation
18   if @queue_size > 0 and @batch_queue.length >= @queue_size
19     begin
20       @cassandra.flush_batch(@options)
21     ensure
22       @batch_queue = []
23     end
24   end
25 end
each(&block) click to toggle source

Implement each method (required by Enumerable)

   # File lib/cassandra/batch.rb
30 def each(&block)
31   @batch_queue.each(&block)
32 end
length() click to toggle source

Queue size

   # File lib/cassandra/batch.rb
37 def length
38   @batch_queue.length
39 end