Skip to content

Commit

Permalink
Use pipelines for peek/pop, fixes #167.
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Leifer committed Jul 21, 2016
1 parent 46ab563 commit 21bdb2b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions huey/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,19 @@ def put_data(self, key, value):
self.conn.hset(self.result_key, key, value)

def peek_data(self, key):
if self.conn.hexists(self.result_key, key):
return self.conn.hget(self.result_key, key)
return EmptyData
pipe = self.conn.pipeline()
pipe.hexists(self.result_key, key)
pipe.hget(self.result_key, key)
exists, val = pipe.execute()
return EmptyData if not exists else val

def pop_data(self, key):
val = self.peek_data(key)
if val is not EmptyData:
self.conn.hdel(self.result_key, key)
return val
pipe = self.conn.pipeline()
pipe.hexists(self.result_key, key)
pipe.hget(self.result_key, key)
pipe.hdel(self.result_key, key)
exists, val, n = pipe.execute()
return EmptyData if not exists else val

def has_data_for_key(self, key):
return self.conn.hexists(self.result_key, key)
Expand Down

0 comments on commit 21bdb2b

Please sign in to comment.