tessl install tessl/pypi-pytest-redis@3.1.0Redis fixtures and fixture factories for Pytest.
Agent Success
Agent success rate when using this tile
95%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.12x
Baseline
Agent success rate without this tile
85%
Build a session counter system that tracks user session counts in Redis and provides utilities to manage these counts. The system should be fully tested to ensure proper isolation between tests.
Your implementation should include:
A SessionCounter class with the following methods:
increment(user_id: str) - Increments the session count for a given user ID by 1get_count(user_id: str) -> int - Returns the current session count for a user (returns 0 if user has no sessions)reset(user_id: str) - Resets a user's session count to 0get_all_users() -> list - Returns a list of all user IDs that have session countsThe SessionCounter class constructor should accept a Redis client as a parameter
Test file that validates:
Provides Redis fixtures and automatic database cleanup for testing.
Your test file should include at least the following test cases:
@generates
class SessionCounter:
"""Manages user session counts in Redis."""
def __init__(self, redis_client):
"""
Initialize the session counter with a Redis client.
Args:
redis_client: A Redis client instance
"""
pass
def increment(self, user_id: str) -> None:
"""
Increment the session count for a user.
Args:
user_id: The user identifier
"""
pass
def get_count(self, user_id: str) -> int:
"""
Get the current session count for a user.
Args:
user_id: The user identifier
Returns:
The session count (0 if user has no sessions)
"""
pass
def reset(self, user_id: str) -> None:
"""
Reset the session count for a user to 0.
Args:
user_id: The user identifier
"""
pass
def get_all_users(self) -> list:
"""
Get all user IDs that have session counts.
Returns:
List of user IDs
"""
pass