or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pytest-redis@3.1.x
tile.json

tessl/pypi-pytest-redis

tessl install tessl/pypi-pytest-redis@3.1.0

Redis 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%

task.mdevals/scenario-3/

Session Counter with Redis

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.

Requirements

Your implementation should include:

  1. A SessionCounter class with the following methods:

    • increment(user_id: str) - Increments the session count for a given user ID by 1
    • get_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 0
    • get_all_users() -> list - Returns a list of all user IDs that have session counts
  2. The SessionCounter class constructor should accept a Redis client as a parameter

  3. Test file that validates:

    • Basic increment and retrieval operations work correctly
    • Multiple increments accumulate properly
    • Reset functionality works as expected
    • Tests are properly isolated (data from one test doesn't affect another test)

Dependencies { .dependencies }

pytest-redis { .dependency }

Provides Redis fixtures and automatic database cleanup for testing.

Test Cases

Your test file should include at least the following test cases:

  • Test that incrementing a user's session count and retrieving it returns the correct value @test
  • Test that multiple increments for the same user accumulate correctly (e.g., incrementing 3 times results in count of 3) @test
  • Test that resetting a user's count brings it back to 0 @test
  • Test that different users have independent session counts @test
  • Test that demonstrates proper test isolation - run a test that sets data and then a second test that verifies the database starts clean @test

Implementation

@generates

API

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