-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Python: fix(redis): scope RedisHistoryProvider keys by source_id #7494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,9 +106,13 @@ def __init__( | |
| else: | ||
| self._redis_client = redis.from_url(redis_url, decode_responses=True) # type: ignore[no-untyped-call] | ||
|
|
||
| # Unit separator: source ids and session ids are opaque strings and can | ||
| # legitimately contain ':', which would make colon-joined keys ambiguous. | ||
| _KEY_SEP = "\x1f" | ||
|
|
||
| def _redis_key(self, session_id: str | None) -> str: | ||
| """Get the Redis key for a given session's messages.""" | ||
| return f"{self.key_prefix}:{session_id or 'default'}" | ||
| return self._KEY_SEP.join([self.key_prefix, self.source_id, session_id or "default"]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, have we thought about an explicit migration path before changing every existing Redis key? After an upgrade, data written as |
||
|
|
||
| async def get_messages( | ||
| self, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could
_redis_keyencode each component injectively instead of joining opaque IDs with\x1f?source_id="audit", session_id="x\x1fy"andsource_id="audit\x1fx", session_id="y"produce the same Redis key, soget_messages()can return the other provider's history andclear()can delete it. Length-prefixing or encoding each component would preserve isolation for the identifier domain the base API accepts.