Skip to content

Commit

Permalink
namespace param doesn't make sense while creating rate limit object
Browse files Browse the repository at this point in the history
  • Loading branch information
biplap-sarkar committed Mar 14, 2016
1 parent 6f3202f commit aa1750c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
3 changes: 1 addition & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ PyLimit.init(redis_host="localhost", redis_port=6379)
3.) Create a rate limit namespace
```
limit = PyLimit()
limit.create('api_count', # namespace
60, # rate limit period in seconds
limit.create(60, # rate limit period in seconds
100) # no of attempts in the time period
```

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ PyLimit.init(redis_host="localhost", redis_port=6379)
3.) Create a rate limit namespace
```
limit = PyLimit()
limit.create('api_count', # namespace
60, # rate limit period in seconds
limit.create(60, # rate limit period in seconds
100) # no of attempts in the time period
```

Expand Down
9 changes: 2 additions & 7 deletions pylimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class PyLimit(object):
redis_helper = None # type: RedisHelper

def __init__(self):
self.namespace = None # type: str
self.period = None # type: int
self.limit = None # type: int

Expand All @@ -32,12 +31,9 @@ def init(cls, redis_host: str, redis_port: int, is_sentinel_redis=False, redis_s
cls.redis_helper = RedisHelper(host=redis_host, port=redis_port, is_sentinel=is_sentinel_redis,
sentinel_service=redis_sentinel_service)

def create(self, namespace: str, period: int, limit: int):
def create(self, period: int, limit: int):
"""
Creates a namespace for which rate limiting is to be implemented
:param namespace: Rate limiting namespace
:type: str
Creates a rate limiting rule with rate limiting period and attempt limit
:param period: Rate limiting period in seconds
:type: int
Expand All @@ -46,7 +42,6 @@ def create(self, namespace: str, period: int, limit: int):
:type: int
"""
self.namespace = namespace
self.period = period
self.limit = limit

Expand Down
6 changes: 2 additions & 4 deletions tests/test_pylimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ def test_exception(self):
def test_throttle(self):
PyLimit.init(redis_host="localhost", redis_port=6379)
limit = PyLimit()
limit.create('test_namespace', # namespace
10, # rate limit period in seconds
limit.create(10, # rate limit period in seconds
10) # no of attempts in the time period
for x in range(0, 20):
time.sleep(.5)
Expand All @@ -27,8 +26,7 @@ def test_throttle(self):
def test_peek(self):
PyLimit.init(redis_host="localhost", redis_port=6379)
limit = PyLimit()
limit.create('test_namespace', # namespace
10, # rate limit period in seconds
limit.create(10, # rate limit period in seconds
10) # no of attempts in the time period
for x in range(0, 10):
self.assertTrue(limit.attempt('test_namespace2'))
Expand Down

0 comments on commit aa1750c

Please sign in to comment.