summaryrefslogtreecommitdiff
path: root/queue/zset/run.rb
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2015-12-18 15:59:03 +0200
committerSteve Kemp <steve@steve.org.uk>2015-12-18 15:59:03 +0200
commit2db7fba4d74b663da16625a990f7b7624842712a (patch)
tree0de4b3f3c3139cccfa36342a5e697b14a32f4e2d /queue/zset/run.rb
parent43d6c5affc78755f8a45b242d8d39acc72bd3526 (diff)
Added queue-demonstration programs.
Diffstat (limited to 'queue/zset/run.rb')
-rwxr-xr-xqueue/zset/run.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/queue/zset/run.rb b/queue/zset/run.rb
new file mode 100755
index 0000000..726e19a
--- /dev/null
+++ b/queue/zset/run.rb
@@ -0,0 +1,38 @@
+#!/usr/bin/ruby
+
+require "redis"
+require 'pp'
+@redis = Redis.new(:host => "127.0.0.1")
+
+
+
+def fetch(timeout = 1)
+ job = nil
+
+ loop do
+ job = @redis.ZREVRANGE('zset', '0', '0')
+
+ if !job.empty?
+ # We only have one entry in our array
+ job = job[0]
+
+ # Remove from the queue
+ @redis.zrem('zset', job );
+
+ return job
+ else
+ sleep(timeout)
+ end
+
+ end
+end
+
+
+
+while( x = fetch() )
+ puts "Got job : #{x}"
+ if ( x =~ /ping/i )
+ puts "PING TEST - sleeping"
+ sleep 5
+ end
+end