Skip to content
Browse files

added support for expiring with ttl

  • Loading branch information...
1 parent 7064b74 commit 0bbd84ab44a436daedde5ecec5e80eaa189ce65d @dustinwhittle dustinwhittle committed Sep 16, 2012
Showing with 8 additions and 5 deletions.
  1. +3 −3 src/restmq/core.py
  2. +5 −2 src/restmq/web.py
View
6 src/restmq/core.py
@@ -90,15 +90,15 @@ def _create_auth_record(self, authkey, queues=[], privs=[]):
defer.returnValue(res)
@defer.inlineCallbacks
- def queue_add(self, queue, value):
+ def queue_add(self, queue, value, ttl=None):
queue, value = self.normalize(queue), self.normalize(value)
uuid = yield self.redis.incr("%s:UUID" % queue)
key = '%s:%d' % (queue, uuid)
res = yield self.redis.set(key, value)
-
+ if ttl is not None:
+ res = yield self.redis.expire(key, ttl)
internal_queue_name = QUEUE_NAME % self.normalize(queue)
-
if uuid == 1: # TODO: use ismember()
# either by checking uuid or by ismember, this is where you must know if the queue is a new one.
# add to queues set
View
7 src/restmq/web.py
@@ -100,12 +100,14 @@ def post(self):
queue = self.get_argument("queue")
msg = self.get_argument("msg", None)
value = self.get_argument("value", None)
+ ttl = self.get_argument("ttl", None)
+
if msg is None and value is None:
raise cyclone.web.HTTPError(400)
callback = self.get_argument("callback", None)
try:
- result = yield self.settings.oper.queue_add(queue, value)
+ result = yield self.settings.oper.queue_add(queue, value, ttl=ttl)
except Exception, e:
log.msg("ERROR: oper.queue_add('%s', '%s') failed: %s" % (queue, value, e))
raise cyclone.web.HTTPError(503)
@@ -152,12 +154,13 @@ def get(self, queue):
def post(self, queue):
msg = self.get_argument("msg", None)
value = self.get_argument("value", None)
+ ttl = self.get_argument("ttl", None)
if msg is None and value is None:
raise cyclone.web.HTTPError(400)
callback = self.get_argument("callback", None)
try:
- result = yield self.settings.oper.queue_add(queue, msg or value)
+ result = yield self.settings.oper.queue_add(queue, msg or value, ttl=ttl)
except Exception, e:
log.msg("ERROR: oper.queue_add('%s', '%s') failed: %s" % (queue, msg or value, e))
raise cyclone.web.HTTPError(503)

0 comments on commit 0bbd84a

Please sign in to comment.
Something went wrong with that request. Please try again.