Skip to content

Check Redis server before hash field TTL - #841

Open
sakshichitnis27 wants to merge 3 commits into
redis:mainfrom
sakshichitnis27:fix/829-server-hash-expiration-check
Open

Check Redis server before hash field TTL#841
sakshichitnis27 wants to merge 3 commits into
redis:mainfrom
sakshichitnis27:fix/829-server-hash-expiration-check

Conversation

@sakshichitnis27

@sakshichitnis27 sakshichitnis27 commented Jul 11, 2026

Copy link
Copy Markdown

Fixes #829

Summary

Check the connected Redis server version before using hash field expiration commands. This prevents HashModel.save() from calling HTTL on Redis versions older than 7.4.

Added regression tests for supported and unsupported server versions.

Testing

  • Verified the fix against Redis 7.2.14
  • pytest -q -n auto ./tests/ ./tests_sync/

Fixes #829


Note

Medium Risk
Changes core HashModel save paths to call INFO once per client and alters the public async API of supports_hash_field_expiration; behavior on Redis < 7.4 is safer but callers must await the helper.

Overview
Hash field expiration (HTTL / HEXPIRE on HashModel.save() and related helpers) is now gated on the connected Redis server version, not only redis-py ≥ 5.1.0. That stops saves on servers like 7.2.x from issuing unsupported commands (fixes #829).

supports_hash_field_expiration is async, takes the Redis client, runs INFO server when the library looks capable, treats 7.4+ as supported, and caches the result per client in a weakref.WeakKeyDictionary. Failed INFO calls are not cached so a later retry can succeed. HashModel.save, expire_field, field_ttl, and persist_field all await this check before using field TTL APIs.

Tests cover version thresholds (7.2 vs 7.4+), per-connection caching, and recovery after a transient RedisError on INFO.

Reviewed by Cursor Bugbot for commit f018297. Bugbot is set up for automated code reviews on this repo. Configure here.

@sakshichitnis27

Copy link
Copy Markdown
Author

Hi maintainers,
I’ve opened PR #841 to address this issue. Please let me know if any changes or additional tests are needed. I’d be happy to update it. Thanks!

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit b45a990. Configure here.

Comment thread aredis_om/model/model.py
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.

HashModel.save() crashes with unknown command 'HTTL' on Redis < 7.4 when redis-py ≥ 5.1.0

2 participants