Redis built into a python package
—
Debug utilities for troubleshooting redislite installations and understanding the embedded Redis server configuration.
Get comprehensive information about the redislite installation, embedded Redis server, and build details.
def debug_info():
"""
Return a multi-line string with the debug information.
Returns:
str: Multi-line debug information string containing version info,
module path, Redis server details, and source code information
"""
def debug_info_list():
"""
Return a list with the debug information.
Returns:
list: List of strings containing debug information lines
"""
def print_debug_info():
"""
Display information about the redislite build, and redis-server on stdout.
Returns:
None
"""Usage Examples:
from redislite.debug import debug_info, debug_info_list, print_debug_info
# Get debug info as a string
info_string = debug_info()
print(info_string)
# Get debug info as a list of lines
info_lines = debug_info_list()
for line in info_lines:
print(line)
# Print debug info directly to stdout
print_debug_info()Run debug utilities directly from the command line.
Usage Examples:
# Run debug module from command line
python -m redislite.debugThis will output information similar to:
Redislite debug information:
Version: 6.2.912183
Module Path: /path/to/redislite
Installed Redis Server:
Redis Executable: /path/to/redislite/bin/redis-server
build = 3a2b5dab9c14cd5e
sha = 4657e47d:1
bits = 64
v = 6.2.14
malloc = libc
Found redis-server: /path/to/redislite/bin/redis-server
v = 6.2.14
sha = 4657e47d:1
malloc = libc
bits = 64
build = 3a2b5dab9c14cd5e
Source Code Information
Git Source URL: https://github.com/yahoo/redislite/tree/802f8a09fa23470942f8358dee1aa32dc975ea7a
Git Hash: 802f8a09fa23470942f8358dee1aa32dc975ea7a
Git Version: 6.2.912183
Git Origin: https://github.com/yahoo/redislite.git
Git Branch: masterUse debug information to diagnose problems with embedded Redis servers.
Usage Examples:
import redislite
from redislite.debug import debug_info_list
# Create Redis instance and check if it's working
try:
redis_conn = redislite.Redis('/tmp/debug_test.db')
redis_conn.ping()
print("Redis server is working properly")
except Exception as e:
print(f"Redis server problem: {e}")
# Get debug information for troubleshooting
debug_lines = debug_info_list()
print("\nDebug Information:")
for line in debug_lines:
print(line)
# Check specific attributes
print(f"\nRedis executable: {redislite.__redis_executable__}")
print(f"Redis server version: {redislite.__redis_server_version__}")
print(f"Module version: {redislite.__version__}")Access detailed information about the redislite module and embedded Redis server.
Usage Examples:
import redislite
# Version information
print(f"Redislite version: {redislite.__version__}")
print(f"Git version: {redislite.__git_version__}")
print(f"Git hash: {redislite.__git_hash__}")
print(f"Git branch: {redislite.__git_branch__}")
print(f"Git origin: {redislite.__git_origin__}")
print(f"Source URL: {redislite.__source_url__}")
# Redis server information
print(f"Redis executable: {redislite.__redis_executable__}")
print(f"Redis server version: {redislite.__redis_server_version__}")
print(f"Redis server info: {redislite.__redis_server_info__}")
# Module information
print(f"Module __all__: {redislite.__all__}")Verify that redislite was built and installed correctly.
Usage Examples:
import os
import redislite
from redislite.debug import debug_info_list
def verify_installation():
"""Verify redislite installation is complete and functional."""
issues = []
# Check if Redis executable exists
if not redislite.__redis_executable__:
issues.append("No Redis executable found")
elif not os.path.exists(redislite.__redis_executable__):
issues.append(f"Redis executable not found at: {redislite.__redis_executable__}")
# Check if Redis executable is executable
if redislite.__redis_executable__ and os.path.exists(redislite.__redis_executable__):
if not os.access(redislite.__redis_executable__, os.X_OK):
issues.append("Redis executable is not executable")
# Check version consistency
if not redislite.__version__:
issues.append("Module version not set")
if not redislite.__redis_server_version__:
issues.append("Redis server version not available")
# Try to create a Redis instance
try:
test_redis = redislite.Redis()
test_redis.ping()
test_redis.set('test_key', 'test_value')
result = test_redis.get('test_key')
if result != b'test_value':
issues.append("Redis functionality test failed")
except Exception as e:
issues.append(f"Redis instance creation failed: {e}")
if issues:
print("Installation issues found:")
for issue in issues:
print(f" - {issue}")
print("\nDebug information:")
debug_lines = debug_info_list()
for line in debug_lines:
print(line)
else:
print("Installation verified successfully")
# Run verification
verify_installation()Monitor Redis server performance and resource usage.
Usage Examples:
import redislite
import time
def monitor_redis_performance():
"""Monitor Redis server performance metrics."""
redis_conn = redislite.Redis('/tmp/performance_test.db')
print(f"Redis server PID: {redis_conn.pid}")
# Performance test
start_time = time.time()
# Write operations
for i in range(1000):
redis_conn.set(f'key_{i}', f'value_{i}')
write_time = time.time() - start_time
print(f"1000 SET operations took: {write_time:.3f} seconds")
# Read operations
start_time = time.time()
for i in range(1000):
redis_conn.get(f'key_{i}')
read_time = time.time() - start_time
print(f"1000 GET operations took: {read_time:.3f} seconds")
# Check server logs for any issues
recent_logs = redis_conn.redis_log_tail(lines=5)
if recent_logs:
print("\nRecent server logs:")
for log_line in recent_logs:
print(f" {log_line}")
# Database file size
if os.path.exists(redis_conn.db):
db_size = os.path.getsize(redis_conn.db)
print(f"Database file size: {db_size} bytes")
# Run performance monitoring
monitor_redis_performance()Analyze the runtime environment and configuration.
Usage Examples:
import sys
import os
import redislite
from redislite.debug import debug_info_list
def analyze_environment():
"""Analyze the runtime environment for redislite."""
print("Python Environment:")
print(f" Python version: {sys.version}")
print(f" Platform: {sys.platform}")
print(f" Executable: {sys.executable}")
print("\nRedislite Environment:")
debug_lines = debug_info_list()
for line in debug_lines:
print(f" {line}")
print("\nEnvironment Variables:")
redis_vars = [key for key in os.environ.keys() if 'REDIS' in key.upper()]
if redis_vars:
for var in redis_vars:
print(f" {var}={os.environ[var]}")
else:
print(" No Redis-related environment variables found")
print("\nTemporary Directory:")
import tempfile
temp_dir = tempfile.gettempdir()
print(f" Temp directory: {temp_dir}")
print(f" Temp dir writable: {os.access(temp_dir, os.W_OK)}")
# Run environment analysis
analyze_environment()Install with Tessl CLI
npx tessl i tessl/pypi-redislite