Skip to content

Configuration

DBX can be configured using environment variables or command-line arguments. This guide covers all available configuration options.

Environment Variables

Database Configuration

VariableDefaultDescription
REDIS_URLredis://default:redispw@localhost:55000Redis connection URL

Server Configuration

VariableDefaultDescription
HOST0.0.0.0Server host address
PORT3000Server port number
POOL_SIZE10Redis connection pool size

Logging Configuration

VariableDefaultDescription
LOG_LEVELINFOLogging level (DEBUG, INFO, WARN, ERROR)
LOG_FORMATtextLog format (text, json)

Security Configuration (Optional)

VariableDefaultDescription
DBX_API_KEY-Secret API key for authentication
DBX_CORS_ORIGINS*CORS allowed origins
DBX_RATE_LIMIT_REQUESTS1000Rate limit requests per window
DBX_RATE_LIMIT_WINDOW60Rate limit window in seconds

WebSocket Configuration (Optional)

VariableDefaultDescription
DBX_WS_ENABLEDtrueEnable WebSocket support
DBX_WS_PATH/redis_wsWebSocket endpoint path

Monitoring Configuration (Optional)

VariableDefaultDescription
DBX_METRICS_ENABLEDtrueEnable metrics collection
DBX_HEALTH_CHECK_INTERVAL30Health check interval in seconds

Configuration Examples

Basic Configuration

# .env file
REDIS_URL=redis://localhost:6379
HOST=0.0.0.0
PORT=3000
POOL_SIZE=10
LOG_LEVEL=INFO

Production Configuration

# .env file
REDIS_URL=redis://user:password@redis.example.com:6379/0
HOST=0.0.0.0
PORT=8080
POOL_SIZE=50
LOG_LEVEL=WARN
DBX_API_KEY=your-secret-api-key
DBX_CORS_ORIGINS=https://yourdomain.com
DBX_RATE_LIMIT_REQUESTS=1000
DBX_RATE_LIMIT_WINDOW=60

Development Configuration

# .env file
REDIS_URL=redis://localhost:6379
HOST=127.0.0.1
PORT=3000
POOL_SIZE=5
LOG_LEVEL=DEBUG
DBX_CORS_ORIGINS=*
DBX_WS_ENABLED=true
DBX_METRICS_ENABLED=true

Docker Configuration

Docker Run

docker run -d --name dbx -p 3000:3000 \
  -e REDIS_URL=redis://your-redis-server:6379 \
  -e PORT=3000 \
  -e LOG_LEVEL=INFO \
  -e POOL_SIZE=10 \
  effortlesslabs/0dbx_redis:latest

Docker Compose

version: "3.8"
services:
  dbx:
    image: effortlesslabs/0dbx_redis:latest
    ports:
      - "3000:3000"
    environment:
      - REDIS_URL=redis://redis:6379
      - PORT=3000
      - LOG_LEVEL=INFO
      - POOL_SIZE=10
    depends_on:
      - redis
 
  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"

Command Line Arguments

Running with Arguments

# Run with custom Redis URL
cargo run --bin dbx-redis-api -- --redis-url redis://localhost:6379
 
# Run with custom port
cargo run --bin dbx-redis-api -- --port 8080
 
# Run with custom host
cargo run --bin dbx-redis-api -- --host 127.0.0.1

Available Arguments

ArgumentEnvironment VariableDescription
--redis-urlREDIS_URLRedis connection URL
--hostHOSTServer host address
--portPORTServer port number
--pool-sizePOOL_SIZEConnection pool size

Redis URL Format

Basic Format

redis://[username:password@]host:port[/database]

Examples

# Local Redis without authentication
REDIS_URL=redis://localhost:6379
 
# Local Redis with database selection
REDIS_URL=redis://localhost:6379/1
 
# Remote Redis with authentication
REDIS_URL=redis://user:password@redis.example.com:6379
 
# Remote Redis with authentication and database
REDIS_URL=redis://user:password@redis.example.com:6379/2
 
# Redis with SSL/TLS
REDIS_URL=rediss://user:password@redis.example.com:6380

Connection Pooling

Pool Configuration

The connection pool manages Redis connections for optimal performance:

# Set pool size based on your needs
POOL_SIZE=10  # For small applications
POOL_SIZE=50  # For medium applications
POOL_SIZE=100 # For high-traffic applications

Pool Behavior

  • Connections are created on-demand up to the pool size limit
  • Idle connections are kept alive for reuse
  • Failed connections are automatically retried
  • Pool size should be tuned based on your application's concurrency needs

