Class: Cassandra::Batch
- Inherits:
-
Object
- Object
- Cassandra::Batch
- Includes:
- Enumerable
- Defined in:
- lib/cassandra/batch.rb
Instance Method Summary collapse
-
#<<(mutation) ⇒ Object
Append mutation to the batch queue Flush the batch queue if full.
-
#each(&block) ⇒ Object
Implement each method (required by Enumerable).
-
#initialize(cassandra, options) ⇒ Batch
constructor
A new instance of Batch.
-
#length ⇒ Object
Queue size.
Constructor Details
#initialize(cassandra, options) ⇒ Batch
5 6 7 8 9 10 |
# File 'lib/cassandra/batch.rb', line 5 def initialize(cassandra, ) @queue_size = .delete(:queue_size) || 0 @cassandra = cassandra = @batch_queue = [] end |
Instance Method Details
#<<(mutation) ⇒ Object
Append mutation to the batch queue Flush the batch queue if full
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cassandra/batch.rb', line 16 def <<(mutation) @batch_queue << mutation if @queue_size > 0 and @batch_queue.length >= @queue_size begin @cassandra.flush_batch() ensure @batch_queue = [] end end end |
#each(&block) ⇒ Object
Implement each method (required by Enumerable)
30 31 32 |
# File 'lib/cassandra/batch.rb', line 30 def each(&block) @batch_queue.each(&block) end |
#length ⇒ Object
Queue size
37 38 39 |
# File 'lib/cassandra/batch.rb', line 37 def length @batch_queue.length end |