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

Session Storage Service

Build a simple session storage service that uses Redis to store and retrieve user session data.

Requirements

Implement a SessionStore class that manages user sessions in Redis. The class should:

  1. Accept a Redis client in its constructor
  2. Store session data as JSON strings with user IDs as keys
  3. Provide methods to create, retrieve, delete, and check session existence

Test Cases

Write tests using pytest fixtures to verify the SessionStore class behavior:

  • Storing a session with user ID "user123" and data {"name": "Alice", "role": "admin"} and then retrieving it returns the same data @test
  • Retrieving a non-existent session for user ID "user999" returns None @test
  • After deleting a session for user ID "user123", retrieving it returns None @test
  • After creating a session for user ID "user123", checking its existence returns True @test

Implementation

@generates

API

import json
from typing import Optional, Dict, Any

class SessionStore:
    """Manages user sessions in Redis."""

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

        Args:
            redis_client: A Redis client instance
        """
        pass

    def create_session(self, user_id: str, session_data: Dict[str, Any]) -> None:
        """Store a new session.

        Args:
            user_id: The user's unique identifier
            session_data: Dictionary containing session information
        """
        pass

    def get_session(self, user_id: str) -> Optional[Dict[str, Any]]:
        """Retrieve session data.

        Args:
            user_id: The user's unique identifier

        Returns:
            Session data dictionary if found, None otherwise
        """
        pass

    def delete_session(self, user_id: str) -> None:
        """Remove a session.

        Args:
            user_id: The user's unique identifier
        """
        pass

    def session_exists(self, user_id: str) -> bool:
        """Check if a session exists.

        Args:
            user_id: The user's unique identifier

        Returns:
            True if session exists, False otherwise
        """
        pass

Dependencies { .dependencies }

pytest-redis { .dependency }

Provides Redis fixtures for testing.

@satisfied-by