summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshacharPash <93581407+shacharPash@users.noreply.github.com>2023-01-05 14:33:29 +0200
committerGitHub <noreply@github.com>2023-01-05 14:33:29 +0200
commit8401da88d8614d38f2546e46964da6785851cded (patch)
tree2582f5fe9e1dbe23b985031597748e3393be4e94
parente67d15c490585de3f350b91ee9a4e12d3ba134b7 (diff)
downloadredis-py-8401da88d8614d38f2546e46964da6785851cded.tar.gz
add str support for set ex parameter (#2529)
-rw-r--r--redis/commands/core.py2
-rw-r--r--tests/test_commands.py7
2 files changed, 9 insertions, 0 deletions
diff --git a/redis/commands/core.py b/redis/commands/core.py
index e3a758d..3278c57 100644
--- a/redis/commands/core.py
+++ b/redis/commands/core.py
@@ -2265,6 +2265,8 @@ class BasicKeyCommands(CommandsProtocol):
pieces.append(int(ex.total_seconds()))
elif isinstance(ex, int):
pieces.append(ex)
+ elif isinstance(ex, str) and ex.isdigit():
+ pieces.append(int(ex))
else:
raise DataError("ex must be datetime.timedelta or int")
if px is not None:
diff --git a/tests/test_commands.py b/tests/test_commands.py
index 36d004c..94249e9 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -1601,6 +1601,13 @@ class TestRedisCommands:
assert r.set("a", "1", ex=10.0)
@skip_if_server_version_lt("2.6.0")
+ def test_set_ex_str(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.5")
+
+ @skip_if_server_version_lt("2.6.0")
def test_set_ex_timedelta(self, r):
expire_at = datetime.timedelta(seconds=60)
assert r.set("a", "1", ex=expire_at)