or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/aioredis@2.0.x
tile.json

tessl/pypi-aioredis

tessl install tessl/pypi-aioredis@2.0.0

asyncio (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%

task.mdevals/scenario-9/

Task Queue Manager

Build a task queue manager that uses Redis lists to manage pending and processing tasks.

@generates

Requirements

Your task queue manager should support the following operations:

Adding Tasks

  • Add new tasks to the end of the pending queue
  • Support adding multiple tasks at once
  • Return confirmation when tasks are added

Processing Tasks

  • Retrieve the next pending task for processing (removing it from pending queue)
  • Get a batch of multiple tasks at once for parallel processing
  • Return None or empty result when no tasks are available

Queue Inspection

  • Get the current count of pending tasks
  • View upcoming tasks without removing them from the queue
  • Peek at a specific range of pending tasks

Queue Management

  • Remove completed tasks after processing
  • Trim the queue to maintain a maximum size (keeping only the most recent tasks)
  • Clear all tasks from the queue

Implementation

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.

API

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."""
        pass

Test Cases

  • Adding a single task increases the queue length by 1 @test
  • Adding multiple tasks in batch increases the queue length correctly @test
  • Getting next task returns the oldest added task (FIFO order) @test
  • Getting next task from empty queue returns None @test
  • Getting a batch of tasks returns them in correct FIFO order @test
  • Queue length correctly reflects the number of pending tasks @test
  • Peeking at tasks does not remove them from queue @test
  • Trimming queue keeps only the specified number of most recent tasks @test
  • Clearing queue removes all tasks @test

Dependencies { .dependencies }

aioredis { .dependency }

Provides async Redis client functionality for list operations.