Skip to content

Commit

Permalink
Accept long in places that expect int
Browse files Browse the repository at this point in the history
Fixes #145.
  • Loading branch information
bmerry committed Mar 23, 2018
1 parent 3840b3c commit ccec029
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

if PY2:
DEFAULT_ENCODING = 'utf-8'
int_types = (int, long)
text_type = unicode # noqa: F821
string_types = (str, unicode) # noqa: F821
redis_string_types = (str, unicode, bytes) # noqa: F821
Expand Down Expand Up @@ -63,6 +64,7 @@ def iteritems(d):
else:
DEFAULT_ENCODING = sys.getdefaultencoding()
long = int
int_types = (int,)
basestring = str
text_type = str
string_types = (str,)
Expand Down Expand Up @@ -372,7 +374,7 @@ def pexpire(self, name, millis):
def _expire(self, name, time, multiplier=1):
if isinstance(time, timedelta):
time = int(timedelta_total_seconds(time) * multiplier)
if not isinstance(time, int):
if not isinstance(time, int_types):
raise redis.ResponseError("value is not an integer or out of "
"range.")
if self.exists(name):
Expand Down Expand Up @@ -437,7 +439,7 @@ def incr(self, name, amount=1):
the value will be initialized as ``amount``
"""
try:
if not isinstance(amount, int):
if not isinstance(amount, int_types):
raise redis.ResponseError("value is not an integer or out "
"of range.")
value = int(self._get_string(name, b'0')) + amount
Expand Down Expand Up @@ -576,7 +578,7 @@ def setbit(self, name, offset, value):
def setex(self, name, time, value):
if isinstance(time, timedelta):
time = int(timedelta_total_seconds(time))
if not isinstance(time, int):
if not isinstance(time, int_types):
raise ResponseError(
'value is not an integer or out of range')
return self.set(name, value, ex=time)
Expand Down Expand Up @@ -734,7 +736,7 @@ def eval(self, script, numkeys, *keys_and_args):
except ValueError:
# Non-numeric string will be handled below.
pass
if not(isinstance(numkeys, int)):
if not isinstance(numkeys, int_types):
raise ResponseError("value is not an integer or out of range")
elif numkeys > len(keys_and_args):
raise ResponseError("Number of keys can't be greater than number of args")
Expand Down
4 changes: 4 additions & 0 deletions test_fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3529,6 +3529,10 @@ def test_expire_should_return_false_for_missing_key(self):
rv = self.redis.expire('missing', 1)
self.assertIs(rv, False)

def test_expire_long(self):
self.redis.set('foo', 'bar')
self.redis.expire('foo', long(1))

@attr('slow')
def test_expire_should_expire_key_using_timedelta(self):
self.redis.set('foo', 'bar')
Expand Down

0 comments on commit ccec029

Please sign in to comment.