Logging Configuration

Log Levels

# Debug level - detailed information
LOG_LEVEL=DEBUG
 
# Info level - general information
LOG_LEVEL=INFO
 
# Warn level - warnings only
LOG_LEVEL=WARN
 
# Error level - errors only
LOG_LEVEL=ERROR

Log Format

# Text format (human-readable)
LOG_FORMAT=text
 
# JSON format (machine-readable)
LOG_FORMAT=json

Security Configuration

API Key Authentication

# Set a secret API key
DBX_API_KEY=your-secret-api-key
 
# Use in requests
curl -H "Authorization: Bearer your-secret-api-key" \
  http://localhost:3000/redis/admin/health

CORS Configuration

# Allow all origins (development)
DBX_CORS_ORIGINS=*
 
# Allow specific origins
DBX_CORS_ORIGINS=https://yourdomain.com,https://app.yourdomain.com
 
# Allow multiple origins
DBX_CORS_ORIGINS=https://yourdomain.com,https://api.yourdomain.com

Rate Limiting

# Rate limit configuration
DBX_RATE_LIMIT_REQUESTS=1000  # Requests per window
DBX_RATE_LIMIT_WINDOW=60      # Window in seconds

WebSocket Configuration

WebSocket Settings

# Enable/disable WebSocket support
DBX_WS_ENABLED=true
 
# Custom WebSocket path
DBX_WS_PATH=/redis_ws

WebSocket URLs

# Default WebSocket endpoints
ws://localhost:3000/redis_ws/string/ws
ws://localhost:3000/redis_ws/hash/ws
ws://localhost:3000/redis_ws/set/ws
ws://localhost:3000/redis_ws/admin/ws

Monitoring Configuration

Health Checks

# Health check endpoint
GET http://localhost:3000/redis/admin/health
 
# Health check interval
DBX_HEALTH_CHECK_INTERVAL=30

Metrics

# Enable metrics collection
DBX_METRICS_ENABLED=true

Environment-Specific Configurations

Development

# .env.development
REDIS_URL=redis://localhost:6379
HOST=127.0.0.1
PORT=3000
POOL_SIZE=5
LOG_LEVEL=DEBUG
DBX_CORS_ORIGINS=*
DBX_WS_ENABLED=true
DBX_METRICS_ENABLED=true

Staging

# .env.staging
REDIS_URL=redis://staging-redis.example.com:6379
HOST=0.0.0.0
PORT=3000
POOL_SIZE=20
LOG_LEVEL=INFO
DBX_API_KEY=staging-api-key
DBX_CORS_ORIGINS=https://staging.yourdomain.com
DBX_RATE_LIMIT_REQUESTS=500
DBX_RATE_LIMIT_WINDOW=60

Production

# .env.production
REDIS_URL=redis://prod-redis.example.com:6379
HOST=0.0.0.0
PORT=8080
POOL_SIZE=50
LOG_LEVEL=WARN
DBX_API_KEY=production-api-key
DBX_CORS_ORIGINS=https://yourdomain.com
DBX_RATE_LIMIT_REQUESTS=1000
DBX_RATE_LIMIT_WINDOW=60
DBX_WS_ENABLED=true
DBX_METRICS_ENABLED=true

Configuration Validation

Environment Variable Validation

DBX validates configuration on startup:

# Invalid Redis URL
REDIS_URL=invalid-url
# Error: Invalid Redis URL format
 
# Invalid port
PORT=99999
# Error: Port must be between 1 and 65535
 
# Invalid pool size
POOL_SIZE=0
# Error: Pool size must be greater than 0

Configuration Check

# Check configuration without starting server
cargo run --bin dbx-redis-api -- --check-config
 
# Or check environment variables
echo $REDIS_URL
echo $PORT
echo $POOL_SIZE

Troubleshooting

Common Configuration Issues

Redis Connection Failed
# Check Redis URL format
REDIS_URL=redis://localhost:6379
 
# Test Redis connection
redis-cli -u redis://localhost:6379 ping
Port Already in Use
# Check what's using the port
lsof -i :3000
 
# Use a different port
PORT=8080
Permission Denied
# Check file permissions
ls -la .env
 
# Fix permissions
chmod 600 .env

Configuration Debugging

# Enable debug logging
LOG_LEVEL=DEBUG
 
# Check configuration at startup
cargo run --bin dbx-redis-api -- --verbose

Next Steps