-
Notifications
You must be signed in to change notification settings - Fork 73
Add LREM command support for removing list elements by value #38
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?
Conversation
|
I was not sure how to add reviewers, so tagging you to review the PR mortensi. Thank you! |
|
Thanks @nishanthp, we are looking at restructuring the toolset, and eventually reduce the number of exposed tools. As soon as we move forward, we'll review the PR and work on it. Thanks for contributing, I will keep you posted! |
|
Thanks @mortensi for the update! Looking forward to collaborating with you as things progress. |
| async def lrem(name: str, count: int, element: FieldT) -> str: | ||
| """Remove elements from a Redis list. | ||
| Args: | ||
| name: The name of the list | ||
| count: Number of elements to remove (0 = all, positive = from head, negative = from tail) | ||
| element: The element value to remove | ||
| Returns: | ||
| A string indicating the number of elements removed. | ||
| """ | ||
| try: | ||
| r = RedisConnectionManager.get_connection() | ||
| removed_count = r.lrem(name, count, element) | ||
|
|
||
| if removed_count == 0: | ||
| return f"Element '{element}' not found in list '{name}' or list does not exist." | ||
| else: | ||
| return f"Removed {removed_count} occurrence(s) of '{element}' from list '{name}'." | ||
|
|
||
| except RedisError as e: | ||
| return f"Error removing element from list '{name}': {str(e)}" |
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.
This tool needs to be covered by unit tests (see test_list.py) for reference.
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.
@vchomakov Sure, I can add the required unit tests.
This PR implements the LREM (List Remove) functionality in list.py, enabling removal of list elements by value with count-based control.
Changes:
lremfunction to support Redis LREM commandcount > 0: Remove elements from head to tailcount < 0: Remove elements from tail to headcount = 0: Remove all matching elementsUsage: