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-10/

Leaderboard Management System

Build a leaderboard management system that tracks player scores and provides advanced querying capabilities using sorted sets.

Requirements

Core Functionality

The system should provide the following capabilities:

  1. Add players with scores: Store player names with their scores
  2. Get top players in reverse order: Retrieve the highest-scoring players
  3. Get bottom players: Retrieve the lowest-scoring players and remove them
  4. Remove players by score range: Delete all players within a specific score range
  5. Get players by name prefix: Retrieve all players whose names fall within a lexicographic range

Specific Behaviors

  • When retrieving top players in reverse order, return them sorted from highest to lowest score with their scores
  • When getting bottom players to remove, atomically pop and return the N lowest-scoring players with their scores
  • When removing players by score range, delete all players whose scores fall within the specified inclusive range
  • When querying by name prefix, return players whose names start with or fall between specific string ranges, sorted lexicographically

Test Cases

  • It correctly adds players and retrieves top 3 players in descending score order @test
  • It pops the 2 lowest-scoring players and removes them from the leaderboard @test
  • It removes all players with scores between 500 and 800 (inclusive) @test
  • It retrieves players whose names start with 'A' or 'B' in lexicographic order @test

Implementation

@generates

API

import aioredis
from typing import List, Tuple

class LeaderboardManager:
    """Manages a game leaderboard using Redis sorted sets."""

    def __init__(self, redis: aioredis.Redis, leaderboard_key: str = "leaderboard"):
        """
        Initialize the leaderboard manager.

        Args:
            redis: An aioredis Redis client instance
            leaderboard_key: The Redis key for the leaderboard sorted set
        """
        pass

    async def add_player(self, player_name: str, score: float) -> None:
        """
        Add a player with their score to the leaderboard.

        Args:
            player_name: The player's name
            score: The player's score
        """
        pass

    async def get_top_players(self, count: int) -> List[Tuple[str, float]]:
        """
        Get the top N players in descending score order.

        Args:
            count: Number of top players to retrieve

        Returns:
            List of tuples (player_name, score) sorted by score descending
        """
        pass

    async def pop_bottom_players(self, count: int) -> List[Tuple[str, float]]:
        """
        Remove and return the N lowest-scoring players.

        Args:
            count: Number of bottom players to pop

        Returns:
            List of tuples (player_name, score) of removed players
        """
        pass

    async def remove_players_by_score_range(self, min_score: float, max_score: float) -> int:
        """
        Remove all players whose scores fall within the specified range (inclusive).

        Args:
            min_score: Minimum score (inclusive)
            max_score: Maximum score (inclusive)

        Returns:
            Number of players removed
        """
        pass

    async def get_players_by_name_prefix(self, prefix_start: str, prefix_end: str) -> List[str]:
        """
        Get players whose names fall within a lexicographic range.

        Args:
            prefix_start: Starting prefix (inclusive, use '[' notation)
            prefix_end: Ending prefix (inclusive, use '[' notation)

        Returns:
            List of player names in lexicographic order
        """
        pass

Dependencies { .dependencies }

aioredis { .dependency }

Provides async Redis client functionality for sorted set operations.