Skip to content

Commit

Permalink
Add ScheduledSet.available
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Bender committed Mar 31, 2015
1 parent a3b5a41 commit 5c77774
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion redset/__init__.py
Expand Up @@ -7,6 +7,6 @@
"""

__version__ = '0.5'
__version__ = '0.5.1'

from redset.sets import *
7 changes: 7 additions & 0 deletions redset/sets.py
Expand Up @@ -404,6 +404,13 @@ def _get_item(self, position=0, with_score=False):
def _get_next_item(self, with_score=False):
return self._get_item(with_score=with_score)

def available(self):
"""
The count of items with a score less than now.
"""
return self.redis.zcount(self.name, '-inf', time.time())


class _DefaultSerializer(Serializer):

Expand Down
12 changes: 12 additions & 0 deletions tests/test_sets.py
Expand Up @@ -498,6 +498,18 @@ def test_length(self):
5,
)

def test_length_available(self):
for i in range(2):
self.ss.add(i, self.now + 50)

for i in range(3):
self.ss.add(i + 2, self.now - 50)

self.assertEquals(
self.ss.available(),
3,
)

def test_contains(self):
for i in range(5):
self.ss.add(i)
Expand Down

0 comments on commit 5c77774

Please sign in to comment.