Skip to content
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

Replaced zrangebylex method in the range method #521

Merged
merged 5 commits into from
Jan 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion llama_stack/providers/utils/kvstore/redis/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,27 @@ async def delete(self, key: str) -> None:
async def range(self, start_key: str, end_key: str) -> List[str]:
start_key = self._namespaced_key(start_key)
end_key = self._namespaced_key(end_key)
cursor = 0
pattern = start_key + "*" # Match all keys starting with start_key prefix
matching_keys = []
while True:
cursor, keys = await self.redis.scan(cursor, match=pattern, count=1000)

return await self.redis.zrangebylex(start_key, end_key)
for key in keys:
key_str = key.decode("utf-8") if isinstance(key, bytes) else key
dineshyv marked this conversation as resolved.
Show resolved Hide resolved
if start_key <= key_str <= end_key:
dineshyv marked this conversation as resolved.
Show resolved Hide resolved
matching_keys.append(key)

if cursor == 0:
break

# Then fetch all values in a single MGET call
if matching_keys:
values = await self.redis.mget(matching_keys)
return [
value.decode("utf-8") if isinstance(value, bytes) else value
dineshyv marked this conversation as resolved.
Show resolved Hide resolved
for value in values
if value is not None
]

return []
Loading