or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

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

configuration.mddocs/

0

# Server Configuration

1

2

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

3

4

## Capabilities

5

6

### Configuration Generation

7

8

Generate Redis server configuration files based on default settings and custom parameters.

9

10

```python { .api }

11

def config(**kwargs):

12

"""

13

Generate a redis configuration file based on the passed arguments.

14

15

Parameters:

16

**kwargs: Configuration settings where key is the setting name and value

17

is the setting value. If value is list, setting will be repeated

18

with each value. If value is None, setting will be removed from

19

defaults if it exists.

20

21

Returns:

22

str: Redis server configuration

23

"""

24

25

def settings(**kwargs):

26

"""

27

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

28

29

Parameters:

30

**kwargs: Redis server arguments, the keyword is the setting, the value

31

is the value. If value is list, setting will be set multiple times.

32

If value is None, setting will be removed from defaults.

33

34

Returns:

35

dict: Dictionary containing redis server settings with key being the

36

setting name and values being the settings.

37

"""

38

39

def config_line(setting, value):

40

"""

41

Generate a single configuration line based on the setting and value.

42

43

Parameters:

44

setting (str): The configuration setting

45

value (str): The value for the configuration setting

46

47

Returns:

48

str: The configuration line based on the setting and value

49

"""

50

```

51

52

**Usage Examples:**

53

54

```python

55

from redislite.configuration import config, settings, config_line

56

57

# Generate basic configuration

58

basic_config = config()

59

print(basic_config)

60

61

# Generate configuration with custom settings

62

custom_config = config(

63

port='8080',

64

databases='32',

65

loglevel='debug'

66

)

67

print(custom_config)

68

69

# Get settings dictionary

70

config_dict = settings(

71

port='6379',

72

databases='16',

73

appendonly='yes'

74

)

75

print(config_dict)

76

77

# Generate individual configuration line

78

line = config_line('port', '6379')

79

print(line) # "port 6379"

80

```

81

82

### Default Redis Settings

83

84

Comprehensive default configuration settings for Redis server instances.

85

86

```python { .api }

87

DEFAULT_REDIS_SETTINGS = {

88

'activerehashing': 'yes',

89

'aof-rewrite-incremental-fsync': 'yes',

90

'appendonly': 'no',

91

'appendfilename': 'appendonly.aof',

92

'appendfsync': 'everysec',

93

'aof-load-truncated': 'yes',

94

'auto-aof-rewrite-percentage': '100',

95

'auto-aof-rewrite-min-size': '64mb',

96

'bind': None,

97

'daemonize': 'yes',

98

'databases': '16',

99

'dbdir': './',

100

'dbfilename': 'redis.db',

101

'hash-max-ziplist-entries': '512',

102

'hash-max-ziplist-value': '64',

103

'hll-sparse-max-bytes': '3000',

104

'hz': '10',

105

'list-max-ziplist-entries': '512',

106

'list-max-ziplist-value': '64',

107

'loglevel': 'notice',

108

'logfile': 'redis.log',

109

'lua-time-limit': '5000',

110

'pidfile': '/var/run/redislite/redis.pid',

111

'port': '0',

112

'save': ['900 1', '300 100', '60 200', '15 1000'],

113

'stop-writes-on-bgsave-error': 'yes',

114

'tcp-backlog': '511',

115

'tcp-keepalive': '0',

116

'rdbcompression': 'yes',

117

'rdbchecksum': 'yes',

118

'slave-serve-stale-data': 'yes',

119

'slave-read-only': 'yes',

120

'repl-disable-tcp-nodelay': 'no',

121

'slave-priority': '100',

122

'no-appendfsync-on-rewrite': 'no',

123

'slowlog-log-slower-than': '10000',

124

'slowlog-max-len': '128',

125

'latency-monitor-threshold': '0',

126

'notify-keyspace-events': '""',

127

'set-max-intset-entries': '512',

128

'timeout': '0',

129

'unixsocket': '/var/run/redislite/redis.socket',

130

'unixsocketperm': '700',

131

'zset-max-ziplist-entries': '128',

132

'zset-max-ziplist-value': '64',

133

}

134

```

135

136

**Usage Examples:**

137

138

```python

139

from redislite.configuration import DEFAULT_REDIS_SETTINGS, settings

140

141

# View default settings

142

print(DEFAULT_REDIS_SETTINGS['databases']) # '16'

143

print(DEFAULT_REDIS_SETTINGS['port']) # '0' (Unix socket only)

144

145

# Override defaults

146

custom_settings = settings(

147

port='6379', # Enable TCP port

148

databases='32', # More databases

149

loglevel='debug' # Verbose logging

150

)

151

152

# Remove a default setting

153

no_save_settings = settings(

154

save=None # Disable automatic saves

155

)

156

```

157

158

### Advanced Configuration

159

160

Configure Redis server instances with complex settings including replication, persistence, and performance tuning.

161

162

**Usage Examples:**

163

164

```python

165

from redislite import Redis

166

167

# Configure master-slave replication

168

master_config = {

169

'port': '8002',

170

'bind': '127.0.0.1',

171

'databases': '16'

172

}

173

slave_config = {

174

'slaveof': '127.0.0.1 8002',

175

'slave-read-only': 'yes'

176

}

177

178

master = Redis(serverconfig=master_config)

179

slave = Redis(serverconfig=slave_config)

180

181

# Configure persistence options

182

persistent_config = {

183

'appendonly': 'yes',

184

'appendfsync': 'always',

185

'save': ['60 1000', '300 100', '900 1'] # Custom save points

186

}

187

persistent_redis = Redis(serverconfig=persistent_config)

188

189

# Configure performance settings

190

performance_config = {

191

'databases': '32',

192

'hash-max-ziplist-entries': '1024',

193

'hash-max-ziplist-value': '128',

194

'tcp-keepalive': '60'

195

}

196

performance_redis = Redis(serverconfig=performance_config)

197

198

# Disable specific features

199

minimal_config = {

200

'appendonly': 'no',

201

'save': None, # Disable RDB snapshots

202

'slowlog-max-len': '0' # Disable slow log

203

}

204

minimal_redis = Redis(serverconfig=minimal_config)

205

```

206

207

### Configuration File Generation

208

209

Generate complete Redis configuration files for external use.

210

211

**Usage Examples:**

212

213

```python

214

from redislite.configuration import config

215

216

# Generate configuration file content

217

config_content = config(

218

port='6379',

219

bind='127.0.0.1',

220

databases='16',

221

appendonly='yes',

222

appendfilename='myapp.aof',

223

save=['900 1', '300 10', '60 10000'],

224

maxmemory='256mb',

225

maxmemory_policy='allkeys-lru'

226

)

227

228

# Write to file

229

with open('/tmp/redis.conf', 'w') as f:

230

f.write(config_content)

231

232

# Use with external Redis server

233

# redis-server /tmp/redis.conf

234

```