Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Redis storage implementation #4

Merged
merged 1 commit into from
Feb 8, 2025

Conversation

devin-ai-integration[bot]
Copy link
Contributor

Redis Storage Implementation

This PR adds Redis as a storage backend for the rate limiter, enabling distributed rate limiting across multiple instances.

Implementation Details

  • Uses Redis INCR for atomic request counting
  • Sets TTL on keys to match rate limit window
  • Uses Redis key prefixes to avoid collisions
  • Implements proper error handling and context usage
  • Includes comprehensive test suite with Redis integration tests

Configuration

Redis connection can be configured via environment variables:

REDIS_HOST=localhost    # Redis server hostname
REDIS_PORT=6379        # Redis server port
REDIS_PASSWORD=        # Optional Redis password
REDIS_DB=0            # Redis database number

Testing Instructions

  1. Start Redis and the application:
docker compose up -d
  1. Run tests:
docker compose exec app sh -c "cd /app && go test ./... -v"
  1. Try the Redis example:
docker compose exec app sh -c "cd /app && go run examples/redis/redis.go"

Changes

  • Added Redis storage implementation with TTL support
  • Added Redis configuration with environment variables
  • Updated docker-compose with Redis service
  • Added Redis example implementation
  • Added Redis tests with proper cleanup
  • Updated documentation with Redis usage

Testing Done

  • All tests passing including Redis integration tests
  • Redis example working with Docker Compose
  • Proper error handling and cleanup implemented
  • Verified concurrent request handling
  • Tested key expiration and cleanup

Link to Devin run: https://app.devin.ai/sessions/f6c48165523740d4ab8e798b0b34531b
Requested by: Wesley

- Add Redis storage backend with TTL support
- Add Redis configuration with environment variables
- Update docker-compose with Redis service
- Add Redis example implementation
- Add Redis tests with proper cleanup
- Update documentation with Redis usage

Testing:
- All tests passing including Redis integration tests
- Redis example working with Docker Compose
- Proper error handling and cleanup implemented

Co-Authored-By: Wesley Willians <wesleywillians@gmail.com>
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add "(aside)" to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@wesleywillians wesleywillians merged commit 077650b into main Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant