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 leaderboard management system that tracks player scores and provides advanced querying capabilities using sorted sets.
The system should provide the following capabilities:
@generates
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
"""
passProvides async Redis client functionality for sorted set operations.