-
Notifications
You must be signed in to change notification settings - Fork 125
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Summary
Add support for Redis 7.4+ hash field expiration to HashModel. This allows setting TTL on individual hash fields rather than the entire key.
Redis Commands (7.4+)
HEXPIRE/HPEXPIRE- Set TTL on hash fields (seconds/milliseconds)HEXPIREAT/HPEXPIREAT- Set expiration at Unix timestampHTTL/HPTTL- Get TTL of hash fieldsHPERSIST- Remove expiration from hash fields
redis-py Support
These commands are available in redis-py >= 5.1.0 (PR #3218, merged June 2024).
Proposed API
Declarative (field-level default TTL)
class Session(HashModel):
user_id: str
token: str = Field(expire=3600) # Default TTL of 1 hourRuntime methods
session = Session(user_id="123", token="abc")
await session.save()
# Set/update field expiration
await session.expire_field("token", 3600)
# Get remaining TTL
ttl = await session.field_ttl("token")
# Remove expiration
await session.persist_field("token")Per-save TTL
await session.save(field_expirations={"token": 3600})Implementation Checklist
- Extend
FieldInfoandField()withexpireparameter - Add instance methods:
expire_field(),field_ttl(),persist_field() - Modify
HashModel.save()to apply field expirations - Add runtime check for redis-py version / Redis server version
- Tests with Redis 7.4+
- Documentation updates
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request