Skip to content

Fix set command with the get option not returning result #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/commands/string/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ def test_set(redis: Redis):
assert redis.get(key) == value
assert redis.ttl(key) == ex_seconds

def test_set_with_get(redis: Redis):
key = "mykey"
old_value = "old-value"
value = "new-value"

redis.set(key, old_value)

result = redis.set(key, value, get=True)

assert result == old_value
assert redis.get(key) == value


def test_set_invalid_parameters(redis: Redis):
key = "mykey"
Expand Down
8 changes: 7 additions & 1 deletion upstash_redis/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ def format_float_list(

return [float(value) if value is not None else None for value in raw]

def set_formatter(res, command):
options = command[3:]

if "GET" in options:
return res
return res == "OK"

def to_set(res, command):
return set(res)
Expand Down Expand Up @@ -316,7 +322,7 @@ def zunion_formatter(res, command):
"FLUSHALL": ok_to_bool,
"FLUSHDB": ok_to_bool,
"PSETEX": ok_to_bool,
"SET": ok_to_bool,
"SET": set_formatter,
"SETEX": ok_to_bool,
"SETNX": to_bool,
"MSET": ok_to_bool,
Expand Down