diff options
author | Avital Fine <79420960+AvitalFineRedis@users.noreply.github.com> | 2021-10-21 16:23:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-21 17:23:33 +0300 |
commit | cf5c5865bb9947498f3810b028628f3d2ab14030 (patch) | |
tree | ec82815fd8ee5b5a6bdb774d23c53a0380865d6c | |
parent | 638164b15840eddc0c58ae62d3e384b218d31c58 (diff) | |
download | redis-py-cf5c5865bb9947498f3810b028628f3d2ab14030.tar.gz |
Enable floating parameters in SET (ex and px) (#1635)
-rw-r--r-- | redis/commands.py | 10 | ||||
-rw-r--r-- | tests/test_commands.py | 4 |
2 files changed, 12 insertions, 2 deletions
diff --git a/redis/commands.py b/redis/commands.py index 44a7735..f2c1538 100644 --- a/redis/commands.py +++ b/redis/commands.py @@ -1174,12 +1174,18 @@ class Commands: pieces.append('EX') if isinstance(ex, datetime.timedelta): ex = int(ex.total_seconds()) - pieces.append(ex) + if isinstance(ex, int): + pieces.append(ex) + else: + raise DataError("ex must be datetime.timedelta or int") if px is not None: pieces.append('PX') if isinstance(px, datetime.timedelta): px = int(px.total_seconds() * 1000) - pieces.append(px) + if isinstance(px, int): + pieces.append(px) + else: + raise DataError("px must be datetime.timedelta or int") if exat is not None: pieces.append('EXAT') if isinstance(exat, datetime.datetime): diff --git a/tests/test_commands.py b/tests/test_commands.py index faa1e92..fec453f 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1104,6 +1104,8 @@ class TestRedisCommands: assert r['a'] == b'1' assert 0 < r.pttl('a') <= 10000 assert 0 < r.ttl('a') <= 10 + with pytest.raises(exceptions.DataError): + assert r.set('a', '1', px=10.0) @skip_if_server_version_lt('2.6.0') def test_set_px_timedelta(self, r): @@ -1116,6 +1118,8 @@ class TestRedisCommands: def test_set_ex(self, r): assert r.set('a', '1', ex=10) assert 0 < r.ttl('a') <= 10 + with pytest.raises(exceptions.DataError): + assert r.set('a', '1', ex=10.0) @skip_if_server_version_lt('2.6.0') def test_set_ex_timedelta(self, r): |