M2 #25: Redis integration: Caching and pub/sub#65
Merged
Conversation
- Add cache module to indexer crate with Redis support:
- config.rs: RedisConfig with connection and TTL settings
- store.rs: RedisCache for caching operations
- pubsub.rs: RedisPubSub for real-time messaging
- metrics.rs: CacheMetrics for monitoring
- Caching layer with configurable TTLs:
- Market metadata (TTL: 1 minute)
- Order book snapshots (TTL: 1 second)
- Recent trades (TTL: 10 seconds)
- User balances (TTL: 5 seconds)
- Pub/sub channels:
- book:{market} — Book update notifications
- trades:{market} — Trade notifications
- orders:{owner} — User order updates
- Cache operations:
- get/set/delete with TTL support
- Type-safe serialization via serde
- Convenience methods for market/orderbook/trades/balances
- Cache invalidation helpers
- Graceful degradation:
- Configurable enabled/disabled state
- Available/unavailable tracking
- No-op when disabled or unavailable
- CacheMetrics tracking:
- Hits/misses/errors
- Gets/sets/deletes/publishes
- Hit rate and ops/sec
- Add redis and deadpool-redis to workspace dependencies
- 50+ unit tests for config, cache, pubsub, and metrics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements Redis integration for caching frequently accessed data and pub/sub messaging between services. This improves API response times and enables real-time communication.
Changes
New Module:
indexer/src/cache/mod.rsconfig.rsstore.rspubsub.rsmetrics.rsCaching Layer
Cache Operations
get/set/deletewith TTL supportget_market,set_orderbook,get_trades, etc.invalidate_market,invalidate_userPub/Sub Channels
book:{market}— Book update notificationstrades:{market}— Trade notificationsorders:{owner}— User order updatesGraceful Degradation
CacheMetrics Tracking
Dependencies
redis(v0.29) with tokio-comp and connection-manager featuresdeadpool-redis(v0.21) for connection poolingTechnical Decisions
Testing
Checklist
.internalDoc/09-rust-guidelines.mdcargo clippycargo fmtpassesCloses #25