Sha256: d12681a37319c94179f305f7e2443990a0b7502d094b4e7b12fef147fef004f1
Contents?: true
Size: 813 Bytes
Versions: 2
Compression:
Stored size: 813 Bytes
Contents
require 'couchbase_doc_store' module CouchbaseStructures class Queue include CouchbaseDocStore def initialize(key) @key = key @head_index_key = "#{key}::queue::head" @tail_index_key = "#{key}::queue::tail" self end def enqueue(value) new_tail_index = increase_atomic_count(@tail_index_key) create_document("#{key}::queue::#{new_tail_index}", value) self end def pop() head_index = get_document(@head_index_key) tail_index = get_document(@tail_index_key) if tail_index > head_index increase_atomic_count(@head_index_key) get_document("#{key}::queue::#{head_index}") else nil end end def size() get_document(@tail_index_key) - get_document(@head_index_key) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
couchbase-structures-0.0.4 | lib/couchbase_structures/queue.rb |
couchbase-structures-0.0.2 | lib/couchbase_structures/queue.rb |