Redis Storage Documentation
Overview
The Redis storage provider allows storing browser state directly in Redis, making it suitable for high-performance, in-memory storage scenarios.
Installation
Since Redis storage is an optional feature, you need to install the ioredis package:
Configuration
interface RedisStorageOptions {
// Basic connection options
host: string; // Redis server host
port: number; // Redis server port
password?: string; // Redis server password (optional)
db?: number; // Redis database number (optional)
tls?: { // TLS configuration (optional)
rejectUnauthorized?: boolean;
ca?: string[];
cert?: string;
key?: string;
};
// Storage configuration
keyPrefix?: string; // Prefix for Redis keys (default: 'browserstate:')
tempDir?: string; // Temporary directory for file operations
// Advanced options
maxFileSize?: number; // Maximum file size to store (default: 1MB)
compression?: boolean; // Enable data compression (default: false)
ttl?: number; // Time to live in seconds for sessions
}
Usage Example
import { BrowserState } from 'browserstate';
const options = {
storageType: 'redis',
redisOptions: {
host: 'localhost',
port: 6379,
// Optional: password: 'your-password',
// Optional: db: 0,
// Optional: keyPrefix: 'browserstate:',
// Optional: maxFileSize: 1024 * 1024, // 1MB
// Optional: compression: true,
// Optional: ttl: 3600 // 1 hour
}
};
const browserState = new BrowserState(options);
Features
- Compression: Optional data compression using zlib
- File Size Limits: Configurable maximum file size
- TTL Support: Optional time-to-live for sessions
- TLS Support: Secure connections with TLS
- Connection Retry: Built-in retry strategy for reliability
- Error Handling: Graceful error handling and initialization
Error Handling
The Redis storage provider includes robust error handling:
- Graceful initialization failures
- Clear error messages for missing dependencies
- Proper cleanup on errors
- Development vs production error handling
Best Practices
- Use compression for large sessions
- Set appropriate TTL values based on your use case
- Configure maxFileSize based on your Redis memory limits
- Use TLS for production environments
- Consider using a connection pool for high-concurrency scenarios
Limitations
- Maximum file size limit (configurable)
- Memory usage depends on session size
- Requires Redis server to be available
- Network latency for remote Redis servers
Testing
To test Redis storage locally:
- Start a Redis server
- Configure connection options
- Use the example code above
- Monitor Redis memory usage
Dependencies
ioredis (optional peer dependency)
fs-extra (for file operations)
zlib (for compression)
Migration
If you're migrating from another storage provider:
- Install
ioredis
- Update your BrowserState configuration
- Test with a small session first
- Monitor Redis memory usage
- Adjust settings as needed
Security Considerations
- Use TLS for production environments
- Set strong passwords
- Configure appropriate TTL values
- Monitor Redis memory usage
- Use separate Redis databases for different environments
Performance Tips
- Enable compression for large sessions
- Use appropriate TTL values
- Monitor Redis memory usage
- Consider using Redis cluster for high availability
- Use connection pooling for high concurrency
Troubleshooting
Common issues and solutions:
- Connection failures: Check Redis server status
- Memory issues: Adjust maxFileSize
- Performance issues: Enable compression
- Initialization failures: Check ioredis installation
- TLS issues: Verify certificate configuration
Future Improvements
Redis Storage Documentation
Overview
The Redis storage provider allows storing browser state directly in Redis, making it suitable for high-performance, in-memory storage scenarios.
Installation
Since Redis storage is an optional feature, you need to install the
ioredispackage:Configuration
Usage Example
Features
Error Handling
The Redis storage provider includes robust error handling:
Best Practices
Limitations
Testing
To test Redis storage locally:
Dependencies
ioredis(optional peer dependency)fs-extra(for file operations)zlib(for compression)Migration
If you're migrating from another storage provider:
ioredisSecurity Considerations
Performance Tips
Troubleshooting
Common issues and solutions:
Future Improvements