Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
using setex
Browse files Browse the repository at this point in the history
  • Loading branch information
smn committed Nov 19, 2013
1 parent cafa839 commit 3b34993
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions go/vumitools/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,8 @@ def key(self, transport_name, message_id):

def set_inbound_timestamp(self, transport_name, message):
key = self.key(transport_name, message['message_id'])
d = self.redis.set(key, repr(time.time()))
d.addCallback(lambda _: self.redis.expire(key, self.max_lifetime))
return d
return self.redis.setex(
key, self.max_lifetime, repr(time.time()))

@inlineCallbacks
def get_outbound_timestamp(self, transport_name, message):
Expand Down
2 changes: 1 addition & 1 deletion go/vumitools/tests/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def test_expiry(self):
yield mw.handle_inbound(msg1, 'dummy_endpoint')
key = mw.key('dummy_endpoint', msg1['message_id'])
ttl = yield mw.redis.ttl(key)
self.assertTrue(0 < ttl < 60)
self.assertTrue(0 < ttl < 10)


class ConversationStoringMiddlewareTestCase(MiddlewareTestCase):
Expand Down

0 comments on commit 3b34993

Please sign in to comment.