Best Practices

Optimize your 44s usage with these recommendations for key design, connection management, and performance.

Key Naming Conventions

Use consistent, hierarchical key names for easier management and debugging.

✓ Do

user:123:profile
session:abc123
cache:query:products:featured
rate_limit:api:user:456

✗ Don't

u123
abc123
featuredProducts
ratelimit456

Connection Management

Use Connection Pooling

Don't create a new connection for each request. Use a connection pool.

# Python - use a single client instance
import redis

# Create once at app startup
pool = redis.ConnectionPool(
    host='your-instance.44s.io',
    port=6379,
    password='YOUR_API_KEY',
    max_connections=50
)
client = redis.Redis(connection_pool=pool)

# Reuse throughout your app
client.get('key')

Handle Reconnection

Network issues happen. Configure automatic reconnection.

// Node.js - ioredis handles this by default
const redis = new Redis({
    host: 'your-instance.44s.io',
    port: 6379,
    password: 'YOUR_API_KEY',
    retryStrategy: (times) => Math.min(times * 50, 2000),
    maxRetriesPerRequest: 3
});

Batch Operations

Reduce round trips by batching multiple operations.

✓ Do: Use MGET/MSET

# One round trip
MGET user:1 user:2 user:3

# One round trip
MSET user:1 "a" user:2 "b"

✗ Don't: Multiple GETs

# Three round trips
GET user:1
GET user:2
GET user:3

Pipelines for Complex Operations

# Python pipeline - all commands sent in one round trip
pipe = client.pipeline()
pipe.incr('page_views')
pipe.expire('page_views', 3600)
pipe.get('page_views')
results = pipe.execute()

TTL and Memory Management

Always Set TTLs: Data without expiration stays forever. Set appropriate TTLs on cache keys to prevent unbounded memory growth.
# Set TTL when creating the key
SET session:abc "data" EX 3600  # Expires in 1 hour

# Or set TTL separately
EXPIRE cache:expensive_query 300  # 5 minutes

TTL Guidelines

Use the Right Data Structure

Use Case Data Structure Why
User profile HASH Update individual fields without fetching entire object
Leaderboard SORTED SET Automatic ranking by score
Job queue LIST LPUSH/RPOP for FIFO queue
Unique visitors SET Automatic deduplication
Simple cache STRING Simplest option for serialized data

Avoid Common Pitfalls

Avoid KEYS in Production: The KEYS command scans all keys and can block the server. Use SCAN for iteration in production.

✓ Do: Use SCAN

# Incremental iteration
SCAN 0 MATCH user:* COUNT 100

✗ Don't: Use KEYS

# Blocks until complete
KEYS user:*

Other Pitfalls

Monitoring

Use 44S.USAGE to monitor your consumption:

44S.USAGE

# Returns:
# requests: 1523456
# bytes_in: 892345678
# bytes_out: 234567890
# cache_hits: 1234567
# cache_misses: 288889

Track your hit rate: cache_hits / (cache_hits + cache_misses). Aim for >90%.