Skip to content

Instantly share code, notes, and snippets.

@vndee
Created December 25, 2024 08:05
Show Gist options
  • Save vndee/987579f2e07f1ab4fb22f39825091188 to your computer and use it in GitHub Desktop.
Save vndee/987579f2e07f1ab4fb22f39825091188 to your computer and use it in GitHub Desktop.
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