Redis API
Simplified Redis connection management with GCP project-based key namespacing.
What It Does
The Redis API provides a lightweight wrapper around Redis that simplifies connection management and provides utilities for batch key operations. It automatically namespaces keys by GCP project ID to prevent collisions in multi-tenant or multi-project environments.
Key Capabilities
| Capability | Description |
|---|---|
| Singleton Connection | Manages single Redis client instance with connection pooling |
| Auto-Configuration | Retrieves connection parameters from configuration service |
| GCP Project Namespacing | Automatic key prefixing by GCP project ID for isolation |
| Prefix-Based Operations | Batch purge and query operations by key prefix |
| Connection Management | Factory pattern for creating and reusing connections |
| Testing Support | Mock Redis for unit tests without real Redis instance |
Configuration
Default Configuration
- Host: localhost
- Port: 6379
- Key Prefix: GCP Project ID
Environment Variables
- REDIS_HOST: Redis server hostname
- REDIS_PORT: Redis server port
- Configuration service provides these values
Exports
Classes
RedisConnectionFactory- Connection factory
Functions
purgeKeysWithPrefix()- Batch delete by prefixgetKeysWithPrefix()- Query keys by prefix
Common Use Cases
- Cache management: Prefix-based cache invalidation
- Session storage: Project-isolated session keys
- Rate limiting: Project-specific rate limit counters
- Multi-tenant caching: Isolated caches per tenant/project
- Key discovery: Find related cached items
- Batch cleanup: Delete groups of related keys
What Customers Don’t Have to Build
- Redis connection factory
- Singleton connection management
- GCP project-based namespacing
- Prefix-based batch operations
- Configuration service integration
- Connection pooling
- Key prefix management
- Pattern-based key discovery
- Batch deletion logic
Last updated on