Repository navigation
fix(tools): don't delete the key when expire_seconds is 0 - #211
Conversation
hset, json_set and sadd called EXPIRE whenever expire_seconds was not None. Redis deletes a key immediately on EXPIRE 0, so passing 0 (a common way for a client to say 'no expiration') wrote the value, then deleted the whole hash/set/document while reporting success. Only set an expiration for a non-zero value, matching lpush, rpush, zadd and xadd and the success message, which already treated 0 as no expiration. Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #211 +/- ##
==========================================
+ Coverage 88.20% 88.85% +0.65%
==========================================
Files 19 19
Lines 1060 1122 +62
==========================================
+ Hits 935 997 +62
Misses 125 125
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Thanks, good catch. Reproduced against a real Redis: on main, hset and sadd with expire_seconds=0 delete the whole key, including data that was already there, and still report success. With this change, the key survives with no TTL, and positive values behave as before.
LGTM.
Summary
hset,json_setandsaddcallEXPIREwheneverexpire_seconds is not None. Redis deletes a key immediately when it getsEXPIRE key 0. So a call withexpire_seconds=0, which a client or LLM can easily send to mean "no expiration":"... set successfully". The success message already treats 0 as "no expiration" (if expire_seconds), so it doesn't mention any expiry.lpush,rpush,zaddandxaddalready guard with a truthiness check (if expire:/if expiration:), so this PR makes the three tools consistent with them and with their own success message.Changes
src/tools/hash.py,src/tools/json.py,src/tools/set.py:if expire_seconds is not None:→if expire_seconds:, with a short comment explaining why.Tests
test_*_zero_expiration_does_not_delete_keyforhset,saddandjson_set. Each one asserts thatEXPIREisn't called and that the result doesn't mention an expiry.mainand pass with this change.pytest: 379 passed), andruff check/ruff format --checkare clean.