Skip to content

fix(tools): don't delete the key when expire_seconds is 0 - #211

Merged
vchomakov merged 1 commit into
redis:mainfrom
sarankumar1325:fix/zero-expire-deletes-key
Nov 27, 2026
Merged

vchomakov merged 1 commit into
redis:mainfrom
sarankumar1325:fix/zero-expire-deletes-key

Conversation

@sarankumar1325

Copy link
Copy Markdown
Contributor

Summary

hset, json_set and sadd call EXPIRE whenever expire_seconds is not None. Redis deletes a key immediately when it gets EXPIRE key 0. So a call with expire_seconds=0, which a client or LLM can easily send to mean "no expiration":

  1. writes the field/value/member,
  2. then deletes the whole hash / JSON document / set,
  3. and still returns "... set successfully". The success message already treats 0 as "no expiration" (if expire_seconds), so it doesn't mention any expiry.

lpush, rpush, zadd and xadd already 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

  • Added test_*_zero_expiration_does_not_delete_key for hset, sadd and json_set. Each one asserts that EXPIRE isn't called and that the result doesn't mention an expiry.
  • The new tests fail on main and pass with this change.
  • The full suite passes (pytest: 379 passed), and ruff check / ruff format --check are clean.

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>
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T15:33:42.560244Z
We couldn’t complete this review. Comment @codex review to try again.
23d9d0a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.85%. Comparing base (faeb09f) to head (23d9d0a).
⚠️ Report is 61 commits behind head on main.

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              
Flag Coverage Δ
unittests 88.85% <100.00%> (+0.65%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vchomakov vchomakov left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vchomakov
vchomakov merged commit 2449070 into redis:main Nov 27, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants