Skip to content

Commit

Permalink
Return query size
Browse files Browse the repository at this point in the history
This is an utility method. It isn't hard to realize that
`query.key.llen` will return the current size of the queue, but this
makes it even easier.
  • Loading branch information
inkel committed Feb 19, 2014
1 parent 657f577 commit bdf38a6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/ost.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def items
alias << push alias << push
alias pop each alias pop each


def size
key.llen
end

def redis def redis
@redis ||= Redis.connect(Ost.options) @redis ||= Redis.connect(Ost.options)
end end
Expand Down
22 changes: 22 additions & 0 deletions test/ost_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -135,4 +135,26 @@ def enqueue(id)


assert_equal queue.key.redis, queue.redis assert_equal queue.key.redis, queue.redis
end end

test "report the queue size" do
queue = Ost[:size]

assert_equal 0, queue.size

queue << 1

assert_equal 1, queue.size

done = false

Thread.new do
Ost[:size].each do |item|
done = true
end
end

until done; end

assert_equal 0, queue.size
end
end end

0 comments on commit bdf38a6

Please sign in to comment.