Permalink
Browse files

fixed a bug in core.py for softget, new stuff on restmq.rb

  • Loading branch information...
1 parent f227340 commit 769f53fd2d69d017e7784c210e6e95280e44ae5f @gleicon committed Aug 14, 2010
Showing with 21 additions and 5 deletions.
  1. +1 −0 .gitignore
  2. +1 −1 restmq/core.py
  3. +19 −4 ruby/restmq.rb
View
@@ -1,3 +1,4 @@
*.pyc
*.swp
*~
+node/redis-node-client/*
View
@@ -132,7 +132,7 @@ def queue_get(self, queue, softget=False):
if softget == False:
okey = yield self.redis.pop(lkey)
else:
- okey = yield self.redis.lindex(lkey, "0")
+ okey = yield self.redis.lindex(lkey, "-1")
if okey == None:
defer.returnValue((None, None))
View
@@ -5,21 +5,36 @@
require 'rubygems'
require 'sinatra'
require 'redis'
+require 'json'
QUEUESET = 'QUEUESET' # queue index
UUID_SUFFIX = ':UUID' # queue unique id
QUEUE_SUFFIX = ':queue' # suffix to identify each queue's LIST
reds = Redis.new
+get '/q' do
+ b = reds.smembers QUEUESET
+ throw :halt, [404, 'Not found (empty queueset)'] if b == nil
+ b.map! do |q| q = '/q/'+q end
+ b.to_json
+end
+
get '/q/*' do
queue = params['splat'].to_s
- throw :halt, [404, 'Not found\n'] if queue == nil
+ soft = params['soft'] # soft = true doesn't rpop values
+ throw :halt, [404, 'Not found'] if queue == nil
queue = queue + QUEUE_SUFFIX
- b = reds.rpop queue
- throw :halt, [404, 'Not found (empty queue)\n'] if b == nil
+ if soft != nil
+ puts queue
+ b = reds.lindex queue, -1
+ else
+ b = reds.rpop queue
+ end
+ throw :halt, [404, 'Not found (empty queue)'] if b == nil
v = reds.get b
- "{'value':" + v + "'key':" + b + "}"
+ throw :halt, [200, "{'value':" + v + "'key':" + b + "}"] unless v == nil
+ 'empty value'
end
post '/q/*' do

0 comments on commit 769f53f

Please sign in to comment.