A multiplayer Plants vs Zombies tower defense game showcasing Redis as a multi-model platform - going far beyond simple caching to demonstrate Redis's capabilities as a complete application database.
- Node.js 14+
- Redis Server 6+
- Modern web browser
git clone <repository-url>
cd plants-vs-zombies-redis
./start.shGame: http://localhost:3001
API: http://localhost:3001/api
Health: http://localhost:3001/api/health
This project demonstrates Redis as a powerful, multi-model platform rather than just a cache:
- Complete game state persistence
- Player profiles with stats, achievements, unlocked content
- No traditional database required - Redis IS the database
- Live multiplayer game updates (plant placements, zombie movements)
- Wave notifications and game events
- Real-time player status updates
- Complete game replay capability
- Analytics pipeline for game insights
- Automatic event cleanup and management
- Global high scores with automatic ranking
- Category-specific leaderboards (zombies killed, plants placed)
- Real-time score updates
- Efficient zombie queues per lane
- FIFO operations for game mechanics
- Lane-specific operations
- Active games and player tracking
- Real-time lobby management
- Efficient membership operations
- HyperLogLog for memory-efficient unique player counting
- Counters for game statistics
- Performance monitoring
- 🌻 Sunflower: Produces sun for economy
- 🌱 Peashooter: Basic projectile damage
- ❄️ Snow Pea: Slowing projectiles
- 🌰 Wall-nut: High-health defensive barrier
- 🍒 Cherry Bomb: Area-of-effect explosion
- 🌶️ Jalapeno: Full-lane destruction
- 🌵 Cactus: Anti-air capabilities
- 🍄 Puff-shroom: Free short-range defense
- 🧟 Basic Zombie: Standard threat
- 🧟♂️ Conehead: Armored zombie
- 🧟♀️ Buckethead: Heavy armor
- 🏃♂️ Runner: Fast-moving threat
- 🦘 Pole Vaulter: Jumps over first plant
- 🎈 Balloon: Flying zombie
- 👑 Boss Zombies: Massive health and damage
- ☀️ Sun Boost: Instant sun generation
- ⚡ Speed Boost: Accelerated plant actions
- 🛡️ Plant Shield: Damage reduction
- 💥 Damage Boost: Increased plant damage
- 🤝 Cooperative: Team up against zombies
- ⚔️ Versus: Competitive multiplayer
- 🏃 Survival: Endless wave challenge
- High Scores: Overall game performance
- Zombies Killed: Combat effectiveness
- Plants Planted: Strategic deployment
- Waves Completed: Survival achievements
- Games Won: Victory statistics
- Auto-generated plant-themed usernames
- Random name generator with 🎲 button
- Names like:
GardenMaster,ZombieSlayer,EpicSunflower
./start.sh# Single container
docker build -t pvz-redis .
docker run -p 3001:3001 pvz-redis
# Multi-container (recommended)
docker-compose up -d# Install dependencies
sudo apt-get install nodejs npm redis-server
# Deploy application
git clone <repository-url>
cd plants-vs-zombies-redis
npm install --production
./start.shSee DEPLOYMENT.md for detailed deployment instructions.
- Enter your player name (or use suggested username)
- Choose game mode (Cooperative/Versus/Survival)
- Optionally enter a game ID to join existing game
- Start with 🌻 Sunflowers for economy
- Place 🌱 Peashooters for basic defense
- Use 🌰 Wall-nuts to protect valuable plants
- 🍒 Cherry Bombs for emergency crowd control
- Prepare for boss waves (every 5 waves)
- Use power-ups strategically
- Coordinate with teammates in multiplayer
- ❄️ Snow Peas slow zombies for better targeting
- 🌵 Cactus can hit flying 🎈 Balloon Zombies
- 🌶️ Jalapenos clear entire lanes instantly
server.js # Express server with Socket.IO
game-engine.js # Core game logic and mechanics
redis-client.js # Multi-model Redis operations
config/game-config.js # Game balance and configuration
public/index.html # Main game interface
public/styles.css # Responsive game styling
public/game-client.js # Client-side game logic
# Game States (Hashes)
game:{gameId}:state -> Complete game state as JSON
# Player Data (Hashes)
player:{playerId}:data -> Profile, stats, achievements
# Event Sourcing (Streams)
game:{gameId}:events -> All game events for replay
# Leaderboards (Sorted Sets)
leaderboard:high_scores -> Global high scores
leaderboard:zombies_killed -> Zombie kill rankings
# Lane Management (Lists)
game:{gameId}:lane:{laneIndex}:zombies -> Zombie queues
# Active Games (Sets)
active_games -> Set of active game IDs
game:{gameId}:players -> Players in game
# Analytics (Various)
counter:total_games -> Game counter
counter:plants_planted -> Plant counter
hll:unique_players -> Unique player count (HyperLogLog)# Health check
GET /api/health
# Global statistics
GET /api/stats
# Active games
GET /api/games/active# Get leaderboard by category
GET /api/leaderboard/high_scores
GET /api/leaderboard/zombies_killed
GET /api/leaderboard/plants_planted
GET /api/leaderboard/waves_completed
GET /api/leaderboard/games_won# Get player data
GET /api/player/{playerName}# Demonstrates all Redis multi-model capabilities
node demo.jsThe demo showcases:
- ✅ Primary database operations
- ✅ Real-time pub/sub messaging
- ✅ Event sourcing with streams
- ✅ Leaderboard management
- ✅ Lane-based operations
- ✅ Analytics and metrics
- Compressed JSON: Game states stored efficiently
- HyperLogLog: ~12KB for millions of unique players
- Automatic Cleanup: TTL and size limits prevent memory bloat
- Sub-millisecond: Pub/Sub message delivery
- Zero Polling: Event-driven updates only
- Horizontal Scaling: Redis Cluster support ready
- RDB Snapshots: Point-in-time game state backups
- AOF Logging: Every game action persisted
- Replication: Master-slave setup for high availability
Edit config/game-config.js to adjust:
- Plant costs and damage
- Zombie health and speed
- Wave patterns and difficulty
- Power-up effects and cooldowns
Copy .env.example to .env and configure:
NODE_ENV=production
PORT=3001
REDIS_HOST=localhost
REDIS_PORT=6379
MAX_PLAYERS_PER_GAME=4# Application health
curl http://localhost:3001/api/health
# Redis monitoring
redis-cli monitor
# View logs
npm run logsThe game automatically tracks:
- Total games played
- Unique players (HyperLogLog)
- Plants planted and zombies killed
- Player progression and achievements
- Game session duration and outcomes
Redis Connection Failed
redis-cli ping
redis-server --daemonize yesGame Not Loading
- Check browser console for JavaScript errors
- Ensure all dependencies are installed (
npm install) - Verify Redis server is accessible
Performance Issues
# Check Redis latency
redis-cli --latency
# Monitor memory usage
redis-cli info memorySee DEPLOYMENT.md for comprehensive troubleshooting.
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure Redis operations are efficient
- Update documentation
- Submit a pull request
MIT License - Feel free to use this project as a reference for Redis multi-model applications.
- Redis Team for creating an amazing multi-model platform
- Plants vs Zombies for the original game inspiration
- Socket.IO for real-time communication
- Node.js community for excellent tooling
This project demonstrates Redis as a complete application platform:
- 🗄️ Primary Database: No SQL database needed - Redis stores everything
- 📡 Real-time Engine: Pub/Sub handles all live updates
- 📊 Analytics Platform: Built-in counters, sets, and HyperLogLog
- 🔄 Event Sourcing: Streams provide complete audit trails
- 🏆 Ranking System: Sorted sets for leaderboards
- ⚡ High Performance: Sub-millisecond operations
- 📈 Scalability: Ready for Redis Cluster deployment
Redis isn't just a cache here - it's the entire backend infrastructure!
Ready to defend your lawn? 🌻🧟♂️
Start the game and experience Redis multi-model power in action!