# Redis Setup Guide for Beginners

This guide will help you install and run Redis on your system to improve TellerPro performance.

## What is Redis?

Redis is an in-memory database that acts as a cache. Think of it like a very fast storage that keeps frequently-used data in RAM instead of reading from the slower hard drive every time.

**Do you need Redis?**
- **Yes, if you want the best performance** for 50+ concurrent users
- **No, if you're okay with good performance** (the system will use file-based caching instead)

## Option 1: Windows Installation (Easiest for Windows Users)

### Step 1: Download Redis for Windows

Download the latest Redis for Windows from:
https://github.com/microsoftarchive/redis/releases

Look for the latest `.msi` or `.zip` file (e.g., `Redis-x64-3.0.504.msi`)

### Step 2: Install Redis

**If you downloaded an .msi file:**
1. Double-click the `.msi` file
2. Follow the installation wizard
3. Accept default settings
4. Complete the installation

**If you downloaded a .zip file:**
1. Extract the zip file to a location like `C:\redis`
2. Navigate to that folder

### Step 3: Run Redis Server

**Option A: Run as a Windows Service (Recommended)**
1. Open Command Prompt as Administrator
2. Navigate to Redis folder: `cd C:\redis`
3. Install as service: `redis-server --service-install`
4. Start the service: `redis-server --service-start`

**Option B: Run Manually**
1. Open Command Prompt
2. Navigate to Redis folder: `cd C:\redis`
3. Run: `redis-server.exe`

You should see a message like:
```
[12345] 12 Apr 10:30:00.123 # Server started, Redis version 3.0.504
[12345] 12 Apr 10:30:00.124 * The server is now ready to accept connections on port 6379
```

### Step 4: Test Redis

1. Open a new Command Prompt window
2. Navigate to Redis folder: `cd C:\redis`
3. Run: `redis-cli.exe ping`
4. You should see: `PONG`

### Step 5: Configure TellerPro

Add these lines to your `.env` file (in the TellerPro root folder):

```env
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_ENABLED=true
```

If you set a password in Redis, add it to `REDIS_PASSWORD`.

## Option 2: Using Docker (If you have Docker installed)

If you have Docker Desktop installed, this is the easiest method:

1. Open PowerShell or Command Prompt
2. Run: `docker run -d -p 6379:6379 --name redis redis:latest`
3. Redis is now running!

Then configure your `.env` file as shown above.

## Option 3: Linux/Ubuntu Installation

If you're using WSL or a Linux server:

```bash
# Update package list
sudo apt update

# Install Redis
sudo apt install redis-server

# Start Redis
sudo systemctl start redis-server

# Enable Redis to start on boot
sudo systemctl enable redis-server

# Test Redis
redis-cli ping
# Should return: PONG
```

## Option 4: Mac Installation

If you're using a Mac:

```bash
# Install using Homebrew
brew install redis

# Start Redis
brew services start redis

# Test Redis
redis-cli ping
# Should return: PONG
```

## How to Stop Redis

### Windows (Service):
```cmd
redis-server --service-stop
```

### Windows (Manual):
Press `Ctrl+C` in the Redis server window

### Docker:
```bash
docker stop redis
docker rm redis
```

### Linux:
```bash
sudo systemctl stop redis-server
```

## Troubleshooting

### Issue: "redis-server command not found"
**Solution:** Make sure Redis is in your system PATH, or use the full path like `C:\redis\redis-server.exe`

### Issue: "Connection refused" when testing
**Solution:** Make sure Redis server is running before running `redis-cli ping`

### Issue: Port 6379 already in use
**Solution:** Either stop the other service using port 6379, or configure Redis to use a different port

### Issue: Don't want to use Redis
**Solution:** That's fine! The system will automatically use file-based caching instead. Just set `REDIS_ENABLED=false` in your `.env` file or don't add Redis configuration at all.

## Quick Test

After installing and configuring Redis, create a test file `test_redis.php`:

```php
<?php
require_once 'config/config.php';
require_once 'core/RedisCache.php';

RedisCache::init();
$stats = RedisCache::getStats();

echo "Redis Status: " . ($stats['connected'] ? 'Connected ✓' : 'Not Connected ✗') . "\n";
if ($stats['connected']) {
    echo "Redis Keys: " . $stats['keys'] . "\n";
}
```

Run it: `php test_redis.php`

If it says "Connected ✓", Redis is working!

## Need More Help?

If you're still having trouble, the system will work fine without Redis - it will just use file-based caching instead. The performance difference is noticeable but not critical for smaller operations.

For the absolute best performance with 50+ concurrent users, Redis is recommended, but it's not required for the system to function.
