0
# Debug and Introspection
1
2
Debug utilities for troubleshooting redislite installations and understanding the embedded Redis server configuration.
3
4
## Capabilities
5
6
### Debug Information Retrieval
7
8
Get comprehensive information about the redislite installation, embedded Redis server, and build details.
9
10
```python { .api }
11
def debug_info():
12
"""
13
Return a multi-line string with the debug information.
14
15
Returns:
16
str: Multi-line debug information string containing version info,
17
module path, Redis server details, and source code information
18
"""
19
20
def debug_info_list():
21
"""
22
Return a list with the debug information.
23
24
Returns:
25
list: List of strings containing debug information lines
26
"""
27
28
def print_debug_info():
29
"""
30
Display information about the redislite build, and redis-server on stdout.
31
32
Returns:
33
None
34
"""
35
```
36
37
**Usage Examples:**
38
39
```python
40
from redislite.debug import debug_info, debug_info_list, print_debug_info
41
42
# Get debug info as a string
43
info_string = debug_info()
44
print(info_string)
45
46
# Get debug info as a list of lines
47
info_lines = debug_info_list()
48
for line in info_lines:
49
print(line)
50
51
# Print debug info directly to stdout
52
print_debug_info()
53
```
54
55
### Command Line Interface
56
57
Run debug utilities directly from the command line.
58
59
**Usage Examples:**
60
61
```bash
62
# Run debug module from command line
63
python -m redislite.debug
64
```
65
66
This will output information similar to:
67
68
```
69
Redislite debug information:
70
Version: 6.2.912183
71
Module Path: /path/to/redislite
72
73
Installed Redis Server:
74
Redis Executable: /path/to/redislite/bin/redis-server
75
build = 3a2b5dab9c14cd5e
76
sha = 4657e47d:1
77
bits = 64
78
v = 6.2.14
79
malloc = libc
80
81
Found redis-server: /path/to/redislite/bin/redis-server
82
v = 6.2.14
83
sha = 4657e47d:1
84
malloc = libc
85
bits = 64
86
build = 3a2b5dab9c14cd5e
87
88
Source Code Information
89
Git Source URL: https://github.com/yahoo/redislite/tree/802f8a09fa23470942f8358dee1aa32dc975ea7a
90
Git Hash: 802f8a09fa23470942f8358dee1aa32dc975ea7a
91
Git Version: 6.2.912183
92
Git Origin: https://github.com/yahoo/redislite.git
93
Git Branch: master
94
```
95
96
### Troubleshooting Redis Server Issues
97
98
Use debug information to diagnose problems with embedded Redis servers.
99
100
**Usage Examples:**
101
102
```python
103
import redislite
104
from redislite.debug import debug_info_list
105
106
# Create Redis instance and check if it's working
107
try:
108
redis_conn = redislite.Redis('/tmp/debug_test.db')
109
redis_conn.ping()
110
print("Redis server is working properly")
111
except Exception as e:
112
print(f"Redis server problem: {e}")
113
114
# Get debug information for troubleshooting
115
debug_lines = debug_info_list()
116
print("\nDebug Information:")
117
for line in debug_lines:
118
print(line)
119
120
# Check specific attributes
121
print(f"\nRedis executable: {redislite.__redis_executable__}")
122
print(f"Redis server version: {redislite.__redis_server_version__}")
123
print(f"Module version: {redislite.__version__}")
124
```
125
126
### Inspecting Module Attributes
127
128
Access detailed information about the redislite module and embedded Redis server.
129
130
**Usage Examples:**
131
132
```python
133
import redislite
134
135
# Version information
136
print(f"Redislite version: {redislite.__version__}")
137
print(f"Git version: {redislite.__git_version__}")
138
print(f"Git hash: {redislite.__git_hash__}")
139
print(f"Git branch: {redislite.__git_branch__}")
140
print(f"Git origin: {redislite.__git_origin__}")
141
print(f"Source URL: {redislite.__source_url__}")
142
143
# Redis server information
144
print(f"Redis executable: {redislite.__redis_executable__}")
145
print(f"Redis server version: {redislite.__redis_server_version__}")
146
print(f"Redis server info: {redislite.__redis_server_info__}")
147
148
# Module information
149
print(f"Module __all__: {redislite.__all__}")
150
```
151
152
### Build and Installation Verification
153
154
Verify that redislite was built and installed correctly.
155
156
**Usage Examples:**
157
158
```python
159
import os
160
import redislite
161
from redislite.debug import debug_info_list
162
163
def verify_installation():
164
"""Verify redislite installation is complete and functional."""
165
166
issues = []
167
168
# Check if Redis executable exists
169
if not redislite.__redis_executable__:
170
issues.append("No Redis executable found")
171
elif not os.path.exists(redislite.__redis_executable__):
172
issues.append(f"Redis executable not found at: {redislite.__redis_executable__}")
173
174
# Check if Redis executable is executable
175
if redislite.__redis_executable__ and os.path.exists(redislite.__redis_executable__):
176
if not os.access(redislite.__redis_executable__, os.X_OK):
177
issues.append("Redis executable is not executable")
178
179
# Check version consistency
180
if not redislite.__version__:
181
issues.append("Module version not set")
182
183
if not redislite.__redis_server_version__:
184
issues.append("Redis server version not available")
185
186
# Try to create a Redis instance
187
try:
188
test_redis = redislite.Redis()
189
test_redis.ping()
190
test_redis.set('test_key', 'test_value')
191
result = test_redis.get('test_key')
192
if result != b'test_value':
193
issues.append("Redis functionality test failed")
194
except Exception as e:
195
issues.append(f"Redis instance creation failed: {e}")
196
197
if issues:
198
print("Installation issues found:")
199
for issue in issues:
200
print(f" - {issue}")
201
202
print("\nDebug information:")
203
debug_lines = debug_info_list()
204
for line in debug_lines:
205
print(line)
206
else:
207
print("Installation verified successfully")
208
209
# Run verification
210
verify_installation()
211
```
212
213
### Performance and Resource Monitoring
214
215
Monitor Redis server performance and resource usage.
216
217
**Usage Examples:**
218
219
```python
220
import redislite
221
import time
222
223
def monitor_redis_performance():
224
"""Monitor Redis server performance metrics."""
225
226
redis_conn = redislite.Redis('/tmp/performance_test.db')
227
228
print(f"Redis server PID: {redis_conn.pid}")
229
230
# Performance test
231
start_time = time.time()
232
233
# Write operations
234
for i in range(1000):
235
redis_conn.set(f'key_{i}', f'value_{i}')
236
237
write_time = time.time() - start_time
238
print(f"1000 SET operations took: {write_time:.3f} seconds")
239
240
# Read operations
241
start_time = time.time()
242
243
for i in range(1000):
244
redis_conn.get(f'key_{i}')
245
246
read_time = time.time() - start_time
247
print(f"1000 GET operations took: {read_time:.3f} seconds")
248
249
# Check server logs for any issues
250
recent_logs = redis_conn.redis_log_tail(lines=5)
251
if recent_logs:
252
print("\nRecent server logs:")
253
for log_line in recent_logs:
254
print(f" {log_line}")
255
256
# Database file size
257
if os.path.exists(redis_conn.db):
258
db_size = os.path.getsize(redis_conn.db)
259
print(f"Database file size: {db_size} bytes")
260
261
# Run performance monitoring
262
monitor_redis_performance()
263
```
264
265
### Environment and Configuration Analysis
266
267
Analyze the runtime environment and configuration.
268
269
**Usage Examples:**
270
271
```python
272
import sys
273
import os
274
import redislite
275
from redislite.debug import debug_info_list
276
277
def analyze_environment():
278
"""Analyze the runtime environment for redislite."""
279
280
print("Python Environment:")
281
print(f" Python version: {sys.version}")
282
print(f" Platform: {sys.platform}")
283
print(f" Executable: {sys.executable}")
284
285
print("\nRedislite Environment:")
286
debug_lines = debug_info_list()
287
for line in debug_lines:
288
print(f" {line}")
289
290
print("\nEnvironment Variables:")
291
redis_vars = [key for key in os.environ.keys() if 'REDIS' in key.upper()]
292
if redis_vars:
293
for var in redis_vars:
294
print(f" {var}={os.environ[var]}")
295
else:
296
print(" No Redis-related environment variables found")
297
298
print("\nTemporary Directory:")
299
import tempfile
300
temp_dir = tempfile.gettempdir()
301
print(f" Temp directory: {temp_dir}")
302
print(f" Temp dir writable: {os.access(temp_dir, os.W_OK)}")
303
304
# Run environment analysis
305
analyze_environment()
306
```