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

User Tagging System

Build a user tagging system that allows adding tags to users and performing various tag-based queries using Redis sets.

Requirements

Implement a UserTagger class with the following functionality:

Tag Management

  • Add one or more tags to a user
  • Remove one or more tags from a user
  • Get all tags for a specific user
  • Check if a user has a specific tag
  • Count the number of tags a user has

Set Algebra Operations

  • Find the intersection of two users' tag sets (tags they both have)
  • Find the union of two users' tag sets (all unique tags from both users)
  • Find the difference between two users' tag sets (tags in first user but not in second)

Additional Operations

  • Get a random tag from a user's tag set
  • Remove and return a random tag from a user's tag set

Implementation Details

  • Store each user's tags in a Redis set with key pattern: user:{user_id}:tags
  • All operations should be asynchronous
  • The class should accept a Redis client in its constructor
  • Handle edge cases like empty sets appropriately

Test Cases

  • Adding tags "python" and "redis" to user "alice" results in the user having both tags @test
  • Removing tag "python" from user "alice" who has tags ["python", "redis"] leaves only "redis" @test
  • Checking if user "bob" with tags ["javascript", "nodejs"] has tag "nodejs" returns True @test
  • Finding the intersection of alice's tags ["python", "redis", "docker"] and bob's tags ["python", "javascript"] returns {"python"} @test
  • Finding the union of alice's tags ["python", "redis"] and bob's tags ["javascript", "nodejs"] returns {"python", "redis", "javascript", "nodejs"} @test
  • Finding the difference of alice's tags ["python", "redis"] minus bob's tags ["python", "javascript"] returns {"redis"} @test

Implementation

@generates

API

class UserTagger:
    """User tagging system using Redis sets."""

    def __init__(self, redis_client):
        """
        Initialize the UserTagger with a Redis client.

        Args:
            redis_client: An aioredis client instance
        """
        pass

    async def add_tags(self, user_id: str, *tags: str) -> int:
        """
        Add one or more tags to a user.

        Args:
            user_id: The user identifier
            *tags: Variable number of tag strings to add

        Returns:
            Number of tags actually added (excluding duplicates)
        """
        pass

    async def remove_tags(self, user_id: str, *tags: str) -> int:
        """
        Remove one or more tags from a user.

        Args:
            user_id: The user identifier
            *tags: Variable number of tag strings to remove

        Returns:
            Number of tags actually removed
        """
        pass

    async def get_tags(self, user_id: str) -> set:
        """
        Get all tags for a user.

        Args:
            user_id: The user identifier

        Returns:
            Set of tag strings
        """
        pass

    async def has_tag(self, user_id: str, tag: str) -> bool:
        """
        Check if a user has a specific tag.

        Args:
            user_id: The user identifier
            tag: The tag to check for

        Returns:
            True if user has the tag, False otherwise
        """
        pass

    async def count_tags(self, user_id: str) -> int:
        """
        Count the number of tags a user has.

        Args:
            user_id: The user identifier

        Returns:
            Number of tags
        """
        pass

    async def get_tags_intersection(self, user_id1: str, user_id2: str) -> set:
        """
        Find the intersection of two users' tag sets (tags they both have).

        Args:
            user_id1: First user identifier
            user_id2: Second user identifier

        Returns:
            Set of tags present in both users' tag sets
        """
        pass

    async def get_tags_union(self, user_id1: str, user_id2: str) -> set:
        """
        Find the union of two users' tag sets (all unique tags from both).

        Args:
            user_id1: First user identifier
            user_id2: Second user identifier

        Returns:
            Set of all unique tags from both users
        """
        pass

    async def get_tags_difference(self, user_id1: str, user_id2: str) -> set:
        """
        Find the difference between two users' tag sets.

        Args:
            user_id1: First user identifier
            user_id2: Second user identifier

        Returns:
            Set of tags in first user's set but not in second user's set
        """
        pass

    async def get_random_tag(self, user_id: str) -> str:
        """
        Get a random tag from a user's tag set.

        Args:
            user_id: The user identifier

        Returns:
            A random tag string, or None if user has no tags
        """
        pass

    async def pop_random_tag(self, user_id: str) -> str:
        """
        Remove and return a random tag from a user's tag set.

        Args:
            user_id: The user identifier

        Returns:
            A random tag string that was removed, or None if user has no tags
        """
        pass

Dependencies { .dependencies }

aioredis { .dependency }

Provides async Redis client functionality for set operations.

@satisfied-by