Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Return query size

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...
commit bdf38a65bb272c3d9279a83d190d5386df8ad3d5 1 parent 657f577
@inkel inkel authored
Showing with 26 additions and 0 deletions.
  1. +4 −0 lib/ost.rb
  2. +22 −0 test/ost_test.rb
View
4 lib/ost.rb
@@ -43,6 +43,10 @@ def items
alias << push
alias pop each
+ def size
+ key.llen
+ end
+
def redis
@redis ||= Redis.connect(Ost.options)
end
View
22 test/ost_test.rb
@@ -135,4 +135,26 @@ def enqueue(id)
assert_equal queue.key.redis, queue.redis
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
Please sign in to comment.
Something went wrong with that request. Please try again.