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 user tagging system that allows adding tags to users and performing various tag-based queries using Redis sets.
Implement a UserTagger class with the following functionality:
user:{user_id}:tags@generates
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
"""
passProvides async Redis client functionality for set operations.
@satisfied-by