tessl install tessl/pypi-aioredis@2.0.0asyncio (PEP 3156) Redis support
Agent Success
Agent success rate when using this tile
98%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.01x
Baseline
Agent success rate without this tile
97%
Build a task queue manager that uses Redis lists to manage pending and processing tasks.
@generates
Your task queue manager should support the following operations:
Create a TaskQueueManager class with async methods that interacts with Redis. The class should accept a Redis client in its constructor and use a configurable queue name.
class TaskQueueManager:
"""Manages a task queue using Redis lists."""
def __init__(self, redis_client, queue_name: str = "tasks"):
"""
Initialize the task queue manager.
Args:
redis_client: An aioredis client instance
queue_name: The name of the Redis key for the queue
"""
pass
async def add_task(self, task: str) -> int:
"""
Add a single task to the end of the queue.
Args:
task: The task identifier or description
Returns:
The new length of the queue
"""
pass
async def add_tasks(self, tasks: list[str]) -> int:
"""
Add multiple tasks to the end of the queue.
Args:
tasks: List of task identifiers or descriptions
Returns:
The new length of the queue
"""
pass
async def get_next_task(self) -> str | None:
"""
Get and remove the next task from the front of the queue.
Returns:
The next task, or None if queue is empty
"""
pass
async def get_tasks_batch(self, count: int) -> list[str]:
"""
Get and remove multiple tasks from the front of the queue.
Args:
count: Maximum number of tasks to retrieve
Returns:
List of tasks (may be fewer than count if queue has fewer items)
"""
pass
async def get_queue_length(self) -> int:
"""
Get the current number of tasks in the queue.
Returns:
The number of pending tasks
"""
pass
async def peek_tasks(self, start: int = 0, end: int = -1) -> list[str]:
"""
View tasks in the queue without removing them.
Args:
start: Starting index (0-based)
end: Ending index (-1 for end of queue)
Returns:
List of tasks in the specified range
"""
pass
async def trim_queue(self, max_size: int) -> None:
"""
Keep only the most recent max_size tasks, removing older ones.
Args:
max_size: Maximum number of tasks to keep
"""
pass
async def clear_queue(self) -> None:
"""Remove all tasks from the queue."""
passProvides async Redis client functionality for list operations.