Created
December 25, 2024 08:05
-
-
Save vndee/987579f2e07f1ab4fb22f39825091188 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from redis_data_structures import HashMap | |
from datetime import datetime | |
from pydantic import BaseModel | |
class UserProfile(BaseModel): | |
name: str | |
last_active: datetime | |
preferences: dict[str, Any] | |
hash_map = HashMap() | |
profile = UserProfile( | |
name="Alice", | |
last_active=datetime.now(), | |
preferences={"theme": "dark"} | |
) | |
# The entire type structure is preserved | |
hash_map.set("users", "alice", profile) | |
retrieved = hash_map.get("users", "alice") | |
assert isinstance(retrieved, UserProfile) # Still a UserProfile! | |
assert isinstance(retrieved.last_active, datetime) # DateTime preserved |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment