or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

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

index.mddocs/

0

# Redislite

1

2

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.

3

4

## Package Information

5

6

- **Package Name**: redislite

7

- **Package Type**: pypi

8

- **Language**: Python

9

- **Installation**: `pip install redislite`

10

11

## Core Imports

12

13

```python

14

import redislite

15

```

16

17

Most commonly used:

18

19

```python

20

from redislite import Redis, StrictRedis

21

```

22

23

Submodule imports:

24

25

```python

26

import redislite.patch

27

import redislite.debug

28

import redislite.configuration

29

```

30

31

## Basic Usage

32

33

```python

34

from redislite import Redis

35

36

# Create a Redis instance with embedded server

37

redis_connection = Redis('/tmp/redis.db')

38

39

# Use it like any Redis connection

40

redis_connection.set('key', 'value')

41

value = redis_connection.get('key')

42

print(value) # b'value'

43

44

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

45

```

46

47

## Architecture

48

49

Redislite is built around several key components:

50

51

- **Enhanced Redis Classes**: `Redis` and `StrictRedis` classes that extend redis-py with embedded server management

52

- **Embedded Server Management**: Automatic installation, configuration, and lifecycle management of Redis server instances

53

- **Configuration System**: Flexible configuration generation for Redis server instances with secure defaults

54

- **Compatibility Layer**: Monkey-patch functionality to replace redis-py classes for existing code compatibility

55

- **Debug and Introspection**: Tools for troubleshooting and understanding the embedded Redis setup

56

57

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.

58

59

## Capabilities

60

61

### Redis Client Classes

62

63

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.

64

65

```python { .api }

66

class Redis(RedisMixin, redis.Redis):

67

def __init__(self, dbfilename=None, serverconfig=None, host=None, port=None, **kwargs):

68

"""Enhanced Redis client with embedded server management"""

69

70

class StrictRedis(RedisMixin, redis.StrictRedis):

71

def __init__(self, dbfilename=None, serverconfig=None, host=None, port=None, **kwargs):

72

"""Enhanced StrictRedis client with embedded server management"""

73

```

74

75

[Redis Client Classes](./redis-clients.md)

76

77

### Server Configuration

78

79

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

80

81

```python { .api }

82

def config(**kwargs):

83

"""Generate a redis configuration file based on the passed arguments"""

84

85

def settings(**kwargs):

86

"""Get config settings based on the defaults and the arguments passed"""

87

88

DEFAULT_REDIS_SETTINGS = {

89

'activerehashing': 'yes',

90

'appendonly': 'no',

91

'databases': '16',

92

# ... additional default settings

93

}

94

```

95

96

[Server Configuration](./configuration.md)

97

98

### Compatibility and Patching

99

100

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

101

102

```python { .api }

103

def patch_redis(dbfile=None):

104

"""Patch all the redis classes provided by redislite"""

105

106

def unpatch_redis():

107

"""Unpatch all the redis classes provided by redislite"""

108

109

def patch_redis_Redis(dbfile=None):

110

"""Patch the redis module to replace redis.Redis() class with redislite.Redis()"""

111

112

def patch_redis_StrictRedis(dbfile=None):

113

"""Patch the redis module to replace redis.StrictRedis() class with redislite.StrictRedis()"""

114

```

115

116

[Compatibility and Patching](./patch.md)

117

118

### Debug and Introspection

119

120

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

121

122

```python { .api }

123

def debug_info():

124

"""Return a multi-line string with the debug information"""

125

126

def debug_info_list():

127

"""Return a list with the debug information"""

128

129

def print_debug_info():

130

"""Display information about the redislite build, and redis-server on stdout"""

131

```

132

133

[Debug and Introspection](./debug.md)

134

135

## Types

136

137

```python { .api }

138

class RedisLiteException(Exception):

139

"""Redislite Client Error exception class"""

140

141

class RedisLiteServerStartError(Exception):

142

"""Redislite redis-server start error"""

143

144

# Module attributes

145

__version__: str # The version of the redislite module

146

__git_version__: str # Version number derived from git revisions

147

__git_origin__: str # Git origin of the source repository

148

__git_branch__: str # Git branch the module was built from

149

__git_hash__: str # Git hash value for the code used to build this module

150

__source_url__: str # GitHub web URL for the source code

151

__redis_executable__: str # Full path to the embedded redis-server executable

152

__redis_server_version__: str # Version of the embedded redis-server

153

__redis_server_info__: dict # Redis server information dictionary

154

```