or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mddebug.mdindex.mdpatch.mdredis-clients.md
tile.json

tessl/pypi-redislite

Redis built into a python package

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/redislite@6.2.x

To install, run

npx @tessl/cli install tessl/pypi-redislite@6.2.0

index.mddocs/

Redislite

Redislite is a self-contained Python library that provides enhanced Redis-py bindings with a built-in Redis server that is automatically installed, configured, and managed. It offers seamless integration for Python applications requiring Redis functionality without external Redis server setup, supporting all Redis features including replication and clustering.

Package Information

  • Package Name: redislite
  • Package Type: pypi
  • Language: Python
  • Installation: pip install redislite

Core Imports

import redislite

Most commonly used:

from redislite import Redis, StrictRedis

Submodule imports:

import redislite.patch
import redislite.debug
import redislite.configuration

Basic Usage

from redislite import Redis

# Create a Redis instance with embedded server
redis_connection = Redis('/tmp/redis.db')

# Use it like any Redis connection
redis_connection.set('key', 'value')
value = redis_connection.get('key')
print(value)  # b'value'

# The server is automatically started and will be cleaned up when the instance is deleted

Architecture

Redislite is built around several key components:

  • Enhanced Redis Classes: Redis and StrictRedis classes that extend redis-py with embedded server management
  • Embedded Server Management: Automatic installation, configuration, and lifecycle management of Redis server instances
  • Configuration System: Flexible configuration generation for Redis server instances with secure defaults
  • Compatibility Layer: Monkey-patch functionality to replace redis-py classes for existing code compatibility
  • Debug and Introspection: Tools for troubleshooting and understanding the embedded Redis setup

The library enables easy creation of either single shared servers or multiple independent servers, maintains full compatibility with existing redis-py code, and uses secure default configurations accessible only by the creating user.

Capabilities

Redis Client Classes

Enhanced Redis client classes that automatically manage embedded Redis server instances. These classes provide all the functionality of redis-py Redis classes with additional embedded server management capabilities.

class Redis(RedisMixin, redis.Redis):
    def __init__(self, dbfilename=None, serverconfig=None, host=None, port=None, **kwargs):
        """Enhanced Redis client with embedded server management"""

class StrictRedis(RedisMixin, redis.StrictRedis):
    def __init__(self, dbfilename=None, serverconfig=None, host=None, port=None, **kwargs):
        """Enhanced StrictRedis client with embedded server management"""

Redis Client Classes

Server Configuration

Configuration generation and management for Redis server instances, including default settings and custom configuration options.

def config(**kwargs):
    """Generate a redis configuration file based on the passed arguments"""

def settings(**kwargs):
    """Get config settings based on the defaults and the arguments passed"""

DEFAULT_REDIS_SETTINGS = {
    'activerehashing': 'yes',
    'appendonly': 'no',
    'databases': '16',
    # ... additional default settings
}

Server Configuration

Compatibility and Patching

Monkey-patch functionality to replace redis-py classes with redislite classes, enabling existing code to use embedded Redis servers without modification.

def patch_redis(dbfile=None):
    """Patch all the redis classes provided by redislite"""

def unpatch_redis():
    """Unpatch all the redis classes provided by redislite"""

def patch_redis_Redis(dbfile=None):
    """Patch the redis module to replace redis.Redis() class with redislite.Redis()"""

def patch_redis_StrictRedis(dbfile=None):
    """Patch the redis module to replace redis.StrictRedis() class with redislite.StrictRedis()"""

Compatibility and Patching

Debug and Introspection

Debug utilities for troubleshooting redislite installations and understanding the embedded Redis server configuration.

def debug_info():
    """Return a multi-line string with the debug information"""

def debug_info_list():
    """Return a list with the debug information"""

def print_debug_info():
    """Display information about the redislite build, and redis-server on stdout"""

Debug and Introspection

Types

class RedisLiteException(Exception):
    """Redislite Client Error exception class"""

class RedisLiteServerStartError(Exception):
    """Redislite redis-server start error"""

# Module attributes
__version__: str  # The version of the redislite module
__git_version__: str  # Version number derived from git revisions
__git_origin__: str  # Git origin of the source repository
__git_branch__: str  # Git branch the module was built from
__git_hash__: str  # Git hash value for the code used to build this module
__source_url__: str  # GitHub web URL for the source code
__redis_executable__: str  # Full path to the embedded redis-server executable
__redis_server_version__: str  # Version of the embedded redis-server
__redis_server_info__: dict  # Redis server information dictionary