Sha256: 892f0f82df8592ad4ed0cf9b1250159edde873a2057604f87eef8265d8cdc008
Contents?: true
Size: 788 Bytes
Versions: 15
Compression:
Stored size: 788 Bytes
Contents
class Cassandra class Batch include Enumerable def initialize(cassandra, options) @queue_size = options.delete(:queue_size) || 0 @cassandra = cassandra @options = options @batch_queue = [] end ## # Append mutation to the batch queue # Flush the batch queue if full # def <<(mutation) @batch_queue << mutation if @queue_size > 0 and @batch_queue.length >= @queue_size begin @cassandra.flush_batch(@options) ensure @batch_queue = [] end end end ## # Implement each method (required by Enumerable) # def each(&block) @batch_queue.each(&block) end ## # Queue size # def length @batch_queue.length end end end
Version data entries
15 entries across 15 versions & 3 rubygems